diff --git a/README.md b/README.md index 046197a..a4b911a 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,438 @@ -# BehatMage +## BehatMage Behat extension for Magento, providing Behat context with specific Magento requirements allowing you to quickly define Magento scenarios and steps to enable BDD within Magento projects. -# Documentation +## Target -This is coming very soon! +* To create a tool that makes testing easy and straight forward to use for testing external behavior of Magento. +* To create a tool that provides clear feedback when exceptions are raised. The feedback should coach the developer on how to resolve the issue and the messaging should be correct to the Magento domain. -# License and Authors +## How? + +* The tool can be installed easily with composer. +* The creation of standard scenarios can be accomplished without the need to create new contexts. +* There are no exceptions raised that do not provide feedback on how to proceed or resolve the issue. +* The documentation includes examples of how to use each feature of the tool. + +## Installation + +### Prerequisites + +BehatMage requires PHP 5.3.x or greater. + +### Method 1 (composer) + +First, add BehatMage to the list of dependencies inside your `composer.json` and be sure to register few paths for autoloading: + +```json +{ + "config": { + "bin-dir": "bin" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "magetest/magento-behat-extension": "dev-develop" + }, + "autoload": { + "psr-0": { + "": [ + "app", + "app/code/local", + "app/code/community", + "app/code/core", + "lib" + ] + } + }, + "minimum-stability": "dev" +} +``` + +Then simply install it with composer: + +```bash +$ composer install --dev --prefer-dist +``` + +You can read more about Composer on its [official webpage](http://getcomposer.org). + +## Basic usage + +Change directory to your project one and setup behat inside the directory: + +```bash +$ cd project +$ behat --init +``` + +The behat --init will create a features/ directory with some basic things to get your started. +The output on the screen should be similar to: + +```bash +$ bin/behat --init ++d features - place your *.feature files here ++d features/bootstrap - place bootstrap scripts and static files here ++f features/bootstrap/FeatureContext.php - place your feature related code here +``` + +### Define your feature + +Everything in Behat always starts with a feature that you want to describe and then implement. In this example, the feature will be give an admin user the ability to manage review visibility, so we can start by creating a features/admin_user_manages_review_visibility.feature file: + +```Cucumber +Feature: Admin User can manage review visibility + So that our Customers are not influenced by a product with bad review history, + as an Admin User + I want to disable reviews of those specific products +``` + +Every feature starts with this same format: a line naming the feature, followed by three lines that describe the benefit, the role and the feature itself. And while this section is required, its contents aren’t actually important to Behat or your eventual test. This section is important, however, so that each feature is described consistently and is readable by other people. + +### Define a scenario + +Next, add the following scenario to the end of the features/admin_user_manages_review_visibility.feature file: + +```Cucumber +Scenario: Turn off reviews per product + Given the following products exist: + | sku | name | accepts_reviews | + | Ottoman1 | Ottoman | 1 | + And "Ottoman1" has existing reviews + When I turn reviews off for "Ottoman1" product + Then no review should be displayed for "Ottoman1" +``` + +Each feature is defined by one or more “scenarios”, which explain how that feature should act under different conditions. This is the part that will be transformed into a test. Each scenario always follows the same basic format: + +```Cucumber +Scenario: Some description of the scenario + Given [some context] + When [some event] + Then [outcome] +``` + +Each part of the scenario - the context, the event, and the outcome - can be extended by adding the And or But keyword: + +```Cucumber +Scenario: Some description of the scenario + Given [some context] + And [more context] + When [some event] + And [second event occurs] + Then [outcome] + And [another outcome] + But [another outcome] +``` + +There’s no actual difference between, Then, And But or any of the other words that start each line. These keywords are all made available so that your scenarios are natural and readable. + +### Executing Behat + +You’ve now defined the feature and one scenario for that feature. You’re ready to see Behat in action! Try executing Behat from inside your project directory: + +```bash +$ bin/behat +``` + +If everything worked correctly, you should see something like this: + +```bash +Feature: Admin User can manage review visibility + So that our Customers are not influenced by a product with bad review history, + as an Admin User + I want to disable reviews of those specific products + + Scenario: Turn off reviews per product # features/reviews/admin_user_manages_review_visibility.feature:7 + Given the following products exist: + | sku | name | accepts_reviews | + | Ottoman1 | Ottoman | 1 | + And "Ottoman1" has existing reviews + When I turn reviews off for "Ottoman1" product + Then no review should be displayed for "Ottoman1" + +1 scenario (1 undefined) +4 steps (4 undefined) +0m1.836s + +You can implement step definitions for undefined steps with these snippets: + + /** + * @Given /^the following products exist:$/ + */ + public function theFollowingProductsExist(TableNode $table) + { + throw new PendingException(); + } + + /** + * @Given /^"([^"]*)" has existing reviews$/ + */ + public function hasExistingReviews($arg1) + { + throw new PendingException(); + } + + /** + * @When /^I turn reviews off for "([^"]*)" product$/ + */ + public function iTurnReviewsOffForProduct($arg1) + { + throw new PendingException(); + } + + /** + * @Then /^no review should be displayed for "([^"]*)"$/ + */ + public function noReviewShouldBeDisplayedFor($arg1) + { + throw new PendingException(); + } +``` + +### Writing your step definition + +Behat automatically finds the feature/admin_user_manages_review_visibility.feature file and tries to execute its Scenario as a test. However, we haven’t told Behat what to do with statements like Given the following products exist, which causes an error. Behat works by matching each statement of a Scenario to a list of regular expression “steps” that you define. In other words, it’s your job to tell Behat what to do when it sees Given the following products exist. Fortunately, Behat helps you out by printing the regular expression that you probably need in order to create that step definition: + +```bash +You can implement step definitions for undefined steps with these snippets: + + /** + * @Given /^the following products exist:$/ + */ + public function theFollowingProductsExist(TableNode $table) + { + throw new PendingException(); + } + + /** + * @Given /^"([^"]*)" has existing reviews$/ + */ + public function hasExistingReviews($arg1) + { + throw new PendingException(); + } + + /** + * @When /^I turn reviews off for "([^"]*)" product$/ + */ + public function iTurnReviewsOffForProduct($arg1) + { + throw new PendingException(); + } + + /** + * @Then /^no review should be displayed for "([^"]*)"$/ + */ + public function noReviewShouldBeDisplayedFor($arg1) + { + throw new PendingException(); + } +``` + +Behat, however, is not aware yet of the Magento domain and it's requiring us to add step definitions that we likely want to skip because of their repetitive nature. We then have to make Behat be Magento aware using its configuration file behat.yml adding the following lines: + +```yml +default: + extensions: + MageTest\MagentoExtension\Extension: + base_url: "http://project.development.local" + +``` + +where we tell Behat which extension to load and what store we want to test. Well done so far, we now have to tell Behat that we want to use, just for clarity, a specific sub context for every actor that we have, in our example admin user. In order to do so we have to update the features/bootstrap/FeatureContext.php file as following: + +```php +# features/bootstrap/FeatureContext.php +useContext('admin_user', new AdminUserContext($parameters)); + } +} +``` + +and create such a sub context as php class extending the MagentoContext provided by the BehatMage extension as following: + +```php +# features/bootstrap/AdminUserContext.php + diff --git a/composer.json b/composer.json index 31dced9..91b23bf 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,8 @@ "homepage": "https://github.com/MageTest/BehatMage", "license": "MIT", "require": { - "php": ">=5.3.0", - "behat/behat": "2.4.4", + "php": "~5.3", + "behat/behat": "~2.4.4", "behat/mink-extension": "*", "behat/mink-browserkit-driver": "*", "behat/mink-goutte-driver": ">=1.0.3" @@ -56,6 +56,10 @@ { "name": "Mark Slocock", "email": "mark@gpmd.co.uk" + }, + { + "name": "Other contributors", + "homepage": "https://github.com/MageTest/BehatMage/contributors" } ] } diff --git a/spec/MageTest/MagentoExtension/Context/ClassGuesser.php b/spec/MageTest/MagentoExtension/Context/ClassGuesser.php deleted file mode 100644 index 7111d96..0000000 --- a/spec/MageTest/MagentoExtension/Context/ClassGuesser.php +++ /dev/null @@ -1,44 +0,0 @@ - so we can send you a copy immediately. - * - * @category MageTest - * @package MagentoExtension - * @subpackage Context - * - * @copyright Copyright (c) 2012-2013 MageTest team and contributors. - */ -namespace spec\MageTest\MagentoExtension\Context; - -use PHPSpec2\ObjectBehavior; - -/** - * ClassGuesser - * - * @category MageTest - * @package MagentoExtension - * @subpackage Context - * - * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) - */ -class ClassGuesser extends ObjectBehavior -{ - function it_should_guess_which_context_to_add() - { - $this->guess()->shouldReturn( - array('MageTest\MagentoExtension\Context\MagentoAwareInterface') - ); - } -} diff --git a/spec/MageTest/MagentoExtension/EventListener/BeforeScenarioListener.php b/spec/MageTest/MagentoExtension/EventListener/BeforeScenarioListener.php deleted file mode 100644 index d29a5cf..0000000 --- a/spec/MageTest/MagentoExtension/EventListener/BeforeScenarioListener.php +++ /dev/null @@ -1,52 +0,0 @@ - so we can send you a copy immediately. - * - * @category MageTest - * @package MagentoExtension - * @subpackage EventListener - * - * @copyright Copyright (c) 2012-2013 MageTest team and contributors. - */ -namespace spec\MageTest\MagentoExtension\EventListener; - -use PHPSpec2\ObjectBehavior; - -/** - * BeforeScenarioListener - * - * @category MageTest - * @package MagentoExtension - * @subpackage EventListener - * - * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) - */ -class BeforeScenarioListener extends ObjectBehavior -{ - /** - * @param MageTest\MagentoExtension\Service\CacheManager $cacheManager - */ - function let($cacheManager) - { - $this->beConstructedWith($cacheManager); - } - - function it_should_clear_cache($cacheManager) - { - $cacheManager->clear()->shouldBeCalled(); - - $this->beforeScenario(); - } -} diff --git a/src/MageTest/Controller/Request/HttpTestCase.php b/src/MageTest/Controller/Request/HttpTestCase.php deleted file mode 100644 index 0d94065..0000000 --- a/src/MageTest/Controller/Request/HttpTestCase.php +++ /dev/null @@ -1,546 +0,0 @@ - so we can send you a copy immediately. - * - * @category MageTest - * @package Controller - * @subpackage Request - * - * @copyright Copyright (c) 2012-2013 MageTest team and contributors. - */ -namespace MageTest\Controller\Request; - -use Zend_Controller_Request_HttpTestCase; - -/** - * HttpTestCase - * - * @category MageTest - * @package Controller - * @subpackage Request - * - * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) - */ -class HttpTestCase extends Zend_Controller_Request_HttpTestCase -{ - const XML_NODE_DIRECT_FRONT_NAMES = 'global/request/direct_front_name'; - const MAGE_TEST_USER_AGENT = 'Mage-Test Mock Browser'; - - /** - * ORIGINAL_PATH_INFO - * @var string - */ - protected $_originalPathInfo= ''; - protected $_storeCode = null; - protected $_requestString = ''; - - /** - * Path info array used before applying rewrite from config - * - * @var null || array - */ - protected $_rewritedPathInfo= null; - protected $_requestedRouteName = null; - protected $_routingInfo = array(); - - protected $_route; - - protected $_directFrontNames = null; - protected $_controllerModule = null; - - /** - * Streight request flag. - * If flag is determined no additional logic is applicable - * - * @var $_isStraight bool - */ - protected $_isStraight = false; - - /** - * Request's original information before forward. - * - * @var array - */ - protected $_beforeForwardInfo = array(); - - /** - * Overload the constructor to set the User_agaent header - * - * @return void - * @author Alistair Stead - **/ - public function __construct() - { - parent::__construct(); - $this->setHeader('User-Agent', self::MAGE_TEST_USER_AGENT); - $this->setHeader('Accept', 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'); - } - - /** - * Returns ORIGINAL_PATH_INFO. - * This value is calculated instead of reading PATH_INFO - * directly from $_SERVER due to cross-platform differences. - * - * @return string - */ - public function getOriginalPathInfo() - { - if (empty($this->_originalPathInfo)) { - $this->setPathInfo(); - } - return $this->_originalPathInfo; - } - - public function getStoreCodeFromPath() - { - if (!$this->_storeCode) { - // get store view code - if ($this->_canBeStoreCodeInUrl()) { - $p = explode('/', trim($this->getPathInfo(), '/')); - $storeCode = $p[0]; - - $stores = Mage::app()->getStores(true, true); - - if ($storeCode !== '' && isset($stores[$storeCode])) { - array_shift($p); - $this->setPathInfo(implode('/', $p)); - $this->_storeCode = $storeCode; - Mage::app()->setCurrentStore($storeCode); - } - else { - $this->_storeCode = Mage::app()->getStore()->getCode(); - } - } else { - $this->_storeCode = Mage::app()->getStore()->getCode(); - } - - } - return $this->_storeCode; - } - - /** - * Set the PATH_INFO string - * Set the ORIGINAL_PATH_INFO string - * - * @param string|null $pathInfo - * @return Zend_Controller_Request_Http - */ - public function setPathInfo($pathInfo = null) - { - if ($pathInfo === null) { - $requestUri = $this->getRequestUri(); - if (null === $requestUri) { - return $this; - } - - // Remove the query string from REQUEST_URI - $pos = strpos($requestUri, '?'); - if ($pos) { - $requestUri = substr($requestUri, 0, $pos); - } - - $baseUrl = $this->getBaseUrl(); - $pathInfo = substr($requestUri, strlen($baseUrl)); - - if ((null !== $baseUrl) && (false === $pathInfo)) { - $pathInfo = ''; - } elseif (null === $baseUrl) { - $pathInfo = $requestUri; - } - - if ($this->_canBeStoreCodeInUrl()) { - $pathParts = explode('/', ltrim($pathInfo, '/'), 2); - $storeCode = $pathParts[0]; - - if (!$this->isDirectAccessFrontendName($storeCode)) { - $stores = Mage::app()->getStores(true, true); - if ($storeCode!=='' && isset($stores[$storeCode])) { - Mage::app()->setCurrentStore($storeCode); - $pathInfo = '/'.(isset($pathParts[1]) ? $pathParts[1] : ''); - } - elseif ($storeCode !== '') { - $this->setActionName('noRoute'); - } - } - } - - $this->_originalPathInfo = (string) $pathInfo; - - $this->_requestString = $pathInfo . ($pos!==false ? substr($requestUri, $pos) : ''); - } - - $this->_pathInfo = (string) $pathInfo; - return $this; - } - - /** - * Specify new path info - * It happen when occur rewrite based on configuration - * - * @param string $pathInfo - * @return Mage_Core_Controller_Request_Http - */ - public function rewritePathInfo($pathInfo) - { - if (($pathInfo != $this->getPathInfo()) && ($this->_rewritedPathInfo === null)) { - $this->_rewritedPathInfo = explode('/', trim($this->getPathInfo(), '/')); - } - $this->setPathInfo($pathInfo); - return $this; - } - - /** - * Check if can be store code as part of url - * - * @return bool - */ - protected function _canBeStoreCodeInUrl() - { - return Mage::isInstalled() && Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL); - } - - /** - * Check if code declared as direct access frontend name - * this mean what this url can be used without store code - * - * @param string $code - * @return bool - */ - public function isDirectAccessFrontendName($code) - { - $names = $this->getDirectFrontNames(); - return isset($names[$code]); - } - - /** - * Get list of front names available with access without store code - * - * @return array - */ - public function getDirectFrontNames() - { - if (is_null($this->_directFrontNames)) { - $names = Mage::getConfig()->getNode(self::XML_NODE_DIRECT_FRONT_NAMES); - if ($names) { - $this->_directFrontNames = $names->asArray(); - } else { - return array(); - } - } - return $this->_directFrontNames; - } - - public function getOriginalRequest() - { - $request = new Zend_Controller_Request_Http(); - $request->setPathInfo($this->getOriginalPathInfo()); - return $request; - } - - public function getRequestString() - { - return $this->_requestString; - } - - public function getBasePath() - { - $path = parent::getBasePath(); - if (empty($path)) { - $path = '/'; - } else { - $path = str_replace('\\', '/', $path); - } - return $path; - } - - public function getBaseUrl() - { - $url = parent::getBaseUrl(); - $url = str_replace('\\', '/', $url); - return $url; - } - - public function setRouteName($route) - { - $this->_route = $route; - $router = Mage::app()->getFrontController()->getRouterByRoute($route); - if (!$router) return $this; - $module = $router->getFrontNameByRoute($route); - if ($module) { - $this->setModuleName($module); - } - return $this; - } - - public function getRouteName() - { - return $this->_route; - } - - /** - * Retrieve HTTP HOST - * - * @param bool $trimPort - * @return string - */ - public function getHttpHost($trimPort = true) - { - if (!isset($_SERVER['HTTP_HOST'])) { - return false; - } - if ($trimPort) { - $host = explode(':', $_SERVER['HTTP_HOST']); - return $host[0]; - } - return $_SERVER['HTTP_HOST']; - } - - /** - * Set a member of the $_POST superglobal - * - * @param striing|array $key - * @param mixed $value - * - * @return Mage_Core_Controller_Request_Http - */ - public function setPost($key, $value = null) - { - if (is_array($key)) { - $_POST = $key; - } - else { - $_POST[$key] = $value; - } - return $this; - } - - /** - * Specify module name where was found currently used controller - * - * @param string $module - * @return Mage_Core_Controller_Request_Http - */ - public function setControllerModule($module) - { - $this->_controllerModule = $module; - return $this; - } - - /** - * Get module name of currently used controller - * - * @return string - */ - public function getControllerModule() - { - return $this->_controllerModule; - } - - /** - * Retrieve the module name - * - * @return string - */ - public function getModuleName() - { - return $this->_module; - } - /** - * Retrieve the controller name - * - * @return string - */ - public function getControllerName() - { - return $this->_controller; - } - /** - * Retrieve the action name - * - * @return string - */ - public function getActionName() - { - return $this->_action; - } - - /** - * Retrieve an alias - * - * Retrieve the actual key represented by the alias $name. - * - * @param string $name - * @return string|null Returns null when no alias exists - */ - public function getAlias($name) - { - $aliases = $this->getAliases(); - if (isset($aliases[$name])) { - return $aliases[$name]; - } - return null; - } - - /** - * Retrieve the list of all aliases - * - * @return array - */ - public function getAliases() - { - if (isset($this->_routingInfo['aliases'])) { - return $this->_routingInfo['aliases']; - } - return parent::getAliases(); - } - - /** - * Get route name used in request (ignore rewrite) - * - * @return string - */ - public function getRequestedRouteName() - { - if (isset($this->_routingInfo['requested_route'])) { - return $this->_routingInfo['requested_route']; - } - if ($this->_requestedRouteName === null) { - if ($this->_rewritedPathInfo !== null && isset($this->_rewritedPathInfo[0])) { - $fronName = $this->_rewritedPathInfo[0]; - $router = Mage::app()->getFrontController()->getRouterByFrontName($fronName); - $this->_requestedRouteName = $router->getRouteByFrontName($fronName); - } else { - // no rewritten path found, use default route name - return $this->getRouteName(); - } - } - return $this->_requestedRouteName; - } - - /** - * Get controller name used in request (ignore rewrite) - * - * @return string - */ - public function getRequestedControllerName() - { - if (isset($this->_routingInfo['requested_controller'])) { - return $this->_routingInfo['requested_controller']; - } - if (($this->_rewritedPathInfo !== null) && isset($this->_rewritedPathInfo[1])) { - return $this->_rewritedPathInfo[1]; - } - return $this->getControllerName(); - } - - /** - * Get action name used in request (ignore rewrite) - * - * @return string - */ - public function getRequestedActionName() - { - if (isset($this->_routingInfo['requested_action'])) { - return $this->_routingInfo['requested_action']; - } - if (($this->_rewritedPathInfo !== null) && isset($this->_rewritedPathInfo[2])) { - return $this->_rewritedPathInfo[2]; - } - return $this->getActionName(); - } - - /** - * Set routing info data - * - * @param array $data - * @return Mage_Core_Controller_Request_Http - */ - public function setRoutingInfo($data) - { - if (is_array($data)) { - $this->_routingInfo = $data; - } - return $this; - } - - /** - * Collect properties changed by _forward in protected storage - * before _forward was called first time. - * - * @return Mage_Core_Controller_Varien_Action - */ - public function initForward() - { - if (empty($this->_beforeForwardInfo)) { - $this->_beforeForwardInfo = array( - 'params' => $this->getParams(), - 'action_name' => $this->getActionName(), - 'controller_name' => $this->getControllerName(), - 'module_name' => $this->getModuleName() - ); - } - - return $this; - } - - /** - * Retrieve property's value which was before _forward call. - * If property was not changed during _forward call null will be returned. - * If passed name will be null whole state array will be returned. - * - * @param string $name - * @return array|string|null - */ - public function getBeforeForwardInfo($name = null) - { - if (is_null($name)) { - return $this->_beforeForwardInfo; - } elseif (isset($this->_beforeForwardInfo[$name])) { - return $this->_beforeForwardInfo[$name]; - } - - return null; - } - - /** - * Specify/get _isStraight flag value - * - * @param bool $flag - * @return bool - */ - public function isStraight($flag = null) - { - if ($flag !== null) { - $this->_isStraight = $flag; - } - return $this->_isStraight; - } - - /** - * Check is Request from AJAX - * - * @return boolean - */ - public function isAjax() - { - if ($this->isXmlHttpRequest()) { - return true; - } - if ($this->getParam('ajax') || $this->getParam('isAjax')) { - return true; - } - return false; - } -} \ No newline at end of file diff --git a/src/MageTest/Controller/Response/HttpTestCase.php b/src/MageTest/Controller/Response/HttpTestCase.php deleted file mode 100644 index 8727bb9..0000000 --- a/src/MageTest/Controller/Response/HttpTestCase.php +++ /dev/null @@ -1,47 +0,0 @@ - so we can send you a copy immediately. - * - * @category MageTest - * @package Controller - * @subpackage Response - * - * @copyright Copyright (c) 2012-2013 MageTest team and contributors. - */ -namespace MageTest\Controller\Response; - -use Zend_Controller_Response_HttpTestCase; - -/** - * HttpTestCase - * - * @category MageTest - * @package Controller - * @subpackage Response - * - * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) - */ -class HttpTestCase extends Zend_Controller_Response_HttpTestCase -{ - public function __construct() - { - } - - public function sendResponse() - { - Mage::dispatchEvent('http_response_send_before', array('response'=>$this)); - return parent::sendResponse(); - } -} \ No newline at end of file diff --git a/src/MageTest/MagentoExtension/Context/ClassGuesser.php b/src/MageTest/MagentoExtension/Context/ClassGuesser.php deleted file mode 100644 index b6a8af2..0000000 --- a/src/MageTest/MagentoExtension/Context/ClassGuesser.php +++ /dev/null @@ -1,46 +0,0 @@ - so we can send you a copy immediately. - * - * @category MageTest - * @package MagentoExtension - * @subpackage Context - * - * @copyright Copyright (c) 2012-2013 MageTest team and contributors. - */ -namespace MageTest\MagentoExtension\Context; - -use Behat\Behat\Context\ClassGuesser\ClassGuesserInterface; - -/** - * ClassGuesser - * - * @category MageTest - * @package MagentoExtension - * @subpackage Context - * - * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) - */ -class ClassGuesser implements ClassGuesserInterface -{ - public function __construct() - { - } - - public function guess() - { - return array('MageTest\MagentoExtension\Context\MagentoAwareInterface'); - } -} diff --git a/src/MageTest/MagentoExtension/Context/MagentoContext.php b/src/MageTest/MagentoExtension/Context/MagentoContext.php index a208928..06ae70f 100644 --- a/src/MageTest/MagentoExtension/Context/MagentoContext.php +++ b/src/MageTest/MagentoExtension/Context/MagentoContext.php @@ -30,10 +30,8 @@ MageTest\MagentoExtension\Fixture\FixtureFactory, MageTest\MagentoExtension\Service\Session; -use Behat\MinkExtension\Context\MinkAwareInterface, - Behat\Behat\Context\BehatContext, - Behat\Gherkin\Node\TableNode, - Behat\Mink\Mink; +use Behat\MinkExtension\Context\RawMinkContext, + Behat\Gherkin\Node\TableNode; /** * MagentoContext @@ -44,25 +42,14 @@ * * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) */ -class MagentoContext extends BehatContext implements MinkAwareInterface, MagentoAwareInterface +class MagentoContext extends RawMinkContext implements MagentoAwareInterface { private $app; private $configManager; private $cacheManager; private $factory; - private $mink; - private $minkProperties; private $sessionService; - /** - * @Given /^I log in as admin user "([^"]*)" identified by "([^"]*)"$/ - */ - public function iLoginAsAdmin($username, $password) - { - $sid = $this->sessionService->adminLogin($username, $password); - $this->mink->getSession()->setCookie('adminhtml', $sid); - } - /** * @When /^I open admin URI "([^"]*)"$/ */ @@ -71,53 +58,40 @@ public function iOpenAdminUri($uri) $urlModel = new \Mage_Adminhtml_Model_Url(); if (preg_match('@^/admin/(.*?)/(.*?)((/.*)?)$@', $uri, $m)) { $processedUri = "/admin/{$m[1]}/{$m[2]}/key/".$urlModel->getSecretKey($m[1], $m[2])."/{$m[3]}"; - $this->mink->getSession()->visit($processedUri); + $this->getSession()->visit($processedUri); } else { throw new \InvalidArgumentException('$uri parameter should start with /admin/ and contain controller and action elements'); } } /** - * @When /^I am on "([^"]*)"$/ - */ - public function iAmOn($uri) - { - $this->mink->getSession()->visit($uri); - } - - /** - * @Then /^I should see text "([^"]*)"$/ + * @When /^I log in as admin user "([^"]*)" identified by "([^"]*)"$/ */ - public function iShouldSeeText($text) + public function iLoginAsAdmin($username, $password) { - $select = '//*[text()="'.$text.'"]'; - if (!$this->mink->getSession()->getDriver()->find($select)) { - throw new \Behat\Mink\Exception\ElementNotFoundException($this->mink->getSession(), 'xpath', $select, null); - } + $sid = $this->sessionService->adminLogin($username, $password); + $this->getSession()->setCookie('adminhtml', $sid); } /** - * @Then /^I should not see text "([^"]*)"$/ + * @When /^I am on "([^"]*)"$/ */ - public function iShouldNotSeeText($text) + public function iAmOn($uri) { - $select = '//*[text()="'.$text.'"]'; - if ($this->mink->getSession()->getDriver()->find($select)) { - throw new \Exception("the given text \"$text\" is unexpectedly found."); - } + $this->getSession()->visit($uri); } /** - * @Given /^I set config value for "([^"]*)" to "([^"]*)" in "([^"]*)" scope$/ + * @When /^I set config value for "([^"]*)" to "([^"]*)" in "([^"]*)" scope$/ */ public function iSetConfigValueForScope($path, $value, $scope) { $this->configManager->setCoreConfig($path, $value, $scope); } - /** * @Given /^the cache is clean$/ + * @When /^I clear the cache$/ */ public function theCacheIsClean() { @@ -169,16 +143,6 @@ public function setSessionService(Session $session) $this->sessionService = $session; } - public function setMink(Mink $mink) - { - $this->mink = $mink; - } - - public function setMinkParameters(array $parameters) - { - $this->minkParameters = $parameters; - } - public function getFixture($identifier) { return $this->factory->create($identifier); diff --git a/src/MageTest/MagentoExtension/EventListener/BeforeScenarioListener.php b/src/MageTest/MagentoExtension/EventListener/BeforeScenarioListener.php deleted file mode 100644 index e47f86d..0000000 --- a/src/MageTest/MagentoExtension/EventListener/BeforeScenarioListener.php +++ /dev/null @@ -1,57 +0,0 @@ - so we can send you a copy immediately. - * - * @category MageTest - * @package MagentoExtension - * @subpackage EventListener - * - * @copyright Copyright (c) 2012-2013 MageTest team and contributors. - */ -namespace MageTest\MagentoExtension\EventListener; - -use MageTest\MagentoExtension\Service\CacheManager; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -/** - * BeforeScenarioListener - * - * @category MageTest - * @package MagentoExtension - * @subpackage EventListener - * - * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) - */ -class BeforeScenarioListener implements EventSubscriberInterface -{ - private $cacheManager; - - public function __construct(CacheManager $manager) - { - $this->cacheManager = $manager; - } - - public static function getSubscribedEvents() - { - return array( - 'beforeScenario' => 'beforeScenario' - ); - } - - public function beforeScenario() - { - $this->cacheManager->clear(); - } -} \ No newline at end of file diff --git a/src/MageTest/MagentoExtension/Fixture/FixtureFactory.php b/src/MageTest/MagentoExtension/Fixture/FixtureFactory.php index 0bbfe43..76fd9d9 100644 --- a/src/MageTest/MagentoExtension/Fixture/FixtureFactory.php +++ b/src/MageTest/MagentoExtension/Fixture/FixtureFactory.php @@ -69,6 +69,7 @@ public function clean() foreach ($this->getRegistry() as $fixtures) { $fixture->delete(); } + $this->registry = array(); } public function getRegistry() diff --git a/src/MageTest/MagentoExtension/services/core.xml b/src/MageTest/MagentoExtension/services/core.xml index 9d7c7b1..28793b0 100644 --- a/src/MageTest/MagentoExtension/services/core.xml +++ b/src/MageTest/MagentoExtension/services/core.xml @@ -32,10 +32,6 @@ - - - - @@ -45,8 +41,5 @@ - - -