From 117c1ef662aa0175e5789c61c72d74b19d6e78da Mon Sep 17 00:00:00 2001 From: Jeffrey Guo Date: Thu, 2 Jul 2015 14:12:10 +1200 Subject: [PATCH 01/16] email contains plain text --- .../BehatExtension/Context/EmailContext.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/SilverStripe/BehatExtension/Context/EmailContext.php b/src/SilverStripe/BehatExtension/Context/EmailContext.php index b6b815d..dc873a6 100644 --- a/src/SilverStripe/BehatExtension/Context/EmailContext.php +++ b/src/SilverStripe/BehatExtension/Context/EmailContext.php @@ -134,6 +134,28 @@ class EmailContext extends BehatContext } } + /** + * Example: Given the email contains "Thank you for registering!". + * Then the email should contain plain text "Thank you for registering!" + * Assumes an email has been identified by a previous step, + * e.g. through 'Given there should be an email to "test@test.com"'. + * + * @Given /^the email should contain plain text "([^"]*)"$/ + */ + public function thereTheEmailContainsPlainText($content) + { + if(!$this->lastMatchedEmail) { + throw new \LogicException('No matched email found from previous step'); + } + + $email = $this->lastMatchedEmail; + $emailContent = ($email->Content) ? ($email->Content) : ($email->PlainContent); + $emailPlainText = strip_tags($emailContent); + $emailPlainText = preg_replace("/\h+/", " ", $emailPlainText); + + assertContains($content, $emailPlainText); + } + /** * @When /^I click on the "([^"]*)" link in the email (to|from) "([^"]*)"$/ */ @@ -223,6 +245,7 @@ class EmailContext extends BehatContext } // Convert html content to plain text $emailContent = strip_tags($emailContent); + $emailContent = preg_replace("/\h+/", " ", $emailContent); $rows = $table->getRows(); // For "should not contain" From 64c4819e6811814dbee0d51c89ed15f3ca702473 Mon Sep 17 00:00:00 2001 From: Jeffrey Guo Date: Tue, 21 Jul 2015 16:27:09 +1200 Subject: [PATCH 02/16] make matched email simple --- README.md | 6 +++ .../BehatExtension/Context/EmailContext.php | 52 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/README.md b/README.md index 1db2c84..baf3f9f 100644 --- a/README.md +++ b/README.md @@ -701,6 +701,12 @@ It's based on the `vendor/bin/behat -di @cms` output. Then /^the email should (not |)contain the following data:$/ Example: Then the email should contain the following data: + Then /^there should (not |)be an email titled "([^"]*)"$/ + + Then /^the email should (not |)be sent from "([^"]*)"$/ + + Then /^the email should (not |)be sent to "([^"]*)"$/ + ### Transformations Behat [transformations](http://docs.behat.org/guides/2.definitions.html#step-argument-transformations) diff --git a/src/SilverStripe/BehatExtension/Context/EmailContext.php b/src/SilverStripe/BehatExtension/Context/EmailContext.php index b6b815d..b1736db 100644 --- a/src/SilverStripe/BehatExtension/Context/EmailContext.php +++ b/src/SilverStripe/BehatExtension/Context/EmailContext.php @@ -236,4 +236,56 @@ class EmailContext extends BehatContext } } } + + /** + * @Then /^there should (not |)be an email titled "([^"]*)"$/ + */ + public function thereIsAnEmailTitled($negate, $subject) + { + $match = $this->mailer->findEmail(null, null, $subject); + if(trim($negate)) { + assertNull($match); + } else { + $msg = sprintf( + 'Could not find email titled "%s".', + $subject + ); + assertNotNull($match,$msg); + } + $this->lastMatchedEmail = $match; + } + + /** + * @Then /^the email should (not |)be sent from "([^"]*)"$/ + */ + public function theEmailSentFrom($negate, $from) + { + if(!$this->lastMatchedEmail) { + throw new \LogicException('No matched email found from previous step'); + } + + $match = $this->lastMatchedEmail; + if(trim($negate)) { + assertNotContains($from, $match->From); + } else { + assertContains($from, $match->From); + } + } + + /** + * @Then /^the email should (not |)be sent to "([^"]*)"$/ + */ + public function theEmailSentTo($negate, $to) + { + if(!$this->lastMatchedEmail) { + throw new \LogicException('No matched email found from previous step'); + } + + $match = $this->lastMatchedEmail; + if(trim($negate)) { + assertNotContains($to, $match->To); + } else { + assertContains($to, $match->To); + } + } } From ed391da99144e2828ef9757a0b9bf4a6ac5f805d Mon Sep 17 00:00:00 2001 From: Igor Nadj Date: Wed, 9 Sep 2015 16:59:06 +1200 Subject: [PATCH 03/16] ENH: adding wrapper around visit to detect 404s --- .../Context/SilverStripeContext.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php index 6d462b1..bda4147 100644 --- a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php +++ b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php @@ -497,5 +497,26 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex EOS; $this->getSession()->getDriver()->executeScript($script); } - + + + /** + * @Override "When /^(?:|I )go to "(?P[^"]+)"$/" + * We override this function to detect issues with .htaccess external redirects. + * + * For instance, if the behat test is being run with a base_url which includes a + * path, e.g. "http://localhost/behat-test-abc123/", .htaccess redirects may take the browser + * to the wrong base path, e.g. "http://localhost/", which will then probably generate + * a apache 404 response, which is pretty standard and we can detect it and give a better + * error message. + */ + public function visit($page){ + parent::visit($page); + + // We now check the response body. We would check for the response status code, + // but that is not quite possible yet, so this is the best we can do. + $page = $this->getSession()->getPage(); + $title = $page->find('css', 'title')->getHtml(); // getText returns empty string, so have to use getHtml + assertNotEquals('404 Not Found', $title, 'A 404 response was detected from the server. If you intended to test an apache 404 response, please write a specific 404 test step.'); + } + } From 15b491ed7459a76cbf0176dddf7ee3a66f59547e Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 16 Oct 2015 10:53:37 +1300 Subject: [PATCH 04/16] API Update for filesystem refactor --- composer.json | 2 +- .../BehatExtension/Context/BasicContext.php | 10 ++-- .../BehatExtension/Context/FixtureContext.php | 53 +++++++++++++------ 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 72d12a9..18b7a68 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "symfony/yaml": "~2.0", "symfony/finder": "~2.0", "silverstripe/testsession": "*", - "silverstripe/framework": ">=3.1.0" + "silverstripe/framework": "^4.0.0" }, "autoload": { diff --git a/src/SilverStripe/BehatExtension/Context/BasicContext.php b/src/SilverStripe/BehatExtension/Context/BasicContext.php index 31cebed..a6ee63b 100644 --- a/src/SilverStripe/BehatExtension/Context/BasicContext.php +++ b/src/SilverStripe/BehatExtension/Context/BasicContext.php @@ -2,13 +2,10 @@ namespace SilverStripe\BehatExtension\Context; -use Behat\Behat\Context\ClosuredContextInterface, - Behat\Behat\Context\TranslatedContextInterface, - Behat\Behat\Context\BehatContext, +use Behat\Behat\Context\BehatContext, Behat\Behat\Context\Step, Behat\Behat\Event\StepEvent, - Behat\Behat\Event\ScenarioEvent, - Behat\Behat\Exception\PendingException; + Behat\Behat\Event\ScenarioEvent; use Behat\Mink\Driver\Selenium2Driver; @@ -268,8 +265,9 @@ JS; */ public function cleanAssetsAfterScenario(ScenarioEvent $event) { foreach(\File::get() as $file) { - if(file_exists($file->getFullPath())) $file->delete(); + $file->delete(); } + \Filesystem::removeFolder(ASSETS_PATH, true); } public function takeScreenshot(StepEvent $event) { diff --git a/src/SilverStripe/BehatExtension/Context/FixtureContext.php b/src/SilverStripe/BehatExtension/Context/FixtureContext.php index 64b8ffe..dc81e56 100644 --- a/src/SilverStripe/BehatExtension/Context/FixtureContext.php +++ b/src/SilverStripe/BehatExtension/Context/FixtureContext.php @@ -2,17 +2,11 @@ namespace SilverStripe\BehatExtension\Context; -use Behat\Behat\Context\ClosuredContextInterface, - Behat\Behat\Context\TranslatedContextInterface, - Behat\Behat\Context\BehatContext, - Behat\Behat\Context\Step, - Behat\Behat\Event\StepEvent, - Behat\Behat\Event\FeatureEvent, +use Behat\Behat\Context\BehatContext, Behat\Behat\Event\ScenarioEvent, - Behat\Behat\Exception\PendingException, - Behat\Mink\Driver\Selenium2Driver, Behat\Gherkin\Node\PyStringNode, - Behat\Gherkin\Node\TableNode; + Behat\Gherkin\Node\TableNode, + SilverStripe\Filesystem\Storage\AssetStore; // PHPUnit require_once 'PHPUnit/Autoload.php'; @@ -548,13 +542,13 @@ class FixtureContext extends BehatContext protected function prepareAsset($class, $identifier, $data = null) { if(!$data) $data = array(); $relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier; - $relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '/', '', $relativeTargetPath); - $targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath); + $relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '\/?/', '', $relativeTargetPath); $sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath)); // Create file or folder on filesystem + $parent = \Folder::find_or_make(dirname($relativeTargetPath)); if($class == 'Folder' || is_subclass_of($class, 'Folder')) { - $parent = \Folder::find_or_make($relativeTargetPath); + $targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath); } else { if(!file_exists($sourcePath)) { throw new \InvalidArgumentException(sprintf( @@ -563,18 +557,43 @@ class FixtureContext extends BehatContext $sourcePath )); } - $parent = \Folder::find_or_make(dirname($relativeTargetPath)); - copy($sourcePath, $targetPath); + // Load file into APL and retrieve tuple + $asset = $this->getAssetStore()->setFromLocalFile( + $sourcePath, + $relativeTargetPath, + null, + null, + AssetStore::CONFLICT_OVERWRITE + ); + $data['FileFilename'] = $asset['Filename']; + $data['FileHash'] = $asset['Hash']; + $data['FileVariant'] = $asset['Variant']; + + // Strip base from url to get dir relative to base + $url = $this->getAssetStore()->getAsURL($asset['Filename'], $asset['Hash'], $asset['Variant']); + $targetPath = $this->joinPaths(BASE_PATH, substr($url, strlen(\Director::baseURL()))); + } + unset($data['Filename']); + if(!isset($data['Name'])) { + $data['Name'] = basename($relativeTargetPath); + } + if($parent) { + $data['ParentID'] = $parent->ID; } - $data['Filename'] = $this->joinPaths(ASSETS_DIR, $relativeTargetPath); - if(!isset($data['Name'])) $data['Name'] = basename($relativeTargetPath); - if($parent) $data['ParentID'] = $parent->ID; $this->createdFilesPaths[] = $targetPath; return $data; } + /** + * + * @return AssetStore + */ + protected function getAssetStore() { + return singleton('AssetStore'); + } + /** * Converts a natural language class description to an actual class name. * Respects {@link DataObject::$singular_name} variations. From 8d49da260988b1cee1eac420f37bfe80d4c0eb6b Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 19 Oct 2015 10:55:56 +1300 Subject: [PATCH 05/16] Fixed Folder::find_or_make() use --- src/SilverStripe/BehatExtension/Context/FixtureContext.php | 4 +++- tests/Context/FixtureContextTest.php | 0 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 tests/Context/FixtureContextTest.php diff --git a/src/SilverStripe/BehatExtension/Context/FixtureContext.php b/src/SilverStripe/BehatExtension/Context/FixtureContext.php index dc81e56..b7a54ac 100644 --- a/src/SilverStripe/BehatExtension/Context/FixtureContext.php +++ b/src/SilverStripe/BehatExtension/Context/FixtureContext.php @@ -546,10 +546,12 @@ class FixtureContext extends BehatContext $sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath)); // Create file or folder on filesystem - $parent = \Folder::find_or_make(dirname($relativeTargetPath)); + $parent = null; if($class == 'Folder' || is_subclass_of($class, 'Folder')) { + $parent = \Folder::find_or_make($relativeTargetPath); $targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath); } else { + $parent = \Folder::find_or_make(dirname($relativeTargetPath)); if(!file_exists($sourcePath)) { throw new \InvalidArgumentException(sprintf( 'Source file for "%s" cannot be found in "%s"', diff --git a/tests/Context/FixtureContextTest.php b/tests/Context/FixtureContextTest.php new file mode 100644 index 0000000..e69de29 From 71cfcab8c08b416a138d7167549cd40e7e3018c3 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 19 Oct 2015 13:45:17 +1300 Subject: [PATCH 06/16] Remove php 5.3 for framework 4.0 compatibility --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2ec2ce8..6d991f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ language: php sudo: false php: - - 5.3 - 5.4 - 5.5 From f4b5150763412797d262f141b0af06076c291ab4 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 20 Oct 2015 11:39:36 +1300 Subject: [PATCH 07/16] Noted --name in README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 1db2c84..2d0b8aa 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,10 @@ Now you can run the tests (for example for the `framework` module): In order to run specific tests only, use their feature file name: vendor/bin/behat @framework/login.feature + +Or even run a single scenario by it's name (supports regular expressions): + + vendor/bin/behat --name 'My scenario title' @framework This will start a Firefox browser by default. Other browsers and profiles can be configured in `behat.yml`. From d39c8ebd29800d056cf0b1aada22047f6c164d8a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 22 Oct 2015 13:27:09 +1300 Subject: [PATCH 08/16] Fix nested folder fixture creation Fixes regression caused by 8d49da260988b1cee1eac420f37bfe80d4c0eb6b prepareAsset('Folder','some/folder') would create some/folder/folder due to wrong ParentID relations. Also set the 'ID' of folders to avoid creating them again. --- src/SilverStripe/BehatExtension/Context/FixtureContext.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/SilverStripe/BehatExtension/Context/FixtureContext.php b/src/SilverStripe/BehatExtension/Context/FixtureContext.php index b7a54ac..e365e8b 100644 --- a/src/SilverStripe/BehatExtension/Context/FixtureContext.php +++ b/src/SilverStripe/BehatExtension/Context/FixtureContext.php @@ -550,6 +550,7 @@ class FixtureContext extends BehatContext if($class == 'Folder' || is_subclass_of($class, 'Folder')) { $parent = \Folder::find_or_make($relativeTargetPath); $targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath); + $data['ID'] = $parent->ID; } else { $parent = \Folder::find_or_make(dirname($relativeTargetPath)); if(!file_exists($sourcePath)) { @@ -559,6 +560,8 @@ class FixtureContext extends BehatContext $sourcePath )); } + $data['ParentID'] = $parent->ID; + // Load file into APL and retrieve tuple $asset = $this->getAssetStore()->setFromLocalFile( $sourcePath, @@ -575,13 +578,9 @@ class FixtureContext extends BehatContext $url = $this->getAssetStore()->getAsURL($asset['Filename'], $asset['Hash'], $asset['Variant']); $targetPath = $this->joinPaths(BASE_PATH, substr($url, strlen(\Director::baseURL()))); } - unset($data['Filename']); if(!isset($data['Name'])) { $data['Name'] = basename($relativeTargetPath); } - if($parent) { - $data['ParentID'] = $parent->ID; - } $this->createdFilesPaths[] = $targetPath; From b2ff3e73ada6154614b72bfa8fca2b6b578f6354 Mon Sep 17 00:00:00 2001 From: scott1702 Date: Thu, 22 Oct 2015 16:13:47 +1300 Subject: [PATCH 09/16] Add double click action --- README.md | 2 +- .../BehatExtension/Context/BasicContext.php | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2d0b8aa..e006b2d 100644 --- a/README.md +++ b/README.md @@ -584,7 +584,7 @@ It's based on the `vendor/bin/behat -di @cms` output. Given /^I press the "([^"]*)" button$/ - Given /^I click "([^"]*)" in the "([^"]*)" element$/ + Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element$/ Given /^I type "([^"]*)" into the dialog$/ diff --git a/src/SilverStripe/BehatExtension/Context/BasicContext.php b/src/SilverStripe/BehatExtension/Context/BasicContext.php index a6ee63b..0283810 100644 --- a/src/SilverStripe/BehatExtension/Context/BasicContext.php +++ b/src/SilverStripe/BehatExtension/Context/BasicContext.php @@ -381,18 +381,20 @@ JS; } /** - * @Given /^I click "([^"]*)" in the "([^"]*)" element$/ + * @Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element$/ */ - public function iClickInTheElement($text, $selector) { + public function iClickInTheElement($clickType, $text, $selector) { + $clickTypeMap = array( + "double click" => "doubleclick", + "click" => "click" + ); $page = $this->getSession()->getPage(); - $parentElement = $page->find('css', $selector); assertNotNull($parentElement, sprintf('"%s" element not found', $selector)); - $element = $parentElement->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $text)); assertNotNull($element, sprintf('"%s" not found', $text)); - - $element->click(); + $clickTypeFn = $clickTypeMap[$clickType]; + $element->$clickTypeFn(); } /** From 33eb0adf0cbb94907d93d80bb6d528523bd8eeb8 Mon Sep 17 00:00:00 2001 From: scott1702 Date: Thu, 22 Oct 2015 16:27:48 +1300 Subject: [PATCH 10/16] Add ability to confirm/dismiss dialogs after clicking in elements --- README.md | 4 ++++ .../BehatExtension/Context/BasicContext.php | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 2d0b8aa..4af1773 100644 --- a/README.md +++ b/README.md @@ -591,6 +591,10 @@ It's based on the `vendor/bin/behat -di @cms` output. Given /^I (?:press|follow) the "([^"]*)" (?:button|link), confirming the dialog$/ Given /^I (?:press|follow) the "([^"]*)" (?:button|link), dismissing the dialog$/ + + Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element, confirming the dialog$/ + + Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element, dismissing the dialog$/ Given /^I confirm the dialog$/ diff --git a/src/SilverStripe/BehatExtension/Context/BasicContext.php b/src/SilverStripe/BehatExtension/Context/BasicContext.php index a6ee63b..f629258 100644 --- a/src/SilverStripe/BehatExtension/Context/BasicContext.php +++ b/src/SilverStripe/BehatExtension/Context/BasicContext.php @@ -394,6 +394,27 @@ JS; $element->click(); } + + /** + * 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 + * + * @Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element, confirming the dialog$/ + */ + public function iClickInTheElementConfirmingTheDialog($clickType, $text, $selector) { + $this->iClickInTheElement($clickType, $text, $selector); + $this->iConfirmTheDialog(); + } + /** + * Needs to be in single command to avoid "unexpected alert open" errors in Selenium. + * Example: I click "Delete" in the ".actions" element, dismissing the dialog + * + * @Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element, dismissing the dialog$/ + */ + public function iClickInTheElementDismissingTheDialog($clickType, $text, $selector) { + $this->iClickInTheElement($clickType, $text, $selector); + $this->iDismissTheDialog(); + } /** * @Given /^I type "([^"]*)" into the dialog$/ From 361933537e30cfd4b856aa7d6bce85d09fa62140 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 3 Dec 2015 12:19:57 +1300 Subject: [PATCH 11/16] Created 2.x branch alias for 4.x core compat --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index 18b7a68..f26cf7f 100644 --- a/composer.json +++ b/composer.json @@ -50,5 +50,10 @@ "vendor/phpunit/phpunit" ] }, + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, "minimum-stability": "dev" } From ef1304a61064b2e168adfbac0fc3a5fe2b8adfcd Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 3 Dec 2015 12:22:45 +1300 Subject: [PATCH 12/16] Fixed PHP build version compat --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6d991f2..ab9621e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ language: php sudo: false php: - - 5.4 - 5.5 + - 5.6 script: - vendor/bin/phpunit tests From 15f1a083fca43429db9c998241eaaf2eabec7ded Mon Sep 17 00:00:00 2001 From: Ben Manu Date: Tue, 8 Dec 2015 11:10:19 +1300 Subject: [PATCH 13/16] FIX: params isn't defined in this context, may be carry over from PHPUnit sessions. Changing context to $state to match other env values. --- src/SilverStripe/BehatExtension/Context/SilverStripeContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php index fce6d9f..c757c8d 100644 --- a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php +++ b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php @@ -200,7 +200,7 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex } // Fixtures - $fixtureFile = (!empty($params['fixture'])) ? $params['fixture'] : null; + $fixtureFile = (!empty($state['fixture'])) ? $state['fixture'] : null; if($fixtureFile) { $this->testSessionEnvironment->loadFixtureIntoDb($fixtureFile); } From 299cde3c9048aac08ebf1b131ccb9cf7f41097b6 Mon Sep 17 00:00:00 2001 From: Jeffrey Guo Date: Fri, 18 Dec 2015 15:42:48 +1300 Subject: [PATCH 14/16] add condition to prevent running endTestSession() twice reformatted with space indent --- .../Context/Initializer/SilverStripeAwareInitializer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SilverStripe/BehatExtension/Context/Initializer/SilverStripeAwareInitializer.php b/src/SilverStripe/BehatExtension/Context/Initializer/SilverStripeAwareInitializer.php index 4042364..ed79843 100644 --- a/src/SilverStripe/BehatExtension/Context/Initializer/SilverStripeAwareInitializer.php +++ b/src/SilverStripe/BehatExtension/Context/Initializer/SilverStripeAwareInitializer.php @@ -83,13 +83,13 @@ class SilverStripeAwareInitializer implements InitializerInterface public function __destruct() { - file_put_contents('php://stdout', "Killing test session environment..."); - + // Add condition here as register_shutdown_function() also calls this in __construct() if($this->testSessionEnvironment) { + file_put_contents('php://stdout', "Killing test session environment..."); $this->testSessionEnvironment->endTestSession(); + $this->testSessionEnvironment = null; + file_put_contents('php://stdout', " done!" . PHP_EOL); } - - file_put_contents('php://stdout', " done!" . PHP_EOL); } /** From 70a6d7777feb6ca25a7d11cb20eaa28f29e9ee0d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 8 Jan 2016 13:00:08 +1300 Subject: [PATCH 15/16] Removed goutte driver from docs Not a tested driver for framework tests. Might work, but we shouldn't recommend it. Plus, we'll need to add it as a composer requirement if mentioned in `behat.yml` (see #94). --- docs/chrome-behat.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/chrome-behat.md b/docs/chrome-behat.md index 554535f..50f5b79 100644 --- a/docs/chrome-behat.md +++ b/docs/chrome-behat.md @@ -10,7 +10,6 @@ If you would like to run Behat Tests using Google Chrome here are a few steps I ``` default_session: selenium2 javascript_session: selenium2 - goutte: ~ selenium2: browser: chrome SilverStripe\BehatExtension\Extension: @@ -27,4 +26,4 @@ java -jar selenium-server.jar -Dwebdriver.chrome.driver="/path/to/chromedriver" ``` behat @mysite --profile=chrome -``` \ No newline at end of file +``` From ae7b16308efee2d8e110edb4317b3995318dda76 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 25 Jan 2016 17:55:03 +1300 Subject: [PATCH 16/16] Revert "ENH: adding wrapper around visit to detect 404s" --- .../Context/SilverStripeContext.php | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php index 0e9aa94..a35080c 100644 --- a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php +++ b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php @@ -497,26 +497,5 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex EOS; $this->getSession()->getDriver()->executeScript($script); } - - - /** - * @Override "When /^(?:|I )go to "(?P[^"]+)"$/" - * We override this function to detect issues with .htaccess external redirects. - * - * For instance, if the behat test is being run with a base_url which includes a - * path, e.g. "http://localhost/behat-test-abc123/", .htaccess redirects may take the browser - * to the wrong base path, e.g. "http://localhost/", which will then probably generate - * a apache 404 response, which is pretty standard and we can detect it and give a better - * error message. - */ - public function visit($page){ - parent::visit($page); - - // We now check the response body. We would check for the response status code, - // but that is not quite possible yet, so this is the best we can do. - $page = $this->getSession()->getPage(); - $title = $page->find('css', 'title')->getHtml(); // getText returns empty string, so have to use getHtml - assertNotEquals('404 Not Found', $title, 'A 404 response was detected from the server. If you intended to test an apache 404 response, please write a specific 404 test step.'); - } - + }