API Upgrade to behat 3

This commit is contained in:
Damian Mooyman 2017-01-20 15:57:50 +13:00 committed by Sam Minnée
parent 9dff7e4eeb
commit 942c0257b7
16 changed files with 88 additions and 195 deletions

View File

@ -68,6 +68,7 @@ before_script:
- if [[ $PHPUNIT_TEST == cms ]] || [[ $BEHAT_TEST == cms ]]; then php ./cms/tests/bootstrap/mysite.php; fi
# Start behat services
- if [[ $BEHAT_TEST ]]; then echo 'SS_BASE_URL=http://localhost:8080/' >> .env; fi
- if [[ $BEHAT_TEST ]]; then sh -e /etc/init.d/xvfb start; sleep 3; fi
- if [[ $BEHAT_TEST ]]; then (vendor/bin/selenium-server-standalone > selenium.log 2>&1 &); fi
- if [[ $BEHAT_TEST == framework ]]; then (vendor/bin/serve --bootstrap-file tests/behat/serve-bootstrap.php &> serve.log &); fi
@ -76,8 +77,8 @@ before_script:
script:
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit --testsuite $PHPUNIT_TEST; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then vendor/bin/phpunit --testsuite $PHPUNIT_COVERAGE_TEST --coverage-clover=coverage.xml; fi
- if [[ $BEHAT_TEST == framework ]]; then vendor/bin/behat --config tests/behat/config.yml .; fi
- if [[ $BEHAT_TEST == cms ]]; then vendor/bin/behat @cms --config tests/behat/cms-config.yml; fi
- if [[ $BEHAT_TEST == framework ]]; then vendor/bin/behat @framework; fi
- if [[ $BEHAT_TEST == cms ]]; then vendor/bin/behat @cms; fi
- if [[ $PHPCS_TEST ]]; then composer run-script lint; fi
- if [[ $PHPCS_TEST ]]; then composer run-script php-peg; fi
- if [[ $PHPCS_TEST ]]; then git diff-files --quiet -w --relative=src; fi

26
behat.yml Normal file
View File

@ -0,0 +1,26 @@
default:
suites:
framework:
paths:
- %paths.modules.framework%/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\BehatExtension\Context\LoginContext
-
SilverStripe\BehatExtension\Context\FixtureContext:
- %paths.modules.framework%/tests/behat/features/files/
extensions:
SilverStripe\BehatExtension\MinkExtension:
default_session: selenium2
javascript_session: selenium2
selenium2:
browser: firefox
SilverStripe\BehatExtension\Extension:
screenshot_path: %paths.base%/tests/behat/artifacts/screenshots
bootstrap_file: "tests/behat/serve-bootstrap.php"

View File

@ -25,9 +25,9 @@
"silverstripe/assets": "^1@dev",
"swiftmailer/swiftmailer": "~5.4",
"symfony/cache": "^3.3@dev",
"symfony/config": "^2.8",
"symfony/config": "^3.2",
"symfony/translation": "^2.8",
"symfony/yaml": "~2.7",
"symfony/yaml": "~3.2",
"vlucas/phpdotenv": "^2.4",
"php": ">=5.6.0",
@ -44,9 +44,8 @@
"require-dev": {
"phpunit/phpunit": "^5.7",
"silverstripe/versioned": "^1.0@dev",
"silverstripe/behat-extension": "^2.1.0",
"silverstripe/behat-extension": "^3",
"silverstripe/serve": "dev-master",
"silverstripe/testsession": "^2.0.0-alpha3",
"se/selenium-server-standalone": "2.41.0"
},
"extra": {
@ -72,13 +71,13 @@
"SilverStripe\\Security\\": "src/Security/",
"SilverStripe\\Security\\Tests\\": "tests/php/Security/",
"SilverStripe\\View\\": "src/View/",
"SilverStripe\\View\\Tests\\": "tests/php/View/"
"SilverStripe\\View\\Tests\\": "tests/php/View/",
"SilverStripe\\Framework\\Tests\\Behaviour\\": "tests/behat/src/"
},
"files": [
"src/Core/Constants.php",
"src/Dev/PhpUnitShim.php"
],
"classmap": ["tests/behat/features/bootstrap"]
]
},
"include-path": [
"src/",

View File

@ -53,6 +53,8 @@ guide developers in preparing existing 3.x code for compatibility with 4.0
* Replaced `Zend_Cache` and the `Cache` API with a PSR-16 implementation (symfony/cache)
* _ss_environment.php files have been removed in favour of `.env` and "real" environment variables.
* admin has been moved to a new module [silverstripe/admin](https://github.com/silverstripe/silverstripe-admin).
* Behat support updated to behat 3. See the
[behat extension](https://github.com/silverstripe/silverstripe-behat-extension) for more information.
## <a name="upgrading"></a>Upgrading
@ -1336,6 +1338,7 @@ A very small number of methods were chosen for deprecation, and will be removed
* Search filter classes (e.g. `ExactMatchFilter`) are now registered with `Injector`
via a new `DataListFilter.` prefix convention.
see [search filter documentation](/developer_guides/model/searchfilters) for more information.
* `Permission::flush_permission_cache()` renamed to `reset()` and added to `Resettable` interface.
* `Versioned` API has some breaking changes:
* Versioned constructor now only allows a single string to declare whether staging is enabled or not. The
number of names of stages are no longer able to be specified. See below for upgrading notes for models

View File

@ -2,6 +2,8 @@
namespace SilverStripe\Dev;
use SilverStripe\Assets\File;
class BehatFixtureFactory extends FixtureFactory
{
public function createObject($name, $identifier, $data = null)
@ -12,7 +14,7 @@ class BehatFixtureFactory extends FixtureFactory
// Copy identifier to some visible property unless its already defined.
// Exclude files, since they generate their own named based on the file path.
if (!is_a($name, 'SilverStripe\\Assets\\File', true)) {
if (!is_a($name, File::class, true)) {
foreach (array('Name', 'Title') as $fieldName) {
if (singleton($name)->hasField($fieldName) && !isset($data[$fieldName])) {
$data[$fieldName] = $identifier;

View File

@ -1042,7 +1042,7 @@ class Member extends DataObject implements TemplateGlobalProvider
{
parent::onAfterWrite();
Permission::flush_permission_cache();
Permission::reset();
if ($this->isChanged('Password')) {
MemberPassword::log($this);

View File

@ -3,6 +3,7 @@
namespace SilverStripe\Security;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Resettable;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataObject;
@ -19,7 +20,7 @@ use SilverStripe\View\TemplateGlobalProvider;
* @property int GroupID
* @method Group Group()
*/
class Permission extends DataObject implements TemplateGlobalProvider
class Permission extends DataObject implements TemplateGlobalProvider, Resettable
{
// the (1) after Type specifies the DB default value which is needed for
@ -148,7 +149,7 @@ class Permission extends DataObject implements TemplateGlobalProvider
* Flush the permission cache, for example if you have edited group membership or a permission record.
* @todo Call this whenever Group_Members is added to or removed from
*/
public static function flush_permission_cache()
public static function reset()
{
self::$cache_permissions = array();
}
@ -711,7 +712,7 @@ class Permission extends DataObject implements TemplateGlobalProvider
parent::onBeforeWrite();
// Just in case we've altered someone's permissions
Permission::flush_permission_cache();
Permission::reset();
}
public static function get_template_global_variables()

View File

@ -1,22 +0,0 @@
# Required to run cms tests as subdirectory within framework module
default:
context:
class: SilverStripe\Cms\Test\Behaviour\FeatureContext
formatter:
name: pretty
parameters:
snippets: false
extensions:
SilverStripe\BehatExtension\MinkExtension:
base_url: http://localhost:8080/
files_path: %behat.paths.base%/features/files/
default_session: selenium2
javascript_session: selenium2
selenium2:
browser: firefox
SilverStripe\BehatExtension\Extension:
screenshot_path: %behat.paths.base%/artifacts/screenshots
framework_path: "../.."
bootstrap_file: "cms/tests/behat/serve-bootstrap.php"

View File

@ -1,23 +0,0 @@
default:
context:
class: SilverStripe\Framework\Test\Behaviour\FeatureContext
filters:
tags: "~@todo"
formatter:
name: pretty
parameters:
snippets: false
extensions:
SilverStripe\BehatExtension\MinkExtension:
base_url: http://localhost:8080/
files_path: %behat.paths.base%/features/files/
default_session: selenium2
javascript_session: selenium2
selenium2:
browser: firefox
SilverStripe\BehatExtension\Extension:
screenshot_path: %behat.paths.base%/artifacts/screenshots
framework_path: "../.."
bootstrap_file: "tests/behat/serve-bootstrap.php"

View File

@ -1,85 +0,0 @@
<?php
namespace SilverStripe\Framework\Test\Behaviour;
use SilverStripe\BehatExtension\Context\SilverStripeContext;
use SilverStripe\BehatExtension\Context\BasicContext;
use SilverStripe\BehatExtension\Context\LoginContext;
use SilverStripe\BehatExtension\Context\FixtureContext;
use SilverStripe\BehatExtension\Context\EmailContext;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\BehatFixtureFactory;
use SilverStripe\Dev\FixtureFactory;
/**
* Features context
*
* Context automatically loaded by Behat.
* Uses subcontexts to extend functionality.
*/
class FeatureContext extends SilverStripeContext
{
/**
* @var FixtureFactory
*/
protected $fixtureFactory;
/**
* 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)
{
parent::__construct($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));
$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('SilverStripe\\Dev\\FixtureBlueprint', 'SilverStripe\\Security\\Member');
$blueprint->addCallback('beforeCreate', function ($identifier, &$data, &$fixtures) {
if (!isset($data['FirstName'])) {
$data['FirstName'] = $identifier;
}
});
$factory->define('SilverStripe\\Security\\Member', $blueprint);
}
public function setMinkParameters(array $parameters)
{
parent::setMinkParameters($parameters);
if (isset($parameters['files_path'])) {
/** @var FixtureContext $fixtureContext */
$fixtureContext = $this->getSubcontext('FixtureContext');
$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;
}
}

View File

@ -15,6 +15,5 @@ Feature: Log in
Scenario: /admin/ redirect for not logged in user
# disable automatic redirection so we can use the profiler
When I go to "/admin/" without redirection
Then I should be redirected to "/Security/login"
When I go to "/admin/"
And I should see a log-in form

View File

@ -12,11 +12,11 @@ Feature: Lost Password
When I follow "I've lost my password"
And I fill in "admin@test.com" for "Email"
And I press the "Send me the password reset link" button
Then I should see "Password reset link sent to 'admin@test.com'"
Then I should see "A reset link has been sent to 'admin@test.com'"
And there should be an email to "admin@test.com" titled "Your password reset link"
When I click on the "password reset link" link in the email to "admin@test.com"
Then I should see "Please enter a new password"
When I fill in "newpassword" for "New Password"
And I fill in "newpassword" for "Confirm New Password"
And I press the "Change Password" button
Then the password for "admin@test.com" should be "newpassword"
Then the password for "admin@test.com" should be "newpassword"

View File

@ -1,10 +1,11 @@
<?php
namespace SilverStripe\Framework\Test\Behaviour;
namespace SilverStripe\Framework\Tests\Behaviour;
use Behat\Behat\Context\BehatContext;
use Behat\Behat\Context\Context;
use Behat\Mink\Exception\ElementHtmlException;
use Behat\Gherkin\Node\TableNode;
use SilverStripe\BehatExtension\Context\MainContextAwareTrait;
use Symfony\Component\DomCrawler\Crawler;
use Behat\Mink\Element\NodeElement;
use SilverStripe\SiteConfig\SiteConfig;
@ -14,21 +15,9 @@ use SilverStripe\SiteConfig\SiteConfig;
*
* Context used to define steps related to forms inside CMS.
*/
class CmsFormsContext extends BehatContext
class CmsFormsContext implements Context
{
protected $context;
/**
* 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)
{
// Initialize your context here
$this->context = $parameters;
}
use MainContextAwareTrait;
/**
* Get Mink session from MinkContext

View File

@ -1,33 +1,23 @@
<?php
namespace SilverStripe\Framework\Test\Behaviour;
namespace SilverStripe\Framework\Tests\Behaviour;
use Behat\Behat\Context\BehatContext;
use Behat\Behat\Context\Step;
use Behat\Behat\Event\StepEvent;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Session;
use Behat\Behat\Context\Context;
use SilverStripe\BehatExtension\Context\MainContextAwareTrait;
use SilverStripe\BehatExtension\Context\RetryableContextTrait;
use SilverStripe\BehatExtension\Utility\StepHelper;
/**
* CmsUiContext
*
* Context used to define steps related to SilverStripe CMS UI like Tree or Panel.
*/
class CmsUiContext extends BehatContext
class CmsUiContext implements Context
{
protected $context;
/**
* 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)
{
// Initialize your context here
$this->context = $parameters;
}
use MainContextAwareTrait;
use StepHelper;
/**
* Get Mink session from MinkContext
@ -148,9 +138,9 @@ class CmsUiContext extends BehatContext
*/
public function stepIShouldSeeInCmsTree($text)
{
$cms_tree_element = $this->getCmsTreeElement();
$element = $cms_tree_element->find('named', array('content', "'$text'"));
// Wait until visible
$cmsTreeElement = $this->getCmsTreeElement();
$element = $cmsTreeElement->find('named', array('content', "'$text'"));
assertNotNull($element, sprintf('%s not found', $text));
}
@ -159,9 +149,9 @@ class CmsUiContext extends BehatContext
*/
public function stepIShouldNotSeeInCmsTree($text)
{
$cms_tree_element = $this->getCmsTreeElement();
$element = $cms_tree_element->find('named', array('content', "'$text'"));
// Wait until not visible
$cmsTreeElement = $this->getCmsTreeElement();
$element = $cmsTreeElement->find('named', array('content', "'$text'"));
assertNull($element, sprintf('%s found', $text));
}
@ -390,10 +380,8 @@ SCRIPT
*/
public function iSetTheCmsToMode($mode)
{
return array(
new Step\When(sprintf('I fill in the "Change view mode" dropdown with "%s"', $mode)),
new Step\When('I wait for 1 second') // wait for CMS layout to redraw
);
$this->theIFillInTheDropdownWith('Change view mode', $mode);
sleep(1);
}
/**
@ -430,7 +418,7 @@ SCRIPT
$label->click();
return new Step\When('I wait for the preview to load');
$this->iWaitForThePreviewToLoad();
}
/**

View File

@ -0,0 +1,15 @@
<?php
namespace SilverStripe\Framework\Tests\Behaviour;
use SilverStripe\BehatExtension\Context\SilverStripeContext;
/**
* Features context
*
* Context automatically loaded by Behat.
* Uses subcontexts to extend functionality.
*/
class FeatureContext extends SilverStripeContext
{
}

View File

@ -30,13 +30,13 @@ class SecurityDefaultAdminTest extends SapphireTest
$this->defaultPassword = Security::default_admin_password();
Security::clear_default_admin();
Security::setDefaultAdmin('admin', 'password');
Permission::flush_permission_cache();
Permission::reset();
}
protected function tearDown()
{
Security::setDefaultAdmin($this->defaultUsername, $this->defaultPassword);
Permission::flush_permission_cache();
Permission::reset();
parent::tearDown();
}