Merge pull request #136 from BiffBangPow/pulls/base-scenario-outlines

Replaced all references to ScenarioEvent with BaseScenarioEvent…
This commit is contained in:
Daniel Hensby 2016-12-13 11:04:29 +00:00 committed by GitHub
commit 8bb5ff5a1f
4 changed files with 72 additions and 72 deletions

View File

@ -7,9 +7,9 @@ use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\BehatContext, Behat\Behat\Context\BehatContext,
Behat\Behat\Context\Step, Behat\Behat\Context\Step,
Behat\Behat\Event\StepEvent, Behat\Behat\Event\StepEvent,
Behat\Behat\Event\ScenarioEvent,
Behat\Behat\Exception\PendingException; Behat\Behat\Exception\PendingException;
use Behat\Behat\Event\BaseScenarioEvent;
use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Driver\Selenium2Driver;
use Behat\Gherkin\Node\PyStringNode, use Behat\Gherkin\Node\PyStringNode,
@ -109,13 +109,13 @@ JS;
public function readErrorHandlerAfterStep(StepEvent $event) { public function readErrorHandlerAfterStep(StepEvent $event) {
try{ try{
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$jserrors = $page->find('xpath', '//body[@data-jserrors]'); $jserrors = $page->find('xpath', '//body[@data-jserrors]');
if (null !== $jserrors) { if (null !== $jserrors) {
$this->takeScreenshot($event); $this->takeScreenshot($event);
file_put_contents('php://stderr', $jserrors->getAttribute('data-jserrors') . PHP_EOL); file_put_contents('php://stderr', $jserrors->getAttribute('data-jserrors') . PHP_EOL);
} }
$javascript = <<<JS $javascript = <<<JS
if ('undefined' !== typeof window.jQuery) { if ('undefined' !== typeof window.jQuery) {
window.jQuery(document).ready(function() { window.jQuery(document).ready(function() {
@ -241,7 +241,7 @@ JS;
* *
* @AfterScenario * @AfterScenario
*/ */
public function closeModalDialog(ScenarioEvent $event) { public function closeModalDialog(BaseScenarioEvent $event) {
try{ try{
// Only for failed tests on CMS page // Only for failed tests on CMS page
if (4 === $event->getResult()) { if (4 === $event->getResult()) {
@ -260,13 +260,13 @@ JS;
$this->logException($e); $this->logException($e);
} }
} }
/** /**
* Delete any created files and folders from assets directory * Delete any created files and folders from assets directory
* *
* @AfterScenario @assets * @AfterScenario @assets
*/ */
public function cleanAssetsAfterScenario(ScenarioEvent $event) { public function cleanAssetsAfterScenario(BaseScenarioEvent $event) {
foreach(\File::get() as $file) { foreach(\File::get() as $file) {
if(file_exists($file->getFullPath())) $file->delete(); if(file_exists($file->getFullPath())) $file->delete();
} }
@ -398,7 +398,7 @@ JS;
$clickTypeFn = $clickTypeMap[$clickType]; $clickTypeFn = $clickTypeMap[$clickType];
$element->$clickTypeFn(); $element->$clickTypeFn();
} }
/** /**
* Needs to be in single command to avoid "unexpected alert open" errors in Selenium. * Needs to be in single command to avoid "unexpected alert open" errors in Selenium.
* Example: I click "Delete" in the ".actions" element, confirming the dialog * Example: I click "Delete" in the ".actions" element, confirming the dialog
@ -646,7 +646,7 @@ JS;
$linkObj = $regionObj->findLink($link); $linkObj = $regionObj->findLink($link);
if (empty($linkObj)) { if (empty($linkObj)) {
throw new \Exception(sprintf('The link "%s" was not found in the region "%s" throw new \Exception(sprintf('The link "%s" was not found in the region "%s"
on the page %s', $link, $region, $this->getSession()->getCurrentUrl())); on the page %s', $link, $region, $this->getSession()->getCurrentUrl()));
} }
@ -667,7 +667,7 @@ JS;
$fieldObj = $regionObj->findField($field); $fieldObj = $regionObj->findField($field);
if (empty($fieldObj)) { if (empty($fieldObj)) {
throw new \Exception(sprintf('The field "%s" was not found in the region "%s" throw new \Exception(sprintf('The field "%s" was not found in the region "%s"
on the page %s', $field, $region, $this->getSession()->getCurrentUrl())); on the page %s', $field, $region, $this->getSession()->getCurrentUrl()));
} }
@ -786,11 +786,11 @@ JS;
); );
// Find tables by a <caption> field // Find tables by a <caption> field
$candidates += $page->findAll('xpath', "//table//caption[contains(normalize-space(string(.)), $candidates += $page->findAll('xpath', "//table//caption[contains(normalize-space(string(.)),
$selector)]/ancestor-or-self::table[1]"); $selector)]/ancestor-or-self::table[1]");
// Find tables by a .title node // Find tables by a .title node
$candidates += $page->findAll('xpath', "//table//*[@class='title' and contains(normalize-space(string(.)), $candidates += $page->findAll('xpath', "//table//*[@class='title' and contains(normalize-space(string(.)),
$selector)]/ancestor-or-self::table[1]"); $selector)]/ancestor-or-self::table[1]");
// Some tables don't have a visible title, so look for a fieldset with data-name instead // Some tables don't have a visible title, so look for a fieldset with data-name instead
@ -989,14 +989,14 @@ JS;
$backtrace[1]['function'] $backtrace[1]['function']
)); ));
} }
/** /**
* We have to catch exceptions and log somehow else otherwise behat falls over * We have to catch exceptions and log somehow else otherwise behat falls over
*/ */
protected function logException($e){ protected function logException($e){
file_put_contents('php://stderr', 'Exception caught: '.$e); file_put_contents('php://stderr', 'Exception caught: '.$e);
} }
} }

View File

@ -7,8 +7,8 @@ Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext, Behat\Behat\Context\BehatContext,
Behat\Behat\Context\Step, Behat\Behat\Context\Step,
Behat\Behat\Event\FeatureEvent, Behat\Behat\Event\FeatureEvent,
Behat\Behat\Event\ScenarioEvent,
Behat\Behat\Exception\PendingException; Behat\Behat\Exception\PendingException;
use Behat\Behat\Event\BaseScenarioEvent;
use Behat\Gherkin\Node\PyStringNode, use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode; Behat\Gherkin\Node\TableNode;
use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DomCrawler\Crawler;
@ -54,7 +54,7 @@ class EmailContext extends BehatContext
/** /**
* @BeforeScenario * @BeforeScenario
*/ */
public function before(ScenarioEvent $event) public function before(BaseScenarioEvent $event)
{ {
// Also set through the 'supportbehat' extension // Also set through the 'supportbehat' extension
// to ensure its available both in CLI execution and the tested browser session // to ensure its available both in CLI execution and the tested browser session
@ -110,7 +110,7 @@ class EmailContext extends BehatContext
* Example: Given the email should contain "Thank you for registering!". * Example: Given the email should contain "Thank you for registering!".
* Assumes an email has been identified by a previous step, * Assumes an email has been identified by a previous step,
* e.g. through 'Given there should be an email to "test@test.com"'. * e.g. through 'Given there should be an email to "test@test.com"'.
* *
* @Given /^the email should (not |)contain "([^"]*)"$/ * @Given /^the email should (not |)contain "([^"]*)"$/
*/ */
public function thereTheEmailContains($negate, $content) public function thereTheEmailContains($negate, $content)
@ -149,7 +149,7 @@ class EmailContext extends BehatContext
assertNotNull($linkEl); assertNotNull($linkEl);
$link = $linkEl->attr('href'); $link = $linkEl->attr('href');
assertNotNull($link); assertNotNull($link);
return new Step\When(sprintf('I go to "%s"', $link)); return new Step\When(sprintf('I go to "%s"', $link));
} }
@ -170,11 +170,11 @@ class EmailContext extends BehatContext
assertNotNull($link); assertNotNull($link);
return new Step\When(sprintf('I go to "%s"', $link)); return new Step\When(sprintf('I go to "%s"', $link));
} }
/** /**
* Assumes an email has been identified by a previous step, * Assumes an email has been identified by a previous step,
* e.g. through 'Given there should be an email to "test@test.com"'. * e.g. through 'Given there should be an email to "test@test.com"'.
* *
* @When /^I click on the "([^"]*)" link in the email"$/ * @When /^I click on the "([^"]*)" link in the email"$/
*/ */
public function iGoToInTheEmail($linkSelector) public function iGoToInTheEmail($linkSelector)
@ -224,7 +224,7 @@ class EmailContext extends BehatContext
// Convert html content to plain text // Convert html content to plain text
$emailContent = strip_tags($emailContent); $emailContent = strip_tags($emailContent);
$rows = $table->getRows(); $rows = $table->getRows();
// For "should not contain" // For "should not contain"
if(trim($negate)) { if(trim($negate)) {
foreach($rows as $row) { foreach($rows as $row) {

View File

@ -8,11 +8,11 @@ use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\Step, Behat\Behat\Context\Step,
Behat\Behat\Event\StepEvent, Behat\Behat\Event\StepEvent,
Behat\Behat\Event\FeatureEvent, Behat\Behat\Event\FeatureEvent,
Behat\Behat\Event\ScenarioEvent,
Behat\Behat\Exception\PendingException, Behat\Behat\Exception\PendingException,
Behat\Mink\Driver\Selenium2Driver, Behat\Mink\Driver\Selenium2Driver,
Behat\Gherkin\Node\PyStringNode, Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode; Behat\Gherkin\Node\TableNode;
use Behat\Behat\Event\BaseScenarioEvent;
// PHPUnit // PHPUnit
require_once 'PHPUnit/Autoload.php'; require_once 'PHPUnit/Autoload.php';
@ -84,7 +84,7 @@ class FixtureContext extends BehatContext
/** /**
* @BeforeScenario @database-defaults * @BeforeScenario @database-defaults
*/ */
public function beforeDatabaseDefaults(ScenarioEvent $event) { public function beforeDatabaseDefaults(BaseScenarioEvent $event) {
\SapphireTest::empty_temp_db(); \SapphireTest::empty_temp_db();
\DB::getConn()->quiet(); \DB::getConn()->quiet();
$dataClasses = \ClassInfo::subclassesFor('DataObject'); $dataClasses = \ClassInfo::subclassesFor('DataObject');
@ -97,14 +97,14 @@ class FixtureContext extends BehatContext
/** /**
* @AfterScenario * @AfterScenario
*/ */
public function afterResetDatabase(ScenarioEvent $event) { public function afterResetDatabase(BaseScenarioEvent $event) {
\SapphireTest::empty_temp_db(); \SapphireTest::empty_temp_db();
} }
/** /**
* @AfterScenario * @AfterScenario
*/ */
public function afterResetAssets(ScenarioEvent $event) { public function afterResetAssets(BaseScenarioEvent $event) {
if (is_array($this->createdFilesPaths)) { if (is_array($this->createdFilesPaths)) {
$createdFiles = array_reverse($this->createdFilesPaths); $createdFiles = array_reverse($this->createdFilesPaths);
foreach ($createdFiles as $path) { foreach ($createdFiles as $path) {
@ -119,7 +119,7 @@ class FixtureContext extends BehatContext
/** /**
* Example: Given a "page" "Page 1" * Example: Given a "page" "Page 1"
* *
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)"$/ * @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)"$/
*/ */
public function stepCreateRecord($type, $id) { public function stepCreateRecord($type, $id) {
@ -129,8 +129,8 @@ class FixtureContext extends BehatContext
} }
/** /**
* Example: Given a "page" "Page 1" has the "content" "My content" * Example: Given a "page" "Page 1" has the "content" "My content"
* *
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" has (?:(an|a|the) )"(?<field>.*)" "(?<value>.*)"$/ * @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" has (?:(an|a|the) )"(?<field>.*)" "(?<value>.*)"$/
*/ */
public function stepCreateRecordHasField($type, $id, $field, $value) { public function stepCreateRecordHasField($type, $id, $field, $value) {
@ -150,17 +150,17 @@ class FixtureContext extends BehatContext
$this->fixtureFactory->createObject($class, $id, $fields); $this->fixtureFactory->createObject($class, $id, $fields);
} }
} }
/** /**
* Example: Given a "page" "Page 1" with "URL"="page-1" and "Content"="my page 1" * Example: Given a "page" "Page 1" with "URL"="page-1" and "Content"="my page 1"
* Example: Given the "page" "Page 1" has "URL"="page-1" and "Content"="my page 1" * Example: Given the "page" "Page 1" has "URL"="page-1" and "Content"="my page 1"
* *
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" (?:(with|has)) (?<data>".*)$/ * @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" (?:(with|has)) (?<data>".*)$/
*/ */
public function stepCreateRecordWithData($type, $id, $data) { public function stepCreateRecordWithData($type, $id, $data) {
$class = $this->convertTypeToClass($type); $class = $this->convertTypeToClass($type);
preg_match_all( preg_match_all(
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/', '/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
$data, $data,
$matches $matches
); );
@ -182,11 +182,11 @@ class FixtureContext extends BehatContext
} }
/** /**
* Example: And the "page" "Page 2" has the following data * Example: And the "page" "Page 2" has the following data
* | Content | <blink> | * | Content | <blink> |
* | My Property | foo | * | My Property | foo |
* | My Boolean | bar | * | My Boolean | bar |
* *
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" has the following data$/ * @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" has the following data$/
*/ */
public function stepCreateRecordWithTable($type, $id, $null, TableNode $fieldsTable) { public function stepCreateRecordWithTable($type, $id, $null, TableNode $fieldsTable) {
@ -210,7 +210,7 @@ class FixtureContext extends BehatContext
/** /**
* Example: Given the "page" "Page 1.1" is a child of the "page" "Page1". * Example: Given the "page" "Page 1.1" is a child of the "page" "Page1".
* Note that this change is not published by default * Note that this change is not published by default
* *
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" is a (?<relation>[^\s]*) of (?:(an|a|the) )"(?<relationType>[^"]+)" "(?<relationId>[^"]+)"/ * @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" is a (?<relation>[^\s]*) of (?:(an|a|the) )"(?<relationType>[^"]+)" "(?<relationId>[^"]+)"/
*/ */
public function stepUpdateRecordRelation($type, $id, $relation, $relationType, $relationId) { public function stepUpdateRecordRelation($type, $id, $relation, $relationType, $relationId) {
@ -263,7 +263,7 @@ class FixtureContext extends BehatContext
* Assign a type of object to another type of object. The base object will be created if it does not exist already. * Assign a type of object to another type of object. The base object will be created if it does not exist already.
* If the last part of the string (in the "X" relation) is omitted, then the first matching relation will be used. * If the last part of the string (in the "X" relation) is omitted, then the first matching relation will be used.
* Assumption: one object has relationship (has_one, has_many or many_many ) with the other object * Assumption: one object has relationship (has_one, has_many or many_many ) with the other object
* *
* @example I assign the "TaxonomyTerm" "For customers" to the "Page" "Page1" in the "Terms" relation * @example I assign the "TaxonomyTerm" "For customers" to the "Page" "Page1" in the "Terms" relation
* @Given /^I assign (?:(an|a|the) )"(?<type>[^"]+)" "(?<value>[^"]+)" to (?:(an|a|the) )"(?<relationType>[^"]+)" "(?<relationId>[^"]+)" in the "(?<relationName>[^"]+)" relation$/ * @Given /^I assign (?:(an|a|the) )"(?<type>[^"]+)" "(?<value>[^"]+)" to (?:(an|a|the) )"(?<relationType>[^"]+)" "(?<relationId>[^"]+)" in the "(?<relationName>[^"]+)" relation$/
*/ */
@ -294,7 +294,7 @@ class FixtureContext extends BehatContext
throw new \Exception("'$relationClass' has no relationship (has_one, has_many and many_many) with '$class'!"); throw new \Exception("'$relationClass' has no relationship (has_one, has_many and many_many) with '$class'!");
} }
// Get the searchable field to check if the fixture object already exists // Get the searchable field to check if the fixture object already exists
$temObj = new $class; $temObj = new $class;
if(isset($temObj->Name)) $field = "Name"; if(isset($temObj->Name)) $field = "Name";
else if(isset($temObj->Title)) $field = "Title"; else if(isset($temObj->Title)) $field = "Title";
@ -311,14 +311,14 @@ class FixtureContext extends BehatContext
// E.g. $has_one = array('PanelOffer' => 'Offer'); // E.g. $has_one = array('PanelOffer' => 'Offer');
// then the join field is PanelOfferID. This is the common rule in the CMS // then the join field is PanelOfferID. This is the common rule in the CMS
$relationObj->{$oneField . 'ID'} = $obj->ID; $relationObj->{$oneField . 'ID'} = $obj->ID;
} }
$relationObj->write(); $relationObj->write();
} }
/** /**
* Example: Given the "page" "Page 1" is not published * Example: Given the "page" "Page 1" is not published
* *
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" is (?<state>[^"]*)$/ * @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" is (?<state>[^"]*)$/
*/ */
public function stepUpdateRecordState($type, $id, $state) { public function stepUpdateRecordState($type, $id, $state) {
@ -350,19 +350,19 @@ class FixtureContext extends BehatContext
default: default:
throw new \InvalidArgumentException(sprintf( throw new \InvalidArgumentException(sprintf(
'Invalid state: "%s"', $state 'Invalid state: "%s"', $state
)); ));
} }
} }
/** /**
* Accepts YAML fixture definitions similar to the ones used in SilverStripe unit testing. * Accepts YAML fixture definitions similar to the ones used in SilverStripe unit testing.
* *
* Example: Given there are the following member records: * Example: Given there are the following member records:
* member1: * member1:
* Email: member1@test.com * Email: member1@test.com
* member2: * member2:
* Email: member2@test.com * Email: member2@test.com
* *
* @Given /^there are the following ([^\s]*) records$/ * @Given /^there are the following ([^\s]*) records$/
*/ */
public function stepThereAreTheFollowingRecords($dataObject, PyStringNode $string) { public function stepThereAreTheFollowingRecords($dataObject, PyStringNode $string) {
@ -377,26 +377,26 @@ class FixtureContext extends BehatContext
/** /**
* Example: Given a "member" "Admin" belonging to "Admin Group" * Example: Given a "member" "Admin" belonging to "Admin Group"
* *
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)"$/ * @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)"$/
*/ */
public function stepCreateMemberWithGroup($id, $groupId) { public function stepCreateMemberWithGroup($id, $groupId) {
$group = $this->fixtureFactory->get('Group', $groupId); $group = $this->fixtureFactory->get('Group', $groupId);
if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId); if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId);
$member = $this->fixtureFactory->createObject('Member', $id); $member = $this->fixtureFactory->createObject('Member', $id);
$member->Groups()->add($group); $member->Groups()->add($group);
} }
/** /**
* Example: Given a "member" "Admin" belonging to "Admin Group" with "Email"="test@test.com" * Example: Given a "member" "Admin" belonging to "Admin Group" with "Email"="test@test.com"
* *
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)" with (?<data>.*)$/ * @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)" with (?<data>.*)$/
*/ */
public function stepCreateMemberWithGroupAndData($id, $groupId, $data) { public function stepCreateMemberWithGroupAndData($id, $groupId, $data) {
$class = 'Member'; $class = 'Member';
preg_match_all( preg_match_all(
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/', '/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
$data, $data,
$matches $matches
); );
@ -404,7 +404,7 @@ class FixtureContext extends BehatContext
$class, $class,
array_combine($matches['key'], $matches['value']) array_combine($matches['key'], $matches['value'])
); );
$group = $this->fixtureFactory->get('Group', $groupId); $group = $this->fixtureFactory->get('Group', $groupId);
if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId); if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId);
@ -414,7 +414,7 @@ class FixtureContext extends BehatContext
/** /**
* Example: Given a "group" "Admin" with permissions "Access to 'Pages' section" and "Access to 'Files' section" * Example: Given a "group" "Admin" with permissions "Access to 'Pages' section" and "Access to 'Files' section"
* *
* @Given /^(?:(an|a|the) )"group" "(?<id>[^"]+)" (?:(with|has)) permissions (?<permissionStr>.*)$/ * @Given /^(?:(an|a|the) )"group" "(?<id>[^"]+)" (?:(with|has)) permissions (?<permissionStr>.*)$/
*/ */
public function stepCreateGroupWithPermissions($id, $permissionStr) { public function stepCreateGroupWithPermissions($id, $permissionStr) {
@ -425,7 +425,7 @@ class FixtureContext extends BehatContext
$group = $this->fixtureFactory->get('Group', $id); $group = $this->fixtureFactory->get('Group', $id);
if(!$group) $group = $this->fixtureFactory->createObject('Group', $id); if(!$group) $group = $this->fixtureFactory->createObject('Group', $id);
foreach($permissions as $permission) { foreach($permissions as $permission) {
$found = false; $found = false;
foreach($codes as $code => $details) { foreach($codes as $code => $details) {
@ -440,7 +440,7 @@ class FixtureContext extends BehatContext
if(!$found) { if(!$found) {
throw new \InvalidArgumentException(sprintf( throw new \InvalidArgumentException(sprintf(
'No permission found for "%s"', $permission 'No permission found for "%s"', $permission
)); ));
} }
} }
} }
@ -449,7 +449,7 @@ class FixtureContext extends BehatContext
* Navigates to a record based on its identifier set during fixture creation, * Navigates to a record based on its identifier set during fixture creation,
* using its RelativeLink() method to map the record to a URL. * using its RelativeLink() method to map the record to a URL.
* Example: Given I go to the "page" "My Page" * Example: Given I go to the "page" "My Page"
* *
* @Given /^I go to (?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)"/ * @Given /^I go to (?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)"/
*/ */
public function stepGoToNamedRecord($type, $id) { public function stepGoToNamedRecord($type, $id) {
@ -472,7 +472,7 @@ class FixtureContext extends BehatContext
/** /**
* Checks that a file or folder exists in the webroot. * Checks that a file or folder exists in the webroot.
* Example: There should be a file "assets/Uploads/test.jpg" * Example: There should be a file "assets/Uploads/test.jpg"
* *
* @Then /^there should be a (?<type>(file|folder) )"(?<path>[^"]*)"/ * @Then /^there should be a (?<type>(file|folder) )"(?<path>[^"]*)"/
*/ */
public function stepThereShouldBeAFileOrFolder($type, $path) { public function stepThereShouldBeAFileOrFolder($type, $path) {
@ -480,9 +480,9 @@ class FixtureContext extends BehatContext
} }
/** /**
* Replaces fixture references in values with their respective database IDs, * Replaces fixture references in values with their respective database IDs,
* with the notation "=><class>.<identifier>". Example: "=>Page.My Page". * with the notation "=><class>.<identifier>". Example: "=>Page.My Page".
* *
* @Transform /^([^"]+)$/ * @Transform /^([^"]+)$/
*/ */
public function lookupFixtureReference($string) { public function lookupFixtureReference($string) {
@ -517,7 +517,7 @@ class FixtureContext extends BehatContext
$field, $field,
$date, $date,
$record->ID $record->ID
)); ));
// Support for Versioned extension, by checking for a "Live" stage // Support for Versioned extension, by checking for a "Live" stage
if(\DB::getConn()->hasTable($table . '_Live')) { if(\DB::getConn()->hasTable($table . '_Live')) {
\DB::query(sprintf( \DB::query(sprintf(
@ -526,13 +526,13 @@ class FixtureContext extends BehatContext
$field, $field,
$date, $date,
$record->ID $record->ID
)); ));
} }
} }
/** /**
* Prepares a fixture for use * Prepares a fixture for use
* *
* @param string $class * @param string $class
* @param string $identifier * @param string $identifier
* @param array $data * @param array $data
@ -551,7 +551,7 @@ class FixtureContext extends BehatContext
$relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '/', '', $relativeTargetPath); $relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '/', '', $relativeTargetPath);
$targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath); $targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath);
$sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath)); $sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath));
// Create file or folder on filesystem // Create file or folder on filesystem
if($class == 'Folder' || is_subclass_of($class, 'Folder')) { if($class == 'Folder' || is_subclass_of($class, 'Folder')) {
$parent = \Folder::find_or_make($relativeTargetPath); $parent = \Folder::find_or_make($relativeTargetPath);
@ -579,8 +579,8 @@ class FixtureContext extends BehatContext
* Converts a natural language class description to an actual class name. * Converts a natural language class description to an actual class name.
* Respects {@link DataObject::$singular_name} variations. * Respects {@link DataObject::$singular_name} variations.
* Example: "redirector page" -> "RedirectorPage" * Example: "redirector page" -> "RedirectorPage"
* *
* @param String * @param String
* @return String Class name * @return String Class name
*/ */
protected function convertTypeToClass($type) { protected function convertTypeToClass($type) {
@ -606,7 +606,7 @@ class FixtureContext extends BehatContext
/** /**
* Updates an object with values, resolving aliases set through * Updates an object with values, resolving aliases set through
* {@link DataObject->fieldLabels()}. * {@link DataObject->fieldLabels()}.
* *
* @param String Class name * @param String Class name
* @param Array Map of field names or aliases to their values. * @param Array Map of field names or aliases to their values.
* @return Array Map of actual object properties to their values. * @return Array Map of actual object properties to their values.
@ -617,7 +617,7 @@ class FixtureContext extends BehatContext
if($fieldLabelKey = array_search($fieldName, $labels)) { if($fieldLabelKey = array_search($fieldName, $labels)) {
unset($fields[$fieldName]); unset($fields[$fieldName]);
$fields[$labels[$fieldLabelKey]] = $fieldVal; $fields[$labels[$fieldLabelKey]] = $fieldVal;
} }
} }
return $fields; return $fields;
@ -631,5 +631,5 @@ class FixtureContext extends BehatContext
if (substr($args[0], 0, 1) == '/') $paths[0] = '/' . $paths[0]; if (substr($args[0], 0, 1) == '/') $paths[0] = '/' . $paths[0];
return join('/', $paths); return join('/', $paths);
} }
} }

View File

@ -4,8 +4,8 @@ namespace SilverStripe\BehatExtension\Context;
use Behat\Behat\Context\Step, use Behat\Behat\Context\Step,
Behat\Behat\Event\FeatureEvent, Behat\Behat\Event\FeatureEvent,
Behat\Behat\Event\ScenarioEvent,
Behat\Behat\Event\SuiteEvent; Behat\Behat\Event\SuiteEvent;
use Behat\Behat\Event\BaseScenarioEvent;
use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\PyStringNode;
use Behat\MinkExtension\Context\MinkContext; use Behat\MinkExtension\Context\MinkContext;
use Behat\Mink\Driver\GoutteDriver, use Behat\Mink\Driver\GoutteDriver,
@ -183,7 +183,7 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex
/** /**
* @BeforeScenario * @BeforeScenario
*/ */
public function before(ScenarioEvent $event) { public function before(BaseScenarioEvent $event) {
if (!isset($this->databaseName)) { if (!isset($this->databaseName)) {
throw new \LogicException( throw new \LogicException(
'Context\'s $databaseName has to be set when implementing SilverStripeAwareContextInterface.' 'Context\'s $databaseName has to be set when implementing SilverStripeAwareContextInterface.'