From 96024a0b33bb56125bc9dfe6228018bd1a5af45a Mon Sep 17 00:00:00 2001 From: Jon Acker Date: Thu, 1 Jan 2015 20:53:37 +0000 Subject: [PATCH 1/3] Fix basic admin scenario --- composer.json | 1 + features/backend/homepage.feature | 11 +- features/bootstrap/AdminContext.php | 49 +++++++ .../Context/MagentoPageTrait.php | 130 ++++++++++++++++++ 4 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 features/bootstrap/AdminContext.php create mode 100644 src/MageTest/MagentoExtension/Context/MagentoPageTrait.php diff --git a/composer.json b/composer.json index d64e8e6..58435cc 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ }, "require-dev": { "phpspec/phpspec": "~2.0", + "bossa/phpspec2-expect": "dev-master", "mockery/mockery": "*", "magetest/magento": "*" }, diff --git a/features/backend/homepage.feature b/features/backend/homepage.feature index 3b903f3..fd70773 100644 --- a/features/backend/homepage.feature +++ b/features/backend/homepage.feature @@ -1,9 +1,12 @@ Feature: Index Page As a website administrator - I want to see the index page + I want to see the dashboard page So that I can understand what the website offers and how it can benefit me + Background: + Given there is an admin user "admintest" "admin" + Scenario: Display Header -# 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" + Given I am logged in as admin "admintest" with credentials "admin" + When I open admin URI "/admin/dashboard/" + Then I should that the page title is "Dashboard" diff --git a/features/bootstrap/AdminContext.php b/features/bootstrap/AdminContext.php new file mode 100644 index 0000000..2e44f8d --- /dev/null +++ b/features/bootstrap/AdminContext.php @@ -0,0 +1,49 @@ +load($username, 'username'); + + if (null === $user->getUsername()) { + $user->setData(array( + 'username' => $username, + 'firstname' => 'Admin', + 'lastname' => 'Admin', + 'email' => 'test@test.com', + 'password' => $password, + 'is_active' => 1 + )) + ->save() + ->setRoleIds(array(1)) + ->setRoleUserId($user->getUserId()) + ->saveRelations(); + } + } + + /** + * @Given I am logged in as admin :username with credentials :password + */ + public function iAmASiteAdmin($username, $password) + { + $sessionId = $this->getSessionService()->adminLogin($username, $password); + $this->getSession()->setCookie('adminhtml', $sessionId); + } + + /** + * @Then I should that the page title is :title + */ + public function iShouldThatThePageTitleIs($title) + { + $page = $this->getSession()->getPage(); + expect($page->find('css', 'h3')->getText())->toBe($title); + } +} diff --git a/src/MageTest/MagentoExtension/Context/MagentoPageTrait.php b/src/MageTest/MagentoExtension/Context/MagentoPageTrait.php new file mode 100644 index 0000000..6d0f74b --- /dev/null +++ b/src/MageTest/MagentoExtension/Context/MagentoPageTrait.php @@ -0,0 +1,130 @@ +_app = $app; + } + + public function setConfigManager(ConfigManager $config) + { + $this->_configManager = $config; + } + + public function setCacheManager(CacheManager $cache) + { + $this->_cacheManager = $cache; + } + + public function setSessionService(Session $session) + { + $this->_sessionService = $session; + } + + public function setMink(Mink $mink) + { + $this->_mink = $mink; + } + + public function setMinkParameters(array $parameters) + { + $this->_minkParameters = $parameters; + } + + private function getCurrentPage() + { + return $this->_page; + } + + private function setCurrentPage(Page $page) + { + $this->_page = $page; + } + + /** + * @param string $username + * @param string $password + */ + private function loginAdminUser($username, $password) + { + $this->resetSession(); + $sessionId = $this->_sessionService->adminLogin($username, $password); + $this->getSession()->setCookie('adminhtml', $sessionId); + } + + private function getSession($name = null) + { + return $this->_mink->getSession($name); + } + + private function resetSession() + { + $session = $this->getSession(); + $session->restart(); + $session->visit($this->_minkParameters['base_url']); + } + + /** + * @BeforeScenario + */ + public function setPrefix() + { + $letters = range('a', 'z'); + + $random = ''; + + for ($i = 0; $i < 10; $i++) { + $random .= $letters[array_rand($letters)]; + } + + $this->_prefix = $random; + } + + public function getPrefix() + { + return $this->_prefix; + } +} From 97cc02db950024a68ded50928b2898da35e77fdb Mon Sep 17 00:00:00 2001 From: Jon Acker Date: Fri, 2 Jan 2015 09:49:00 +0000 Subject: [PATCH 2/3] Remove unused file --- composer.json | 3 +- features/backend/homepage.feature | 4 +- features/bootstrap/AdminContext.php | 4 +- .../MagentoExtension/Client/TestClient.php | 59 ++++++++ .../Context/MagentoPageTrait.php | 130 ------------------ .../MagentoExtension/Driver/MageApp.php | 70 ++++++++++ .../MagentoExtension/Driver/MageAppDriver.php | 17 +++ .../Driver/MagentoFactory.php | 65 +++++++++ src/MageTest/MagentoExtension/Extension.php | 12 +- .../MagentoExtension/services/core.xml | 5 + 10 files changed, 233 insertions(+), 136 deletions(-) create mode 100644 src/MageTest/MagentoExtension/Client/TestClient.php delete mode 100644 src/MageTest/MagentoExtension/Context/MagentoPageTrait.php create mode 100644 src/MageTest/MagentoExtension/Driver/MageApp.php create mode 100644 src/MageTest/MagentoExtension/Driver/MageAppDriver.php create mode 100644 src/MageTest/MagentoExtension/Driver/MagentoFactory.php diff --git a/composer.json b/composer.json index 58435cc..289c13f 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "behat/mink-extension": "*", "behat/mink-browserkit-driver": "*", "behat/mink-goutte-driver": ">=1.0.3", - "sensiolabs/behat-page-object-extension": "*" + "sensiolabs/behat-page-object-extension": "*", + "symfony/http-kernel": "~2.6" }, "require-dev": { "phpspec/phpspec": "~2.0", diff --git a/features/backend/homepage.feature b/features/backend/homepage.feature index fd70773..8d6f3f6 100644 --- a/features/backend/homepage.feature +++ b/features/backend/homepage.feature @@ -8,5 +8,5 @@ Feature: Index Page Scenario: Display Header Given I am logged in as admin "admintest" with credentials "admin" - When I open admin URI "/admin/dashboard/" - Then I should that the page title is "Dashboard" + When I open admin URI "/admin/system_account/" + Then I should see that the page title is "Dashboard" diff --git a/features/bootstrap/AdminContext.php b/features/bootstrap/AdminContext.php index 2e44f8d..bc8bc34 100644 --- a/features/bootstrap/AdminContext.php +++ b/features/bootstrap/AdminContext.php @@ -39,9 +39,9 @@ public function iAmASiteAdmin($username, $password) } /** - * @Then I should that the page title is :title + * @Then I should see that the page title is :title */ - public function iShouldThatThePageTitleIs($title) + public function iShouldSeeThatThePageTitleIs($title) { $page = $this->getSession()->getPage(); expect($page->find('css', 'h3')->getText())->toBe($title); diff --git a/src/MageTest/MagentoExtension/Client/TestClient.php b/src/MageTest/MagentoExtension/Client/TestClient.php new file mode 100644 index 0000000..6c0d8e3 --- /dev/null +++ b/src/MageTest/MagentoExtension/Client/TestClient.php @@ -0,0 +1,59 @@ +kernel = $kernel; + parent::__construct($server); + } + + /** + * Makes a request. + * + * @param HttpRequest $request + * + * @return BrowserKitResponse + */ + protected function doRequest($request) + { + return $this->kernel->handle($request); + } + + /** + * @param HttpResponse $response + * + * @return BrowserKitResponse + */ + protected function filterResponse($response) + { + return new BrowserKitResponse($response->getContent(), $response->getStatusCode(), $response->headers->all()); + } + + /** + * @param BrowserKitRequest $request + * + * @return HttpRequest + */ + protected function filterRequest(BrowserKitRequest $request) + { + return HttpRequest::create($request->getUri(), $request->getMethod()); + } +} diff --git a/src/MageTest/MagentoExtension/Context/MagentoPageTrait.php b/src/MageTest/MagentoExtension/Context/MagentoPageTrait.php deleted file mode 100644 index 6d0f74b..0000000 --- a/src/MageTest/MagentoExtension/Context/MagentoPageTrait.php +++ /dev/null @@ -1,130 +0,0 @@ -_app = $app; - } - - public function setConfigManager(ConfigManager $config) - { - $this->_configManager = $config; - } - - public function setCacheManager(CacheManager $cache) - { - $this->_cacheManager = $cache; - } - - public function setSessionService(Session $session) - { - $this->_sessionService = $session; - } - - public function setMink(Mink $mink) - { - $this->_mink = $mink; - } - - public function setMinkParameters(array $parameters) - { - $this->_minkParameters = $parameters; - } - - private function getCurrentPage() - { - return $this->_page; - } - - private function setCurrentPage(Page $page) - { - $this->_page = $page; - } - - /** - * @param string $username - * @param string $password - */ - private function loginAdminUser($username, $password) - { - $this->resetSession(); - $sessionId = $this->_sessionService->adminLogin($username, $password); - $this->getSession()->setCookie('adminhtml', $sessionId); - } - - private function getSession($name = null) - { - return $this->_mink->getSession($name); - } - - private function resetSession() - { - $session = $this->getSession(); - $session->restart(); - $session->visit($this->_minkParameters['base_url']); - } - - /** - * @BeforeScenario - */ - public function setPrefix() - { - $letters = range('a', 'z'); - - $random = ''; - - for ($i = 0; $i < 10; $i++) { - $random .= $letters[array_rand($letters)]; - } - - $this->_prefix = $random; - } - - public function getPrefix() - { - return $this->_prefix; - } -} diff --git a/src/MageTest/MagentoExtension/Driver/MageApp.php b/src/MageTest/MagentoExtension/Driver/MageApp.php new file mode 100644 index 0000000..004c2db --- /dev/null +++ b/src/MageTest/MagentoExtension/Driver/MageApp.php @@ -0,0 +1,70 @@ +container = $container; + } + + /** + * Handles a Request to convert it to a Response. + * + * @param Request $request A Request instance + * + * @return Response A Response instance + * + * @throws \Exception When an Exception occurs during processing + * + * @api + */ + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) + { + $_SERVER['REQUEST_URI'] = $request->getRequestUri(); + + $contents = $this->runApplication(); + + return new Response($contents, 200); + } + + /** + * Gets the current container. + * + * @return ContainerInterface A ContainerInterface instance + * + * @api + */ + public function getContainer() + { + return $this->container; + } + + /** + * @return string + */ + private function runApplication() + { + ob_start(); + \Mage::run(); + $contents = ob_get_contents(); + ob_end_clean(); + \Mage::reset(); + + return $contents; + } +} diff --git a/src/MageTest/MagentoExtension/Driver/MageAppDriver.php b/src/MageTest/MagentoExtension/Driver/MageAppDriver.php new file mode 100644 index 0000000..caf973e --- /dev/null +++ b/src/MageTest/MagentoExtension/Driver/MageAppDriver.php @@ -0,0 +1,17 @@ +getContainer()->get(TestClient::SERVICE_ID), $baseUrl); + } +} \ No newline at end of file diff --git a/src/MageTest/MagentoExtension/Driver/MagentoFactory.php b/src/MageTest/MagentoExtension/Driver/MagentoFactory.php new file mode 100644 index 0000000..692f8a0 --- /dev/null +++ b/src/MageTest/MagentoExtension/Driver/MagentoFactory.php @@ -0,0 +1,65 @@ +getExtension('mink')) { + $minkExtension->registerDriverFactory(new MagentoFactory()); + } } /** @@ -82,6 +87,11 @@ public function load(ContainerBuilder $container, array $config) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/services')); $loader->load('core.xml'); + + $container->setDefinition( + self::KERNEL_ID, + new Definition('MageTest\MagentoExtension\Driver\MageApp', array($container)) + ); } /** diff --git a/src/MageTest/MagentoExtension/services/core.xml b/src/MageTest/MagentoExtension/services/core.xml index 62bd1d8..584ea6a 100644 --- a/src/MageTest/MagentoExtension/services/core.xml +++ b/src/MageTest/MagentoExtension/services/core.xml @@ -9,6 +9,8 @@ MageTest\MagentoExtension\Service\Bootstrap MageTest\MagentoExtension\Context\Initializer\MagentoAwareInitializer MageTest\MagentoExtension\Service\Session + MageTest\MagentoExtension\Driver\MageApp + MageTest\MagentoExtension\Client\TestClient Mage_Core_Model_Config Mage_Core_Model_Config_Data MageTest\MagentoExtension\Context\ClassGuesser @@ -37,5 +39,8 @@ + + + From 99ece309c2a861f18ca54eba5b90b9272d8d8461 Mon Sep 17 00:00:00 2001 From: Jon Acker Date: Fri, 2 Jan 2015 10:12:18 +0000 Subject: [PATCH 3/3] fix tabs --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 289c13f..7cf24db 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "behat/mink-extension": "*", "behat/mink-browserkit-driver": "*", "behat/mink-goutte-driver": ">=1.0.3", - "sensiolabs/behat-page-object-extension": "*", + "sensiolabs/behat-page-object-extension": "*", "symfony/http-kernel": "~2.6" }, "require-dev": {