basicContext = $scope->getEnvironment()->getContext(BasicContext::class); } protected function scaffoldDefaultFixtureFactory() { $factory = parent::scaffoldDefaultFixtureFactory(); // Use blueprints which auto-publish all subclasses of SiteTree foreach (ClassInfo::subclassesFor(SiteTree::class) as $class) { $blueprint = Injector::inst()->create(FixtureBlueprint::class, $class); $blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) { /** @var SiteTree $obj */ $obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); }); $factory->define($class, $blueprint); } return $factory; } /** * Find or create a redirector page and link to another existing page. * Example: Given a "page" "My Redirect" which redirects to a "page" "Page 1" * * @Given /^(?:(an|a|the) )"(?[^"]+)" "(?[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?[^"]+)" "(?[^"]+)"$/ * @param string $type * @param string $id * @param string $targetType * @param string $targetId */ public function stepCreateRedirectorPage($type, $id, $targetType, $targetId) { $class = RedirectorPage::class; $targetClass = $this->convertTypeToClass($targetType); $targetObj = $this->fixtureFactory->get($targetClass, $targetId); if (!$targetObj) { $targetObj = $this->fixtureFactory->get($targetClass, $targetId); } $fields = ['LinkToID' => $targetObj->ID]; /** @var RedirectorPage $obj */ $obj = $this->fixtureFactory->get($class, $id); if ($obj) { $obj->update($fields); } else { $obj = $this->fixtureFactory->createObject($class, $id, $fields); } $obj->write(); $obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); } /** * @When /^I click the "([^"]+)" element$/ * @param $selector */ public function iClickTheElement($selector) { /** @var DocumentElement $page */ $page = $this->getMainContext()->getSession()->getPage(); $element = $page->find('css', $selector); assertNotNull($element, sprintf('Element %s not found', $selector)); $element->click(); } /** * Needs to be in single command to avoid "unexpected alert open" errors in Selenium. * * @When /^I click the "([^"]+)" element, confirming the dialog$/ * @param $selector */ public function iClickTheElementConfirmingTheDialog($selector) { $this->iClickTheElement($selector); $this->basicContext->iConfirmTheDialog(); } /** * @When /^I see the "([^"]+)" element$/ * @param $selector */ public function iSeeTheElement($selector) { /** @var DocumentElement $page */ $page = $this->getMainContext()->getSession()->getPage(); $element = $page->find('css', $selector); assertNotNull($element, sprintf('Element %s not found', $selector)); } /** * Selects the specified radio button * * @Given /^I see the "([^"]*)" radio button "([^"]*)" attribute equals "([^"]*)"$/ * @param string $radioLabel * @param string $attribute * @param string $value */ public function iSeeTheRadioButtonAttributeEquals($radioLabel, $attribute, $value) { /** @var NodeElement $radioButton */ $session = $this->getMainContext()->getSession(); $radioButton = $session->getPage()->find('named', [ 'radio', $this->getMainContext()->getXpathEscaper()->escapeLiteral($radioLabel) ]); assertNotNull($radioButton); assertEquals($value, $radioButton->getAttribute($attribute)); } }