示例#1
0
 /**
  * @covers sAdmin::sNewsletterSubscription
  */
 public function testsNewsletterSubscription()
 {
     $validAddress = uniqid() . '@shopware.com';
     // Test unsubscribe with non existing email, fail
     $result = $this->module->sNewsletterSubscription(uniqid() . '@shopware.com', true);
     $this->assertEquals(array('code' => 4, 'message' => $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('NewsletterFailureNotFound', 'This mail address could not be found')), $result);
     // Test unsubscribe with empty post field, fail validation
     $result = $this->module->sNewsletterSubscription('', true);
     $this->assertEquals(array('code' => 6, 'message' => $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('NewsletterFailureMail', 'Enter eMail address')), $result);
     // Test with empty field, fail validation
     $result = $this->module->sNewsletterSubscription('');
     $this->assertEquals(array('code' => 6, 'message' => $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('NewsletterFailureMail', 'Enter eMail address')), $result);
     // Test with malformed email, fail validation
     $result = $this->module->sNewsletterSubscription('thisIsNotAValidEmailAddress');
     $this->assertEquals(array('code' => 1, 'message' => $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('NewsletterFailureInvalid', 'Enter valid eMail address')), $result);
     // Check that test email does not exist
     $this->assertFalse(Shopware()->Db()->fetchRow('SELECT email, groupID FROM s_campaigns_mailaddresses WHERE email LIKE ?', array($validAddress)));
     // Test with correct unique email, all ok
     $result = $this->module->sNewsletterSubscription($validAddress);
     $this->assertEquals(array('code' => 3, 'message' => $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('NewsletterSuccess', 'Thank you for receiving our newsletter')), $result);
     // Check that test email was inserted
     $this->assertEquals(array('email' => $validAddress, 'groupID' => $this->config->get('sNEWSLETTERDEFAULTGROUP')), Shopware()->Db()->fetchRow('SELECT email, groupID FROM s_campaigns_mailaddresses WHERE email LIKE ?', array($validAddress)));
     $this->assertEquals(array(array('email' => $validAddress, 'groupID' => $this->config->get('sNEWSLETTERDEFAULTGROUP'))), Shopware()->Db()->fetchAll('SELECT email, groupID FROM s_campaigns_maildata WHERE email LIKE ?', array($validAddress)));
     // Test with same email, fail
     $result = $this->module->sNewsletterSubscription($validAddress);
     $this->assertEquals(array('code' => 2, 'message' => $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('NewsletterFailureAlreadyRegistered', 'You already receive our newsletter')), $result);
     // Test with same email in a different list, fail
     $groupId = rand(1, 9999);
     $result = $this->module->sNewsletterSubscription($validAddress, false, $groupId);
     $this->assertEquals(array('code' => 2, 'message' => $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('NewsletterFailureAlreadyRegistered', 'You already receive our newsletter')), $result);
     // Check that test email address is still there, but now in two groups
     $this->assertEquals(array(array('email' => $validAddress, 'groupID' => $this->config->get('sNEWSLETTERDEFAULTGROUP'))), Shopware()->Db()->fetchAll('SELECT email, groupID FROM s_campaigns_mailaddresses WHERE email LIKE ?', array($validAddress)));
     $this->assertEquals(array(array('email' => $validAddress, 'groupID' => $this->config->get('sNEWSLETTERDEFAULTGROUP')), array('email' => $validAddress, 'groupID' => $groupId)), Shopware()->Db()->fetchAll('SELECT email, groupID FROM s_campaigns_maildata WHERE email LIKE ?', array($validAddress)));
     // Test unsubscribe the same email, all ok
     $result = $this->module->sNewsletterSubscription($validAddress, true);
     $this->assertEquals(array('code' => 5, 'message' => $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('NewsletterMailDeleted', 'Your mail address was deleted')), $result);
     // Check that test email address was removed
     $this->assertFalse(Shopware()->Db()->fetchRow('SELECT email, groupID FROM s_campaigns_mailaddresses WHERE email LIKE ?', array($validAddress)));
     // But not completely from maildata
     $this->assertEquals(array(array('email' => $validAddress, 'groupID' => $groupId)), Shopware()->Db()->fetchAll('SELECT email, groupID FROM s_campaigns_maildata WHERE email LIKE ?', array($validAddress)));
     Shopware()->Db()->delete('s_campaigns_maildata', 'email LIKE "' . $validAddress . '"');
 }