diff --git a/.travis.yml b/.travis.yml index 72b95e6..15337f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ language: php addons: firefox: "31.0" +# Required for Behat, currently +dist: precise + env: global: - COMPOSER_ROOT_VERSION="4.0.x-dev" @@ -17,9 +20,8 @@ matrix: env: DB=PGSQL PHPUNIT_TEST=1 - php: 7.1 env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1 - # @todo Fix behat - # - php: 7.0 - # env: DB=MYSQL BEHAT_TEST=1 + - php: 7.0 + env: DB=MYSQL BEHAT_TEST=1 before_script: - phpenv rehash @@ -43,7 +45,7 @@ before_script: script: - - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/php/ flush=1; fi + - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=framework/phpcs.xml.dist code/ tests/ ; fi - if [[ $BEHAT_TEST ]]; then vendor/bin/behat @subsites; fi diff --git a/behat.yml b/behat.yml new file mode 100644 index 0000000..6bfe6e5 --- /dev/null +++ b/behat.yml @@ -0,0 +1,27 @@ +default: + suites: + subsites: + paths: + - %paths.modules.subsites%/tests/behat/features + contexts: + - SilverStripe\Framework\Tests\Behaviour\FeatureContext + - SilverStripe\Framework\Tests\Behaviour\CmsFormsContext + - SilverStripe\Framework\Tests\Behaviour\CmsUiContext + - SilverStripe\BehatExtension\Context\BasicContext + - SilverStripe\BehatExtension\Context\EmailContext + - SilverStripe\CMS\Tests\Behaviour\LoginContext + - SilverStripe\CMS\Tests\Behaviour\ThemeContext + - SilverStripe\CMS\Tests\Behaviour\FixtureContext: + # Note: double indent for args is intentional + - %paths.modules.subsites%/tests/behat/features/files/ + + extensions: + SilverStripe\BehatExtension\MinkExtension: + default_session: selenium2 + javascript_session: selenium2 + selenium2: + browser: firefox + + SilverStripe\BehatExtension\Extension: + screenshot_path: %paths.base%/artifacts/screenshots + bootstrap_file: "cms/tests/behat/serve-bootstrap.php" diff --git a/tests/behat/features/bootstrap/Context/FeatureContext.php b/tests/behat/features/bootstrap/Context/FeatureContext.php deleted file mode 100644 index bd89c40..0000000 --- a/tests/behat/features/bootstrap/Context/FeatureContext.php +++ /dev/null @@ -1,115 +0,0 @@ -useContext('BasicContext', new BasicContext($parameters)); - $this->useContext('LoginContext', new LoginContext($parameters)); - $this->useContext('CmsFormsContext', new CmsFormsContext($parameters)); - $this->useContext('CmsUiContext', new CmsUiContext($parameters)); - - $fixtureContext = new FixtureContext($parameters); - $fixtureContext->setFixtureFactory($this->getFixtureFactory()); - $this->useContext('FixtureContext', $fixtureContext); - - // Use blueprints to set user name from identifier - $factory = $fixtureContext->getFixtureFactory(); - $blueprint = Injector::inst()->create(FixtureBlueprint::class, Member::class); - $blueprint->addCallback('beforeCreate', function ($identifier, &$data, &$fixtures) { - if (!isset($data['FirstName'])) { - $data['FirstName'] = $identifier; - } - }); - $factory->define(Member::class, $blueprint); - - // Auto-publish pages - foreach (ClassInfo::subclassesFor(SiteTree::class) as $id => $class) { - $blueprint = Injector::inst()->create(FixtureBlueprint::class, $class); - $blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) { - $obj->copyVersionToStage('Stage', 'Live'); - }); - $factory->define($class, $blueprint); - } - } - - public function setMinkParameters(array $parameters) - { - parent::setMinkParameters($parameters); - if (isset($parameters['files_path'])) { - $this->getSubcontext('FixtureContext')->setFilesPath($parameters['files_path']); - } - } - - /** - * @return FixtureFactory - */ - public function getFixtureFactory() - { - if (!$this->fixtureFactory) { - $this->fixtureFactory = Injector::inst()->create(BehatFixtureFactory::class); - } - - return $this->fixtureFactory; - } - - public function setFixtureFactory(FixtureFactory $factory) - { - $this->fixtureFactory = $factory; - } - - // - // Place your definition and hook methods here: - // - // /** - // * @Given /^I have done something with "([^"]*)"$/ - // */ - // public function iHaveDoneSomethingWith($argument) { - // $container = $this->kernel->getContainer(); - // $container->get('some_service')->doSomethingWith($argument); - // } - // -} diff --git a/tests/behat/features/preview-navigation.feature b/tests/behat/features/preview-navigation.feature index 61d1ba5..cab58b6 100644 --- a/tests/behat/features/preview-navigation.feature +++ b/tests/behat/features/preview-navigation.feature @@ -5,22 +5,21 @@ Feature: Preview navigation Background: Given a "subsite" "My subsite" - And a "page" "My page" with "URLSegment"="my-page", "Content"="My page content anameahref" and "Subsite"="=>Subsite.My subsite" - And a "page" "Other page" with "URLSegment"="other-page", "Content"="Other page content
" and "Subsite"="=>Subsite.My subsite" + And a "page" "My page" with "URLSegment"="my-page", "Content"="My page content anameahref" and "Subsite"="=>SilverStripe\Subsites\Model\Subsite.My subsite" + And a "page" "Other page" with "URLSegment"="other-page", "Content"="Other page content Goto my page>" and "Subsite"="=>SilverStripe\Subsites\Model\Subsite.My subsite" Given a "member" "Joe" belonging to "Admin Group" with "Email"="joe@test.com" and "Password"="Password1" And the "group" "Admin Group" has permissions "Full administrative rights" And I log in with "joe@test.com" and "Password1" + @javascript Scenario: I can navigate the subsite preview When I go to "admin" And I select "My subsite" from "SubsitesSelect" And I go to "admin/pages" And I click on "My page" in the tree - And I wait for 3 seconds And I set the CMS mode to "Preview mode" And I follow "ahref" in preview Then the preview contains "Other page content" - # We are already on the second page, submit the form to return to first one. - When I wait for 3 seconds - And I press "Submit my form" in preview + # We are already on the second page, submit the form to return to first one. + And I follow "Goto my page" in preview Then the preview contains "My page content"