Testing Newsletter Subscriptions in Magento and MailChimp using Magium
I am working on a new release of the Magium website and I was writup up one of the tests where you can subscribe to the newsletter when you sign up. I’m using the EBizMart’s MailChimp integration to manage the newsletter integration. If you’re still mad at MailChimp do your Two Minute’s Hate and come back. I’ll be waiting for you.
Anyway, I realized that my registration component wasn’t subscribing to the newsletter. When I built the registration component I had figured that few people were using Magent’s newsletter functionality and didn’t think that third party modules might hook into it. So I didn’t build it.
Well now that I’m using it I realized I needed to do something. So I added the funtionality and also added the magium/mailchimp connector. I am using a static email address (I do have the option of dynamically generated email addresses, but I’m using the free version of MailChimp and I don’t want to be using up the free spots with test data) and so I needed to be able to
- Create a new account
- Verify that it was subscribed to MailChimp
- Delete the account
- Verify that the address was no longer subscribed to MailChimp
The test script itself is this.
// First open up the Magento instance and register $this->commandOpen($this->getTheme()->getBaseUrl()); $this->setTypePreference(self::resolveClass('Customer', 'Identities'), self::resolveClass('TestAccount', 'Identities')); $this->getAction(Register::ACTION)->register(true); // Then assert, using magium/mailchimp, that the address is subscribed $assertion = $this->getAssertion(Subscribed::ASSERTION); $assertion->setEmail($this->getIdentity()->getEmailAddress()); $assertion->setList('Magium'); $assertion->assert(); // Log in to the admin area $this->getAction(Login::ACTION)->execute(); $this->getNavigator(AdminMenu::NAVIGATOR)->navigateTo('Customers/Manage Customers'); // Navigate to the customer page and delete, accepting the confirmation alert $this->byText($this->getIdentity()->getEmailAddress())->click(); $this->getAction(ClickActionButton::ACTION)->click('Delete Customer'); $this->webdriver->switchTo()->alert()->accept(); // Finally, assert, using magium/mailchimp, that the email address is unsubscribed $assertion = $this->getAssertion(NotSubscribed::ASSERTION); /* @var $assertion NotSubscribed */ $assertion->setEmail($this->getIdentity()->getEmailAddress()); $assertion->setList('Magium'); $assertion->assert();