commit 7bfe9573e5dec5910a537558023045e2f81270c3 Author: everzet Date: Sun May 6 21:13:51 2012 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e389710 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.tgz +*.phar +composer.lock +vendor diff --git a/behat.yml.dist b/behat.yml.dist new file mode 100644 index 0000000..d2a9447 --- /dev/null +++ b/behat.yml.dist @@ -0,0 +1,6 @@ +default: + extensions: + Behat\MinkExtension\Extension: + base_url: http://en.wikipedia.org/ + goutte: ~ + sahi: ~ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..65c54a4 --- /dev/null +++ b/composer.json @@ -0,0 +1,36 @@ +{ + "name": "behat/mink-extension", + "type": "behat-extension", + "description": "Mink extension for Behat", + "keywords": ["web", "test", "browser", "gui"], + "homepage": "http://mink.behat.org", + "license": "MIT", + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com" + } + ], + + "require": { + "php": ">=5.3.2", + "behat/behat": "dev-develop", + "behat/mink": "1.4.0.x-dev" + }, + + "require-dev": { + "fabpot/goutte": "*", + "behat/sahi-client": "*" + }, + + "autoload": { + "psr-0": { "Behat\\MinkExtension": "src/" } + }, + + "repositories": { + "behat/mink-deps": { + "type": "composer", + "url": "behat.org" + } + } +} diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php new file mode 100644 index 0000000..3941da0 --- /dev/null +++ b/features/bootstrap/FeatureContext.php @@ -0,0 +1,14 @@ +getSession()->wait(5000, "$('.suggestions-results').children().length > 0"); + } +} diff --git a/features/search.feature b/features/search.feature new file mode 100644 index 0000000..4032094 --- /dev/null +++ b/features/search.feature @@ -0,0 +1,23 @@ +Feature: Search + In order to see a word definition + As a website user + I need to be able to search for a word + + Scenario: Searching for a page that does exist + Given I am on "/wiki/Main_Page" + When I fill in "search" with "Behavior Driven Development" + And I press "searchButton" + Then I should see "agile software development" + + Scenario: Searching for a page that does NOT exist + Given I am on "/wiki/Main_Page" + When I fill in "search" with "Glory Driven Development" + And I press "searchButton" + Then I should see "Search results" + + @javascript + Scenario: Searching for a page with autocompletion + Given I am on "/wiki/Main_Page" + When I fill in "search" with "Behavior Driv" + And I wait for the suggestion box to appear + Then I should see "Behavior Driven Development" diff --git a/src/Behat/MinkExtension/Compiler/SelectorsPass.php b/src/Behat/MinkExtension/Compiler/SelectorsPass.php new file mode 100644 index 0000000..77032e1 --- /dev/null +++ b/src/Behat/MinkExtension/Compiler/SelectorsPass.php @@ -0,0 +1,47 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Selectors handler compilation pass. Registers all avaiable Mink selector engines. + * + * @author Konstantin Kudryashov + */ +class SelectorsPass implements CompilerPassInterface +{ + /** + * Registers additional Mink selector handlers. + * + * @param ContainerBuilder $container + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('behat.mink.selectors_handler')) { + return; + } + + $handlerDefinition = $container->getDefinition('behat.mink.selectors_handler'); + foreach ($container->findTaggedServiceIds('behat.mink.selector') as $id => $attributes) { + foreach ($attributes as $attribute) { + if (isset($attribute['alias']) && $alias = $attribute['alias']) { + $handlerDefinition->addMethodCall( + 'registerSelector', array($alias, new Reference($id)) + ); + } + } + } + } +} diff --git a/src/Behat/MinkExtension/Compiler/SessionsPass.php b/src/Behat/MinkExtension/Compiler/SessionsPass.php new file mode 100644 index 0000000..44e1661 --- /dev/null +++ b/src/Behat/MinkExtension/Compiler/SessionsPass.php @@ -0,0 +1,52 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Behat\Mink container compilation pass. + * Registers all available in controller Mink sessions. + * + * @author Konstantin Kudryashov + */ +class SessionsPass implements CompilerPassInterface +{ + /** + * Registers Mink sessions. + * + * @param ContainerBuilder $container + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('behat.mink')) { + return; + } + $minkDefinition = $container->getDefinition('behat.mink'); + + foreach ($container->findTaggedServiceIds('behat.mink.session') as $id => $attributes) { + foreach ($attributes as $attribute) { + if (isset($attribute['alias']) && $name = $attribute['alias']) { + $minkDefinition->addMethodCall( + 'registerSession', array($name, new Reference($id)) + ); + } + } + } + + $minkDefinition->addMethodCall( + 'setDefaultSessionName', array($container->getParameter('behat.mink.default_session')) + ); + } +} diff --git a/src/Behat/MinkExtension/Configuration.php b/src/Behat/MinkExtension/Configuration.php new file mode 100644 index 0000000..47a48a4 --- /dev/null +++ b/src/Behat/MinkExtension/Configuration.php @@ -0,0 +1,142 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * MinkExtension configuration tree. + * + * @author Konstantin Kudryashov + */ +class Configuration implements ConfigurationInterface +{ + /** + * Returns configuration tree. + * + * @return TreeBuilder + */ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + + return $treeBuilder->root('mink')-> + children()-> + scalarNode('base_url')-> + defaultNull()-> + end()-> + scalarNode('files_path')-> + defaultNull()-> + end()-> + scalarNode('show_cmd')-> + defaultNull()-> + end()-> + scalarNode('show_tmp_dir')-> + defaultValue(sys_get_temp_dir())-> + end()-> + scalarNode('default_session')-> + defaultValue('goutte')-> + end()-> + scalarNode('javascript_session')-> + defaultValue('sahi')-> + end()-> + scalarNode('browser_name')-> + defaultValue('firefox')-> + end()-> + arrayNode('goutte')-> + children()-> + arrayNode('zend_config')-> + useAttributeAsKey('key')-> + prototype('variable')->end()-> + end()-> + arrayNode('server_parameters')-> + useAttributeAsKey('key')-> + prototype('variable')->end()-> + end()-> + end()-> + end()-> + arrayNode('sahi')-> + children()-> + scalarNode('sid')-> + defaultNull()-> + end()-> + scalarNode('host')-> + defaultValue('localhost')-> + end()-> + scalarNode('port')-> + defaultValue(9999)-> + end()-> + end()-> + end()-> + arrayNode('zombie')-> + children()-> + scalarNode('host')-> + defaultValue('127.0.0.1')-> + end()-> + scalarNode('port')-> + defaultValue(8124)-> + end()-> + scalarNode('auto_server')-> + defaultValue(true)-> + end()-> + scalarNode('node_bin')-> + defaultValue('node')-> + end()-> + end()-> + end()-> + arrayNode('selenium')-> + children()-> + scalarNode('host')-> + defaultValue('127.0.0.1')-> + end()-> + scalarNode('port')-> + defaultValue(4444)-> + end()-> + scalarNode('browser')-> + defaultValue('*%behat.mink.browser_name%')-> + end()-> + end()-> + end()-> + arrayNode('selenium2')-> + children()-> + scalarNode('browser')-> + defaultValue('%behat.mink.browser_name%')-> + end()-> + arrayNode('capabilities')-> + children()-> + scalarNode('browserName')-> + defaultValue('firefox')-> + end()-> + scalarNode('version')-> + defaultValue(8)-> + end()-> + scalarNode('platform')-> + defaultValue('ANY')-> + end()-> + scalarNode('browserVersion')-> + defaultValue(8)-> + end()-> + scalarNode('browser')-> + defaultValue('firefox')-> + end()-> + end()-> + end()-> + scalarNode('wd_host')-> + defaultValue('http://localhost:4444/wd/hub')-> + end()-> + end()-> + end()-> + end()-> + end(); + } +} diff --git a/src/Behat/MinkExtension/Context/MinkAwareContextInitializer.php b/src/Behat/MinkExtension/Context/MinkAwareContextInitializer.php new file mode 100644 index 0000000..91d131a --- /dev/null +++ b/src/Behat/MinkExtension/Context/MinkAwareContextInitializer.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Mink aware contexts initializer. + * Sets Mink instance and parameters to the MinkAware contexts. + * + * @author Konstantin Kudryashov + */ +class MinkAwareContextInitializer implements ContextInitializerInterface +{ + private $mink; + private $parameters; + + /** + * Initializes initializer. + * + * @param Mink $mink + * @param array $parameters + */ + public function __construct(Mink $mink, array $parameters) + { + $this->mink = $mink; + $this->parameters = $parameters; + } + + /** + * Checks if initializer supports provided context. + * + * @param ContextInterface $context + * + * @return Boolean + */ + public function supports(ContextInterface $context) + { + return $context instanceof MinkAwareContextInterface; + } + + /** + * Initializes provided context. + * + * @param ContextInterface $context + */ + public function initialize(ContextInterface $context) + { + $context->setMink($this->mink); + $context->setMinkParameters($this->parameters); + } +} diff --git a/src/Behat/MinkExtension/Context/MinkAwareContextInterface.php b/src/Behat/MinkExtension/Context/MinkAwareContextInterface.php new file mode 100644 index 0000000..9374376 --- /dev/null +++ b/src/Behat/MinkExtension/Context/MinkAwareContextInterface.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Mink aware interface for contexts. + * + * @author Konstantin Kudryashov + */ +interface MinkAwareContextInterface +{ + /** + * Sets Mink instance. + * + * @param Mink $mink Mink session manager + */ + function setMink(Mink $mink); + + /** + * Sets parameters provided for Mink. + * + * @param array $parameters + */ + function setMinkParameters(array $parameters); +} diff --git a/src/Behat/MinkExtension/Context/MinkContext.php b/src/Behat/MinkExtension/Context/MinkContext.php new file mode 100644 index 0000000..37b5a54 --- /dev/null +++ b/src/Behat/MinkExtension/Context/MinkContext.php @@ -0,0 +1,440 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Mink context for Behat BDD tool. + * Provides Mink integration and base step definitions. + * + * @author Konstantin Kudryashov + */ +class MinkContext extends RawMinkContext implements TranslatedContextInterface +{ + /** + * Opens specified page. + * + * @Given /^(?:|I )am on "(?P[^"]+)"$/ + * @When /^(?:|I )go to "(?P[^"]+)"$/ + */ + public function visit($page) + { + $this->getSession()->visit($this->locatePath($page)); + } + + /** + * Reloads current page. + * + * @When /^(?:|I )reload the page$/ + */ + public function reload() + { + $this->getSession()->reload(); + } + + /** + * Moves backward one page in history. + * + * @When /^(?:|I )move backward one page$/ + */ + public function back() + { + $this->getSession()->back(); + } + + /** + * Moves forward one page in history + * + * @When /^(?:|I )move forward one page$/ + */ + public function forward() + { + $this->getSession()->forward(); + } + + /** + * Presses button with specified id|name|title|alt|value. + * + * @When /^(?:|I )press "(?P