diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..8849d54 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,11 @@ +tools: + external_code_coverage: true +build: + nodes: + analysis: + tests: + override: + - php-scrutinizer-run +filter: + excluded_paths: + - "tests/_support/_generated" \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 4e34745..8071c86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,25 @@ language: php - +stages: + - test + - php: - 5.6 - 7.0 - 7.1 - 7.2 - 7.3 - # faster builds on new travis setup not using sudo sudo: false install: - '[[ -z "$CI_USER_TOKEN" ]] || composer config github-oauth.github.com ${CI_USER_TOKEN};' - travis_retry composer self-update && composer --version - - travis_retry composer update --prefer-dist --no-interaction - + - travis_retry composer install --prefer-dist --no-interaction + - phpenv config-rm xdebug.ini + - if [[ "$TRAVIS_PHP_VERSION" == "7.3" ]]; then pecl install -f pcov; fi + script: - php ./vendor/bin/codecept run + - if [[ "$TRAVIS_PHP_VERSION" == "7.3" ]]; then php ./vendor/bin/codecept run --coverage-xml; fi +after_script: + - if [[ "$TRAVIS_PHP_VERSION" == "7.3" ]]; then wget https://scrutinizer-ci.com/ocular.phar; php ocular.phar code-coverage:upload --format=php-clover tests/_output/coverage.xml; fi diff --git a/codeception.yml b/codeception.yml index 0048e8a..abe375d 100644 --- a/codeception.yml +++ b/codeception.yml @@ -5,3 +5,8 @@ paths: support: tests/_support envs: tests/_envs actor_suffix: Tester +coverage: + enabled: true + local: true + include: + - src/*.php diff --git a/composer.json b/composer.json index 5e51595..071433b 100644 --- a/composer.json +++ b/composer.json @@ -34,5 +34,8 @@ }, "config": { "classmap-authoritative": true + }, + "scripts": { + "test": "codecept run --coverage-xml" } } diff --git a/src/Codeception/Lib/InnerBrowser.php b/src/Codeception/Lib/InnerBrowser.php index 296c5b9..9a92995 100644 --- a/src/Codeception/Lib/InnerBrowser.php +++ b/src/Codeception/Lib/InnerBrowser.php @@ -439,29 +439,47 @@ protected function clickByLocator($link) */ private function clickButton(\DOMNode $node) { - $formParams = []; - $buttonName = (string)$node->getAttribute('name'); - $buttonValue = $node->getAttribute('value'); - - if ($buttonName !== '' && $buttonValue !== null) { - $formParams = [$buttonName => $buttonValue]; + /** + * First we check if the button is associated to a form. + * It is associated to a form when it has a nonempty form + */ + $formAttribute = $node->attributes->getNamedItem('form'); + if (isset($formAttribute)) { + $form = empty($formAttribute->nodeValue) ? null : $this->filterByCSS('#' . $formAttribute->nodeValue)->getNode(0); + } else { + // Check parents + $currentNode = $node; + $form = null; + while ($currentNode->parentNode !== null) { + $currentNode = $currentNode->parentNode; + if ($currentNode->nodeName === 'form') { + $form = $node; + break; + } + } } - while ($node->parentNode !== null) { - $node = $node->parentNode; - if (!isset($node->tagName)) { - // this is the top most node, it has no parent either - break; + if (isset($form)) { + $buttonName = $node->getAttribute('name'); + if ($buttonName !== '') { + $formParams = [$buttonName => $node->getAttribute('value')]; + } else { + $formParams = []; } - if ($node->tagName === 'a') { - $this->openHrefFromDomNode($node); - return true; - } elseif ($node->tagName === 'form') { - $this->proceedSubmitForm( - new Crawler($node, $this->getAbsoluteUrlFor($this->_getCurrentUri()), $this->getBaseUrl()), - $formParams - ); - return true; + $this->proceedSubmitForm( + new Crawler($form, $this->getAbsoluteUrlFor($this->_getCurrentUri()), $this->getBaseUrl()), + $formParams + ); + return true; + } else { + // Check if the button is inside an anchor. + $currentNode = $node; + while ($currentNode->parentNode !== null) { + $currentNode = $currentNode->parentNode; + if ($currentNode->nodeName === 'a') { + $this->openHrefFromDomNode($currentNode); + return true; + } } } throw new TestRuntimeException('Button is not inside a link or a form'); diff --git a/tests/data/app/view/form/button-not-in-form.php b/tests/data/app/view/form/button-not-in-form.php index 77ad75c..e6338f5 100644 --- a/tests/data/app/view/form/button-not-in-form.php +++ b/tests/data/app/view/form/button-not-in-form.php @@ -5,11 +5,16 @@