diff --git a/behat.yml.dist b/behat.yml.dist index 493c7d2..d45ecbc 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -1,10 +1,7 @@ default: - formatter: - name: progress extensions: MageTest\MagentoExtension\Extension: ~ Behat\MinkExtension\Extension: base_url: test.magento.loc goutte: - server_parameters: - HTTP_HOST: %behat.mink.base_url% + server_parameters: ~ diff --git a/composer.json b/composer.json index 7e0e3c0..11c1157 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": "~5.3", - "behat/behat": "~2.4.4", + "behat/behat": "3.0.*@dev", "behat/mink-extension": "*", "behat/mink-browserkit-driver": "*", "behat/mink-goutte-driver": ">=1.0.3" diff --git a/features/backend/homepage.feature b/features/backend/homepage.feature index 6d76699..3b903f3 100644 --- a/features/backend/homepage.feature +++ b/features/backend/homepage.feature @@ -4,6 +4,6 @@ Feature: Index Page So that I can understand what the website offers and how it can benefit me Scenario: Display Header - Given I log in as admin user "admin" identified by "123123pass" +# Given I log in as admin user "admin" identified by "123123pass" When I open admin URI "/admin/process/list" Then I should see text "Index Management" diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 20466af..9dbd643 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -22,7 +22,8 @@ use Behat\Behat\Context\ClosuredContextInterface, Behat\Behat\Context\TranslatedContextInterface, Behat\Behat\Context\BehatContext, - Behat\Behat\Exception\PendingException; + Behat\Behat\Tester\Exception\PendingException; +use Behat\Behat\Context\SnippetAcceptingContext; use Behat\Gherkin\Node\PyStringNode, Behat\Gherkin\Node\TableNode; @@ -36,17 +37,14 @@ * * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) */ -class FeatureContext extends MagentoContext +class FeatureContext extends MagentoContext implements SnippetAcceptingContext { /** * 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) + public function __construct() { - // Initialize your context here + } /** diff --git a/features/frontend/homepage.feature b/features/frontend/homepage.feature index e740def..ffd3fac 100644 --- a/features/frontend/homepage.feature +++ b/features/frontend/homepage.feature @@ -3,74 +3,86 @@ Feature: Home Page I want to see the homepage So that I can understand what the website offers and how it can benefit me - # Scenario: Display Logo - # Given I am on "home page" - # Then I should see "Magento Logo" - # - # Scenario: Display Search Box - # Given I am on "home page" - # Then I should see "a textbox for my search term" - # And the search box should contain the message "Search entire store here" - # And I should see a button with the text "Search" + @wip + Scenario: Display Logo + Given I am on "home page" + Then I should see "Magento Logo" - # Scenario: Display Welcome Message - # Given I am on "home page" - # Then I should see "Default welcome msg!" - # - # Scenario: Display Account Menu - # Given I am on "home page" - # Then I should see "My Account, My Wishlist, My Cart, Checkout, Log In" - # - # Scenario: Display Language - # Given I am on "home page" - # Then I should see the text "Your Language" - # And a dropdown with the options "Czech (Czech Republic), Danish (Denmark), Dutch (Netherlands), English, French, German, Norwegian Bokmai (Norway), Polish (Poland)" - # - # Scenario: Display Main Menu - # Given I am on "home page" - # Then I should see "Furniture, Electronics, Apparel, Music, Ebooks" - # - # Scenario: Display Left Column - # Given I am on "home page" - # Then I should see "A Small Banner Advert" - # And I should see "A Product Feature" - # And I should see "Popular Tags" - # - # Scenario: Display Main Content - # Given I am on "home page" - # Then I should see "A Large Banner Advert" - # And I should see "A Wide Banner Advert" - # And I should see "A Best Selling Product Feature showing 6 products" - # - # Scenario: Display Right Column - # Given I am on "home page" - # Then I should see "A Product Comparison Feature" - # And I should see "A Mini View of My Cart" - # And I should see "A Small Banner Advert" - # And I should see "A Community Poll" - # And I should see "A PayPal Advert" - # - # Scenario: Display Footer - # Given I am on "home page" - # Then I should see "Select Store" and a dropdown with the values "Blue SKin, Main Store, Modern Theme" - # And I should see "About Us, Customer Service, privacy Policy, Site Map, Search Terms, Advanced Search, Orders and Returns, Contact Us" - # And I should see "Help us to Keep Magento Healthy - Report all bugs (ver.1.7.0.2)" - # And I should see "© 2012 Magento Demo Store. All Rights Reserved." - + @wip + Scenario: Display Search Box + Given I am on "home page" + Then I should see "a textbox for my search term" + And the search box should contain the message "Search entire store here" + And I should see a button with the text "Search" - Scenario: Contact Us link is shown when active - Given I set config value for "contacts/contacts/enabled" to "1" in "default" scope - And the cache is clean - When I am on "/" - Then I should see text "Contact Us" + @wip + Scenario: Display Welcome Message + Given I am on "home page" + Then I should see "Default welcome msg!" + + @wip + Scenario: Display Account Menu + Given I am on "home page" + Then I should see "My Account, My Wishlist, My Cart, Checkout, Log In" + + @wip + Scenario: Display Language + Given I am on "home page" + Then I should see the text "Your Language" + And a dropdown with the options "Czech (Czech Republic), Danish (Denmark), Dutch (Netherlands), English, French, German, Norwegian Bokmai (Norway), Polish (Poland)" + + @wip + Scenario: Display Main Menu + Given I am on "home page" + Then I should see "Furniture, Electronics, Apparel, Music, Ebooks" + + @wip + Scenario: Display Left Column + Given I am on "home page" + Then I should see "A Small Banner Advert" + And I should see "A Product Feature" + And I should see "Popular Tags" + @wip + Scenario: Display Main Content + Given I am on "home page" + Then I should see "A Large Banner Advert" + And I should see "A Wide Banner Advert" + And I should see "A Best Selling Product Feature showing 6 products" + + @wip + Scenario: Display Right Column + Given I am on "home page" + Then I should see "A Product Comparison Feature" + And I should see "A Mini View of My Cart" + And I should see "A Small Banner Advert" + And I should see "A Community Poll" + And I should see "A PayPal Advert" + + @wip + Scenario: Display Footer + Given I am on "home page" + Then I should see "Select Store" and a dropdown with the values "Blue SKin, Main Store, Modern Theme" + And I should see "About Us, Customer Service, privacy Policy, Site Map, Search Terms, Advanced Search, Orders and Returns, Contact Us" + And I should see "Help us to Keep Magento Healthy - Report all bugs (ver.1.7.0.2)" + And I should see "© 2012 Magento Demo Store. All Rights Reserved." + + + @wip + Scenario: Contact Us link is shown when active + Given I set config value for "contacts/contacts/enabled" to "1" in "default" scope + And the cache is clean + When I am on "/" + Then I should see text "Contact Us" + @wip Scenario: Contact Us link is hidden when disabled - Given I set config value for "contacts/contacts/enabled" to "0" in "default" scope - And the cache is clean - When I am on "/" - Then I should not see text "Contact Us" + Given I set config value for "contacts/contacts/enabled" to "0" in "default" scope + And the cache is clean + When I am on "/" + Then I should not see text "Contact Us" + @wip Scenario: Display Welcome Message - Given I am on "/" - Then I should see text "Default welcome msg! " + Given I am on "/" + Then I should see text "Default welcome msg! " diff --git a/features/frontend/search.feature b/features/frontend/search.feature index 2d88619..551d331 100644 --- a/features/frontend/search.feature +++ b/features/frontend/search.feature @@ -3,16 +3,17 @@ Feature: Search I want to be able to search for Products So that I can find the Product I am looking for quickly - # Scenario: Search for Product - # Given that I am on "home page" - # And that there are products in the database - # When I enter "sony" to the search box - # And click button search - # Then the search results page should be displayed - # And the h1 should be "Search results for 'sony'" - # And 2 items should be returned as a result - # And I should see the text "2 item(s)" - # And I should see the dropdown "Show x per page" dropdown - # And I should be able to view as grid or list - # And I should be able to "sort by relevance, name or price" - # And I should see an image, title, reviews, price, add to cart, add to wishlist, add to compare" + @wip + Scenario: Search for Product + Given that I am on "home page" + And that there are products in the database + When I enter "sony" to the search box + And click button search + Then the search results page should be displayed + And the h1 should be "Search results for 'sony'" + And 2 items should be returned as a result + And I should see the text "2 item(s)" + And I should see the dropdown "Show x per page" dropdown + And I should be able to view as grid or list + And I should be able to "sort by relevance, name or price" + And I should see an image, title, reviews, price, add to cart, add to wishlist, add to compare" diff --git a/features/frontend/storelocator.feature b/features/frontend/storelocator.feature index 062fffc..a324c18 100644 --- a/features/frontend/storelocator.feature +++ b/features/frontend/storelocator.feature @@ -3,28 +3,29 @@ Feature: Store Locator I want to be able to view store information So that I can visit or contact the store - # Scenario: View All Stores - # Given I am on "store locator" - # And there is a store in "London, Manchester, Birmingham" - # Then I should see these stores listed "London, Manchester, Birmingham" - # And I should see a google map "showing the UK" - # And I should see "London, Manchester, Birmingham pins on the map" - # And I should see "a postcode search box" - # - # Scenario: View A Store - # Given I am on "store locator" - # And there is a store in "London" - # Then I should be able to click on "London" - # And be taken to the page "showing the details for the London store" - # - # Scenario: View Store Details - # Given I am on "london store" - # Then I should be able to see the store address - # And I should be able to see the store telephone number - # And I should be able to see a google map shoiwing the store location - # - # Scenario: Search for a store - # Given I am on "store locator" - # And there is "a postcode search box" - # And I enter "EC1Y 2AA" - # Then I should see "the london store displayed as a result" + @wip + Scenario: View All Stores + Given I am on "store locator" + And there is a store in "London, Manchester, Birmingham" + Then I should see these stores listed "London, Manchester, Birmingham" + And I should see a google map "showing the UK" + And I should see "London, Manchester, Birmingham pins on the map" + And I should see "a postcode search box" + + Scenario: View A Store + Given I am on "store locator" + And there is a store in "London" + Then I should be able to click on "London" + And be taken to the page "showing the details for the London store" + + Scenario: View Store Details + Given I am on "london store" + Then I should be able to see the store address + And I should be able to see the store telephone number + And I should be able to see a google map shoiwing the store location + + Scenario: Search for a store + Given I am on "store locator" + And there is "a postcode search box" + And I enter "EC1Y 2AA" + Then I should see "the london store displayed as a result" diff --git a/spec/MageTest/MagentoExtension/Context/Initializer/MagentoAwareInitializerSpec.php b/spec/MageTest/MagentoExtension/Context/Initializer/MagentoAwareInitializerSpec.php index 8f0566a..fc11d68 100644 --- a/spec/MageTest/MagentoExtension/Context/Initializer/MagentoAwareInitializerSpec.php +++ b/spec/MageTest/MagentoExtension/Context/Initializer/MagentoAwareInitializerSpec.php @@ -22,6 +22,13 @@ */ namespace spec\MageTest\MagentoExtension\Context\Initializer; +use Mage_Core_Model_App; +use MageTest\MagentoExtension\Context\MagentoContext; +use MageTest\MagentoExtension\Fixture\FixtureFactory; +use MageTest\MagentoExtension\Service\Bootstrap; +use MageTest\MagentoExtension\Service\CacheManager; +use MageTest\MagentoExtension\Service\ConfigManager; +use MageTest\MagentoExtension\Service\Session; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -37,25 +44,14 @@ */ class MagentoAwareInitializerSpec extends ObjectBehavior { - /** - * @param MageTest\MagentoExtension\Service\Bootstrap $bootstrap - * @param Mage_Core_Model_App $app - * @param MageTest\MagentoExtension\Service\ConfigManager $config - * @param MageTest\MagentoExtension\Service\CacheManager $cache - * @param MageTest\MagentoExtension\Fixture\FixtureFactory $factory - * @param MageTest\MagentoExtension\Service\Session $session - */ - function let($bootstrap, $app, $config, $cache, $factory, $mink, $session) + function let(Bootstrap $bootstrap, Mage_Core_Model_App $app, ConfigManager $config, CacheManager $cache, FixtureFactory $factory, Session $session) { $bootstrap->app()->willReturn($app); $this->beConstructedWith($bootstrap, $cache, $config, $factory, $session); } - /** - * @param MageTest\MagentoExtension\Context\MagentoContext $context - */ - function it_initialises_the_context($context, $app, $config, $cache, $factory, $mink, $session) + function it_initialises_the_context(MagentoContext $context, Mage_Core_Model_App $app, ConfigManager $config, CacheManager $cache, FixtureFactory $factory, Session $session) { $context->setApp($app)->shouldBeCalled(); $context->setConfigManager($config)->shouldBeCalled(); @@ -63,7 +59,6 @@ function it_initialises_the_context($context, $app, $config, $cache, $factory, $ $context->setFixtureFactory($factory)->shouldBeCalled(); $context->setSessionService($session)->shouldBeCalled(); - $this->initialize($context); + $this->initializeContext($context); } - } diff --git a/spec/MageTest/MagentoExtension/Context/MagentoContextSpec.php b/spec/MageTest/MagentoExtension/Context/MagentoContextSpec.php index 1614109..8e734df 100644 --- a/spec/MageTest/MagentoExtension/Context/MagentoContextSpec.php +++ b/spec/MageTest/MagentoExtension/Context/MagentoContextSpec.php @@ -39,7 +39,7 @@ class MagentoContextSpec extends ObjectBehavior { function it_should_support_mink() { - $this->shouldBeAnInstanceOf("Behat\MinkExtension\Context\MinkAwareInterface"); + $this->shouldBeAnInstanceOf("Behat\MinkExtension\Context\MinkAwareContext"); } function it_should_add_some_magento_goodies() diff --git a/src/MageTest/MagentoExtension/Context/Initializer/MagentoAwareInitializer.php b/src/MageTest/MagentoExtension/Context/Initializer/MagentoAwareInitializer.php index c6646a2..83cd433 100644 --- a/src/MageTest/MagentoExtension/Context/Initializer/MagentoAwareInitializer.php +++ b/src/MageTest/MagentoExtension/Context/Initializer/MagentoAwareInitializer.php @@ -22,6 +22,8 @@ */ namespace MageTest\MagentoExtension\Context\Initializer; +use Behat\Behat\Context\Context; +use Behat\Behat\Context\Initializer\ContextInitializer; use MageTest\MagentoExtension\Service\Bootstrap, MageTest\MagentoExtension\Service\CacheManager, MageTest\MagentoExtension\Service\ConfigManager, @@ -41,7 +43,7 @@ * * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) */ -class MagentoAwareInitializer implements InitializerInterface +class MagentoAwareInitializer implements ContextInitializer { private $app = null; @@ -53,8 +55,15 @@ class MagentoAwareInitializer implements InitializerInterface private $session = null; + /** + * @param Bootstrap $bootstrap + * @param CacheManager $cache + * @param ConfigManager $config + * @param FixtureFactory $factory + * @param Session $session + */ public function __construct(Bootstrap $bootstrap, CacheManager $cache, - ConfigManager $config, FixtureFactory $factory, Session $session) + ConfigManager $config, FixtureFactory $factory, Session $session) { $this->app = $bootstrap->app(); $this->cacheManager = $cache; @@ -62,18 +71,22 @@ public function __construct(Bootstrap $bootstrap, CacheManager $cache, $this->factory = $factory; $this->session = $session; } - - public function supports(ContextInterface $context) + /** + * Initializes provided context. + * + * @param Context $context + */ + public function initializeContext(Context $context) { - return $context instanceof MagentoAwareInterface; - } + if (!$context instanceof MagentoAwareInterface) { + return; + } - public function initialize(ContextInterface $context) - { $context->setApp($this->app); $context->setConfigManager($this->configManager); $context->setCacheManager($this->cacheManager); $context->setFixtureFactory($this->factory); $context->setSessionService($this->session); } + } diff --git a/src/MageTest/MagentoExtension/Context/MagentoAwareInterface.php b/src/MageTest/MagentoExtension/Context/MagentoAwareInterface.php index fd3f711..186250e 100644 --- a/src/MageTest/MagentoExtension/Context/MagentoAwareInterface.php +++ b/src/MageTest/MagentoExtension/Context/MagentoAwareInterface.php @@ -23,6 +23,7 @@ namespace MageTest\MagentoExtension\Context; use Mage_Core_Model_App as MageApp; +use Behat\Behat\Context\Context; use MageTest\MagentoExtension\Service\ConfigManager, MageTest\MagentoExtension\Service\CacheManager, MageTest\MagentoExtension\Fixture\FixtureFactory, @@ -37,7 +38,7 @@ * * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) */ -interface MagentoAwareInterface +interface MagentoAwareInterface extends Context { public function setApp(MageApp $app); public function setConfigManager(ConfigManager $config); diff --git a/src/MageTest/MagentoExtension/Context/MagentoContext.php b/src/MageTest/MagentoExtension/Context/MagentoContext.php index 99b9794..9fa83ca 100644 --- a/src/MageTest/MagentoExtension/Context/MagentoContext.php +++ b/src/MageTest/MagentoExtension/Context/MagentoContext.php @@ -22,6 +22,7 @@ */ namespace MageTest\MagentoExtension\Context; +use Behat\Behat\Context\Context; use Mage_Core_Model_App as MageApp; use MageTest\MagentoExtension\Context\MagentoAwareContext, MageTest\MagentoExtension\Service\ConfigManager, @@ -42,7 +43,7 @@ * * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) */ -class MagentoContext extends RawMinkContext implements MagentoAwareInterface +class MagentoContext extends RawMinkContext implements MagentoAwareInterface, Context { /** * @var MageApp diff --git a/src/MageTest/MagentoExtension/Extension.php b/src/MageTest/MagentoExtension/Extension.php index 4787d5b..25c263c 100644 --- a/src/MageTest/MagentoExtension/Extension.php +++ b/src/MageTest/MagentoExtension/Extension.php @@ -1,47 +1,97 @@ so we can send you a copy immediately. + +/* + * This file is part of the Behat Magento Extension * - * @category MageTest - * @package MagentoExtension + * (c) James Cowie * - * @copyright Copyright (c) 2012-2013 MageTest team and contributors. + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. */ + namespace MageTest\MagentoExtension; -use Behat\Behat\Extension\Extension as BaseExtension; -use Symfony\Component\DependencyInjection\ContainerBuilder, - Symfony\Component\DependencyInjection\Loader\XmlFileLoader, - Symfony\Component\Config\FileLocator; +use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; +use Behat\Testwork\ServiceContainer\ExtensionManager; +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Behat\Behat\Context\ServiceContainer\ContextExtension; +use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory; +use Behat\MinkExtension\ServiceContainer\Driver\GoutteFactory; +use Behat\MinkExtension\ServiceContainer\Driver\SahiFactory; +use Behat\MinkExtension\ServiceContainer\Driver\SaucelabsFactory; +use Behat\MinkExtension\ServiceContainer\Driver\Selenium2Factory; +use Behat\MinkExtension\ServiceContainer\Driver\SeleniumFactory; +use Behat\MinkExtension\ServiceContainer\Driver\ZombieFactory; +use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; +use Behat\Testwork\ServiceContainer\Exception\ProcessingException; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Reference; + /** - * Extension + * Magento extension for Behat class. * - * @category MageTest - * @package MagentoExtension - * - * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) */ -class Extension extends BaseExtension +class Extension implements ExtensionInterface { /** - * {@inheritdoc} + * Returns the extension config key. + * + * @return string + */ + public function getConfigKey() + { + return 'magento'; + } + + /** + * Initializes other extensions.de + * + * This method is called immediately after all extensions are activated but + * before any extension `configure()` method is called. This allows extensions + * to hook into the configuration of other extensions providing such an + * extension point. + * + * @param ExtensionManager $extensionManager + */ + public function initialize(ExtensionManager $extensionManager) + { + + } + + /** + * Setups configuration for the extension. + * + * @param ArrayNodeDefinition $builder + */ + public function configure(ArrayNodeDefinition $builder) + { + + } + + /** + * Loads extension services into temporary container. + * + * @param ContainerBuilder $container + * @param array $config */ - public function load(array $config, ContainerBuilder $container) + public function load(ContainerBuilder $container, array $config) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/services')); $loader->load('core.xml'); } -} + + /** + * Processes shared container after all extensions loaded. + * + * @param ContainerBuilder $container + */ + public function process(ContainerBuilder $container) + { + + } +} \ No newline at end of file diff --git a/src/MageTest/MagentoExtension/Service/Session.php b/src/MageTest/MagentoExtension/Service/Session.php index 085c09c..dc1c033 100644 --- a/src/MageTest/MagentoExtension/Service/Session.php +++ b/src/MageTest/MagentoExtension/Service/Session.php @@ -21,6 +21,7 @@ * @copyright Copyright (c) 2012-2013 MageTest team and contributors. */ namespace MageTest\MagentoExtension\Service; +use Mage_Admin_Model_User; /** * Session @@ -51,15 +52,18 @@ public function __construct(Bootstrap $bootstrap) public function adminLogin($username, $password) { $_SESSION = null; + $session = \Mage::getModel('admin/session'); @$session->start(); $_POST['login']=array('username'=>$username); $this->app->setResponse(new \Mage_Core_Controller_Response_Http()); + $this->app->getStore()->setId(\Mage_Core_Model_App::ADMIN_STORE_ID); /** @var $user Mage_Admin_Model_User */ $user = \Mage::getModel('admin/user'); + $user->login($username, $password); if ($user->getId()) { @$session->renewSession(); @@ -79,6 +83,7 @@ public function adminLogin($username, $password) session_write_close(); $_SESSION = null; $_POST = array(); + return $id; } diff --git a/src/MageTest/MagentoExtension/services/core.xml b/src/MageTest/MagentoExtension/services/core.xml index 28793b0..88f460e 100644 --- a/src/MageTest/MagentoExtension/services/core.xml +++ b/src/MageTest/MagentoExtension/services/core.xml @@ -38,7 +38,7 @@ - +