Source of file FeatureContext.php
Size: 3,183 Bytes - Last Modified: 2021-12-23T10:33:22+00:00
/var/www/docs.ssmods.com/process/src/tests/behat/features/bootstrap/FeatureContext.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 | <?php namespace SilverStripe\Newsletter\Test\Behaviour; use SilverStripe\BehatExtension\Context\SilverStripeContext; use SilverStripe\BehatExtension\Context\BasicContext; use SilverStripe\BehatExtension\Context\LoginContext; use SilverStripe\BehatExtension\Context\EmailContext; use SilverStripe\Framework\Test\Behaviour\CmsFormsContext; use SilverStripe\Framework\Test\Behaviour\CmsUiContext; use SilverStripe\Newsletter\Pagetypes\SubscriptionPage; use SilverStripe\Newsletter\Model\MailingList; use SilverStripe\Newsletter\Model\Recipient; /** * Features context * * Context automatically loaded by Behat. * Uses subcontexts to extend functionality. */ class FeatureContext extends SilverStripeContext { /** * Initializes context. * Every scenario gets it's own context object. * * @param array $parameters context parameters (set them up through behat.yml) */ public function __construct(array $parameters) { $this->useContext('BasicContext', new BasicContext($parameters)); $this->useContext('LoginContext', new LoginContext($parameters)); $this->useContext('CmsFormsContext', new CmsFormsContext($parameters)); $this->useContext('CmsUiContext', new CmsUiContext($parameters)); $this->useContext('EmailContext', new EmailContext($parameters)); parent::__construct($parameters); } /** * @Given /^"([^"]*)" should be subscribed to "([^"]*)"$/ */ public function thenEmailShouldBeSubscribedToMailinglist($email, $mailinglistTitle) { $recipient = Recipient::get()->filter('Email', $email)->First(); assertNotNull($recipient, 'Could not find Recipient with ' . $email); $mailinglist = MailingList::get()->filter('Title', $mailinglistTitle)->First(); assertNotNull($mailinglist, 'Could not find MailingList with ' . $mailinglistTitle); assertContains($mailinglistTitle, $recipient->MailingLists()->column('Title')); } /** * @Given /^the newsletter subscription for "([^"]*)" (should|should not) be verified$/ */ public function theNewsletterSubscriptionForIsVerified($email, $shouldOrNot = '') { $recipient = Recipient::get()->filter('Email', $email)->First(); assertNotNull($recipient, 'Could not find Recipient with ' . $email); $assertion = ($shouldOrNot == 'should') ? 'assertTrue' : 'assertFalse'; $assertion((bool)$recipient->Verified); } /** * @Given /^I add the "([^"]*)" mailinglist to the "([^"]*)" page$/ */ public function iAddTheMailinglistToThePage($mailinglistTitle, $pageUrl) { $mailinglist = MailingList::get()->filter('Title', $mailinglistTitle)->First(); assertNotNull($mailinglist, 'Could not find MailingList with ' . $mailinglistTitle); $page = SubscriptionPage::get()->filter('URLSegment', $pageUrl)->First(); assertNotNull($page); $lists = $page->MailingLists ? explode(',', $page->MailingLists) : array(); $lists[] = $mailinglist->ID; $page->MailingLists = implode(',', $lists); $page->write(); $page->publish('Stage', 'Live'); } } |