├── .github └── workflows │ └── build.yml ├── .gitignore ├── .php-cs-fixer.dist.php ├── .phpstan-sources.neon ├── .phpstan-tests.neon ├── LICENSE.txt ├── README.md ├── composer.json ├── phpunit.xml ├── sources ├── Lib │ ├── Base │ │ ├── Component.php │ │ └── ComponentInterface.php │ └── MarkupValidator │ │ ├── DefaultMarkupProvider.php │ │ ├── DefaultMessageFilter.php │ │ ├── DefaultMessagePrinter.php │ │ ├── MarkupProviderInterface.php │ │ ├── MarkupValidatorInterface.php │ │ ├── MarkupValidatorMessage.php │ │ ├── MarkupValidatorMessageInterface.php │ │ ├── MessageFilterInterface.php │ │ ├── MessagePrinterInterface.php │ │ ├── W3CMarkupValidator.php │ │ └── W3CMarkupValidatorMessage.php └── Module │ └── MarkupValidator.php └── tests ├── Base └── TestCase.php ├── Lib ├── Base │ └── ComponentTest.php └── MarkupValidator │ ├── DefaultMarkupProviderTest.php │ ├── DefaultMessageFilterTest.php │ ├── DefaultMessagePrinterTest.php │ ├── MarkupValidatorMessageTest.php │ ├── W3CMarkupValidatorMessageTest.php │ └── W3CMarkupValidatorTest.php └── Module └── MarkupValidatorTest.php /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ 'master' ] 6 | pull_request: 7 | branches: [ 'master' ] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | 14 | test: 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | php-version: 19 | - '8.1' 20 | - '8.2' 21 | - 'latest' 22 | steps: 23 | - 24 | uses: actions/checkout@v3 25 | - 26 | name: Validate composer 27 | run: docker run --volume $PWD:/sources --workdir /sources composer composer validate --strict 28 | - 29 | name: Install dependencies 30 | run: docker run --volume $PWD:/sources --workdir /sources composer composer update 31 | - 32 | name: Validate style 33 | run: > 34 | docker run --volume $PWD:/sources --workdir /sources --env PHP_CS_FIXER_IGNORE_ENV=TRUE php:${{ matrix.php-version }} 35 | vendor/bin/php-cs-fixer fix --dry-run 36 | - 37 | name: Analyze sources 38 | run: > 39 | docker run --volume $PWD:/sources --workdir /sources php:${{ matrix.php-version }} 40 | vendor/bin/phpstan analyze --configuration=.phpstan-sources.neon 41 | - 42 | name: Analyze tests 43 | run: > 44 | docker run --volume $PWD:/sources --workdir /sources php:${{ matrix.php-version }} 45 | vendor/bin/phpstan analyze --configuration=.phpstan-tests.neon 46 | - 47 | name: Run tests 48 | run: > 49 | docker run --volume $PWD:/sources --workdir /sources php:${{ matrix.php-version }} 50 | vendor/bin/phpunit 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.php-cs-fixer.cache 2 | /.phpunit.cache 3 | /build/ 4 | /composer.lock 5 | /vendor/ 6 | -------------------------------------------------------------------------------- /.php-cs-fixer.dist.php: -------------------------------------------------------------------------------- 1 | in(sprintf('%s/sources', __DIR__)) 8 | ->in(sprintf('%s/tests', __DIR__)) 9 | ->name('*.php') 10 | ->files() 11 | ; 12 | 13 | $config = (new Config()) 14 | ->setRules(array( 15 | '@PSR1' => true, 16 | '@PSR2' => true, 17 | 'array_syntax' => array( 18 | 'syntax' => 'long', 19 | ), 20 | 'no_trailing_whitespace' => true, 21 | 'ordered_imports' => array( 22 | 'imports_order' => null, 23 | ), 24 | 'single_blank_line_at_eof' => true, 25 | 'strict_param' => true, 26 | )) 27 | ->setRiskyAllowed(true) 28 | ->setFinder($finder) 29 | ; 30 | 31 | return $config; 32 | -------------------------------------------------------------------------------- /.phpstan-sources.neon: -------------------------------------------------------------------------------- 1 | parameters: 2 | level: 5 3 | paths: 4 | - "sources" 5 | -------------------------------------------------------------------------------- /.phpstan-tests.neon: -------------------------------------------------------------------------------- 1 | parameters: 2 | level: 1 3 | paths: 4 | - "tests" 5 | ignoreErrors: 6 | - '#Call to an undefined method Kolyunya\\Codeception\\Tests\\Lib\\MarkupValidator\\DefaultMessageFilterTest::assertArraySubset#' 7 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Codeception Markup Validator 2 | [![Latest Stable Version](https://poser.pugx.org/kolyunya/codeception-markup-validator/v/stable)](https://packagist.org/packages/kolyunya/codeception-markup-validator) 3 | [![Build Status](https://github.com/Kolyunya/codeception-markup-validator/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/Kolyunya/codeception-markup-validator/actions/workflows/build.yml) 4 | [![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat)](https://github.com/phpstan/phpstan) 5 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Kolyunya/codeception-markup-validator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Kolyunya/codeception-markup-validator/?branch=master) 6 | [![Code Climate](https://codeclimate.com/github/Kolyunya/codeception-markup-validator/badges/gpa.svg)](https://codeclimate.com/github/Kolyunya/codeception-markup-validator) 7 | 8 | ## Problem 9 | Programmatically validate markup of web application pages during automated acceptance testing. 10 | 11 | ## Solution 12 | Markup validator module for [Codeception](http://codeception.com). Validates web-pages markup (HTML, XHTML etc.) using markup validators e.g. [W3C Markup Validator Service](https://validator.w3.org/docs/api.html). Don't let invalid pages reach production. Add some zero effort tests to your acceptance suite which will immediately inform you when your markup gets broken. 13 | ```php 14 | $I->amOnPage('/'); 15 | $I->validateMarkup(); 16 | ``` 17 | 18 | Dead simple to use. Requires literally no configuraton. Works as you expect it out of box. Fully configurable and extendable if you want to hack it. Each component of the module can be replaced with your custom class. Just implement a simple interface and inject custom component to the module. 19 | 20 | ## Installation 21 | The recommended way of module installation is via [composer](https://getcomposer.org): 22 | ```sh 23 | composer require --dev kolyunya/codeception-markup-validator 24 | ``` 25 | 26 | ## Usage 27 | Add the module to your acceptance test suit configuration: 28 | ```yaml 29 | class_name: AcceptanceTester 30 | modules: 31 | enabled: 32 | - PhpBrowser: 33 | url: 'http://localhost/' 34 | - Kolyunya\Codeception\Module\MarkupValidator 35 | ``` 36 | 37 | Build the test suit: 38 | ```sh 39 | codecept build 40 | ``` 41 | 42 | Validate markup: 43 | ```php 44 | $I->amOnPage('/'); 45 | $I->validateMarkup(); 46 | ``` 47 | 48 | If you need, you may override module-wide message filter configuration for each page individually like this: 49 | ```php 50 | // Perform very strict checks for this particular page. 51 | $I->amOnPage('/foo/'); 52 | $I->validateMarkup(array( 53 | 'ignoreWarnings' => false, 54 | )); 55 | 56 | // Ignore those two errors just on this page. 57 | $I->amOnPage('/bar/'); 58 | $I->validateMarkup(array( 59 | 'ignoredErrors' => array( 60 | '/some error/', 61 | '/another error/', 62 | ), 63 | )); 64 | 65 | // Set error count threshold, do not ignore warnings 66 | // but ignore some errors on this page. 67 | $I->amOnPage('/quux/'); 68 | $I->validateMarkup(array( 69 | 'errorCountThreshold' => 10, 70 | 'ignoreWarnings' => false, 71 | 'ignoredErros' => array( 72 | '/this error/', 73 | '/that error/', 74 | ), 75 | )); 76 | ``` 77 | 78 | ## Configuration 79 | The module does not require any configuration. The default setup will work if you have either [`PhpBrowser`](http://codeception.com/docs/modules/PhpBrowser) or [`WebDriver`](http://codeception.com/docs/modules/WebDriver) modules enabled. 80 | 81 | Nevertheless the module is fully-configurable and hackable. It consist of four major components: [`provider`](https://github.com/Kolyunya/codeception-markup-validator/blob/master/sources/Lib/MarkupValidator/MarkupProviderInterface.php) which provides markup to validate, [`validator`](https://github.com/Kolyunya/codeception-markup-validator/blob/master/sources/Lib/MarkupValidator/MarkupValidatorInterface.php) which performs actual markup validation, [`filter`](https://github.com/Kolyunya/codeception-markup-validator/blob/master/sources/Lib/MarkupValidator/MessageFilterInterface.php) which filters messages received from the validator and [`printer`](https://github.com/Kolyunya/codeception-markup-validator/blob/master/sources/Lib/MarkupValidator/MessagePrinterInterface.php) which determines how to print messages received from the validator. You may configure each of the components with a custom implementation. 82 | 83 | ### Provider 84 | The module may be configured with a custom `provider` which will provide the markup to the `validator`. The [`default provider`](https://github.com/Kolyunya/codeception-markup-validator/blob/master/sources/Lib/MarkupValidator/DefaultMarkupProvider.php) tries to obtain markup from the `PhpBrowser` and `WebDriver` modules. 85 | ```yaml 86 | class_name: AcceptanceTester 87 | modules: 88 | enabled: 89 | - PhpBrowser: 90 | url: 'http://localhost/' 91 | - Kolyunya\Codeception\Module\MarkupValidator: 92 | provider: 93 | class: Acme\Tests\Path\To\CustomMarkupProvider 94 | ``` 95 | 96 | ### Validator 97 | The module may be configured with a custom `validator` which will validate markup received from the `provider`. The [default validator](https://github.com/Kolyunya/codeception-markup-validator/blob/master/sources/Lib/MarkupValidator/W3CMarkupValidator.php) uses the [W3C Markup Validation Service API](https://validator.w3.org/docs/api.html). 98 | ```yaml 99 | class_name: AcceptanceTester 100 | modules: 101 | enabled: 102 | - PhpBrowser: 103 | url: 'http://localhost/' 104 | - Kolyunya\Codeception\Module\MarkupValidator: 105 | validator: 106 | class: Acme\Tests\Path\To\CustomMarkupValidator 107 | ``` 108 | 109 | ### Filter 110 | The module may be configured with a custom `filter` which will filter messages received from the `validator`. You may implement you own `filter` or tweak a [default one](https://github.com/Kolyunya/codeception-markup-validator/blob/master/sources/Lib/MarkupValidator/DefaultMessageFilter.php). 111 | ```yaml 112 | class_name: AcceptanceTester 113 | modules: 114 | enabled: 115 | - PhpBrowser: 116 | url: 'http://localhost/' 117 | - Kolyunya\Codeception\Module\MarkupValidator: 118 | filter: 119 | class: Kolyunya\Codeception\Lib\MarkupValidator\DefaultMessageFilter 120 | config: 121 | errorCountThreshold: 10 122 | ignoreWarnings: true 123 | ignoredErrors: 124 | - '/some error/' 125 | - '/another error/' 126 | ``` 127 | 128 | ### Printer 129 | The module may be configured with a custom `printer` which defines how messages received from the `validator` are printed. The [default printer](https://github.com/Kolyunya/codeception-markup-validator/blob/master/sources/Lib/MarkupValidator/DefaultMessagePrinter.php) prints message type, summary, details, first line number, last line number and related markup. 130 | ```yaml 131 | class_name: AcceptanceTester 132 | modules: 133 | enabled: 134 | - PhpBrowser: 135 | url: 'http://localhost/' 136 | - Kolyunya\Codeception\Module\MarkupValidator: 137 | printer: 138 | class: Acme\Tests\Path\To\CustomMessagePrinter 139 | ``` 140 | 141 | ## Contributing 142 | If you found a bug or have a feature request feel free to [open an issue](https://github.com/Kolyunya/codeception-markup-validator/issues/new). If you want to send a pull request, backward-compatible changes should target the `master` branch while breaking changes - the next major version branch. 143 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kolyunya/codeception-markup-validator", 3 | "description": "Markup validator module for Codeception.", 4 | "type": "library", 5 | "license": "LGPL-3.0-or-later", 6 | "minimum-stability": "stable", 7 | "homepage": "https://github.com/Kolyunya/codeception-markup-validator", 8 | "keywords": [ 9 | "acceptance-testing", 10 | "codeception", 11 | "codeception-module", 12 | "html-validator", 13 | "markup-validator", 14 | "w3c-validator" 15 | ], 16 | "authors": [ 17 | { 18 | "name": "Kolyunya", 19 | "email": "oleynikovny@mail.ru", 20 | "homepage": "http://github.com/Kolyunya" 21 | } 22 | ], 23 | "require": { 24 | "php": ">=8.1 <9.0", 25 | "codeception/codeception": ">=2.0 <6.0", 26 | "guzzlehttp/guzzle": "^7.0" 27 | }, 28 | "require-dev": { 29 | "friendsofphp/php-cs-fixer": "^3.0", 30 | "phpstan/phpstan": "^1.9", 31 | "phpunit/phpunit": "^10.0" 32 | }, 33 | "autoload": { 34 | "psr-4": { 35 | "Kolyunya\\Codeception\\": "sources" 36 | } 37 | }, 38 | "autoload-dev": { 39 | "psr-4": { 40 | "Kolyunya\\Codeception\\Tests\\": "tests" 41 | } 42 | }, 43 | "config": { 44 | "sort-packages": true 45 | }, 46 | "scripts": { 47 | "validate-style": "PHP_CS_FIXER_IGNORE_ENV=TRUE vendor/bin/php-cs-fixer fix --dry-run", 48 | "analyze-sources": "vendor/bin/phpstan analyze --configuration=.phpstan-sources.neon", 49 | "analyze-tests": "vendor/bin/phpstan analyze --configuration=.phpstan-tests.neon", 50 | "run-test": "vendor/bin/phpunit" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | tests 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sources/Lib/Base/Component.php: -------------------------------------------------------------------------------- 1 | setConfiguration($configuration); 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | public function setConfiguration(array $configuration) 40 | { 41 | $this->configuration = array_merge($this->configuration, $configuration); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sources/Lib/Base/ComponentInterface.php: -------------------------------------------------------------------------------- 1 | moduleContainer = $moduleContainer; 31 | } 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | public function getMarkup() 37 | { 38 | try { 39 | return $this->getMarkupFromPhpBrowser(); 40 | } catch (Exception $exception) { 41 | // Wasn't able to get markup from the `PhpBrowser` module. 42 | } 43 | 44 | try { 45 | return $this->getMarkupFromWebDriver(); 46 | } catch (Exception $exception) { 47 | // Wasn't able to get markup from the `WebDriver` module. 48 | } 49 | 50 | throw new Exception('Unable to obtain current page markup.'); 51 | } 52 | 53 | /** 54 | * Returns current page markup form the `PhpBrowser` module. 55 | * 56 | * @return string Current page markup. 57 | */ 58 | private function getMarkupFromPhpBrowser() 59 | { 60 | /* @var $phpBrowser PhpBrowser */ 61 | $phpBrowser = $this->getModule('PhpBrowser'); 62 | $markup = $phpBrowser->_getResponseContent(); 63 | 64 | return $markup; 65 | } 66 | 67 | /** 68 | * Returns current page markup form the `WebDriver` module. 69 | * 70 | * @return string Current page markup. 71 | */ 72 | private function getMarkupFromWebDriver() 73 | { 74 | /* @var $webDriver WebDriver */ 75 | $webDriver = $this->getModule('WebDriver'); 76 | $markup = $webDriver->webDriver->getPageSource(); 77 | 78 | return $markup; 79 | } 80 | 81 | /** 82 | * Returns a module instance by its name. 83 | * 84 | * @param string $name Module name. 85 | * @return object Module instance. 86 | */ 87 | private function getModule($name) 88 | { 89 | if (!$this->moduleContainer->hasModule($name)) { 90 | throw new Exception(sprintf('«%s» module is not available.', $name)); 91 | } 92 | 93 | $module = $this->moduleContainer->getModule($name); 94 | 95 | return $module; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /sources/Lib/MarkupValidator/DefaultMessageFilter.php: -------------------------------------------------------------------------------- 1 | 0, 28 | self::IGNORE_WARNINGS_CONFIG_KEY => true, 29 | self::IGNORED_ERRORS_CONFIG_KEY => array(), 30 | ); 31 | 32 | /** 33 | * {@inheritDoc} 34 | */ 35 | public function filterMessages(array $messages) 36 | { 37 | $filteredMessages = array(); 38 | 39 | foreach ($messages as $message) { 40 | /* @var $message MarkupValidatorMessageInterface */ 41 | $messageType = $message->getType(); 42 | 43 | if ($messageType === MarkupValidatorMessageInterface::TYPE_UNDEFINED || 44 | $messageType === MarkupValidatorMessageInterface::TYPE_INFO 45 | ) { 46 | continue; 47 | } 48 | 49 | if ($messageType === MarkupValidatorMessageInterface::TYPE_WARNING && 50 | $this->ignoreWarnings() === true 51 | ) { 52 | continue; 53 | } 54 | 55 | if ($this->ignoreError($message->getSummary()) === true) { 56 | continue; 57 | } 58 | 59 | $filteredMessages[] = $message; 60 | } 61 | 62 | if ($this->belowErrorCountThreshold($filteredMessages) === true) { 63 | // Error count threshold was not reached. 64 | return array(); 65 | } 66 | 67 | return $filteredMessages; 68 | } 69 | 70 | /** 71 | * Returns a boolean indicating whether messages count 72 | * is below the threshold or not. 73 | * 74 | * @param array $messages Messages to report about. 75 | * 76 | * @return boolean Whether messages count is below the threshold or not. 77 | */ 78 | private function belowErrorCountThreshold(array $messages) 79 | { 80 | if (is_int($this->configuration[self::ERROR_COUNT_THRESHOLD_KEY]) === false) { 81 | throw new Exception(sprintf('Invalid «%s» config key.', self::ERROR_COUNT_THRESHOLD_KEY)); 82 | } 83 | 84 | $threshold = $this->configuration[self::ERROR_COUNT_THRESHOLD_KEY]; 85 | $belowThreshold = count($messages) <= $threshold; 86 | 87 | return $belowThreshold; 88 | } 89 | 90 | /** 91 | * Returns a boolean indicating whether the filter ignores warnings or not. 92 | * 93 | * @return bool Whether the filter ignores warnings or not. 94 | */ 95 | private function ignoreWarnings() 96 | { 97 | if (is_bool($this->configuration[self::IGNORE_WARNINGS_CONFIG_KEY]) === false) { 98 | throw new Exception(sprintf('Invalid «%s» config key.', self::IGNORE_WARNINGS_CONFIG_KEY)); 99 | } 100 | 101 | /* @var $ignoreWarnings bool */ 102 | $ignoreWarnings = $this->configuration[self::IGNORE_WARNINGS_CONFIG_KEY]; 103 | 104 | return $ignoreWarnings; 105 | } 106 | 107 | /** 108 | * Returns a boolean indicating whether an error is ignored or not. 109 | * 110 | * @param string|null $summary Error summary. 111 | * @return boolean Whether an error is ignored or not. 112 | */ 113 | private function ignoreError($summary) 114 | { 115 | if (is_array($this->configuration[self::IGNORED_ERRORS_CONFIG_KEY]) === false) { 116 | throw new Exception(sprintf('Invalid «%s» config key.', self::IGNORED_ERRORS_CONFIG_KEY)); 117 | } 118 | 119 | $ignoreError = false; 120 | 121 | if ($summary === null) { 122 | return $ignoreError; 123 | } 124 | 125 | $ignoredErrors = $this->configuration[self::IGNORED_ERRORS_CONFIG_KEY]; 126 | foreach ($ignoredErrors as $ignoredError) { 127 | $erorIsIgnored = preg_match($ignoredError, $summary) === 1; 128 | if ($erorIsIgnored) { 129 | $ignoreError = true; 130 | break; 131 | } 132 | } 133 | 134 | return $ignoreError; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /sources/Lib/MarkupValidator/DefaultMessagePrinter.php: -------------------------------------------------------------------------------- 1 | getMessageStringTemplate(), array( 25 | $message->getType(), 26 | $message->getSummary() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, 27 | $message->getDetails() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, 28 | $message->getFirstLineNumber() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, 29 | $message->getLastLineNumber() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, 30 | $message->getMarkup() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, 31 | )); 32 | } 33 | 34 | /** 35 | * {@inheritDoc} 36 | */ 37 | public function getMessagesString(array $messages) 38 | { 39 | $messagesStrings = array_map(array($this, 'getMessageString'), $messages); 40 | $messagesString = implode("\n", $messagesStrings); 41 | 42 | return $messagesString; 43 | } 44 | 45 | /** 46 | * Returns message string representation template. 47 | * 48 | * @return string Message string representation template. 49 | */ 50 | protected function getMessageStringTemplate() 51 | { 52 | return 53 | <<setType($type); 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | public function __toString() 73 | { 74 | return vsprintf($this->getStringTemplate(), array( 75 | $this->getType(), 76 | $this->getSummary() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, 77 | $this->getDetails() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, 78 | $this->getFirstLineNumber() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, 79 | $this->getLastLineNumber() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, 80 | $this->getMarkup() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, 81 | )); 82 | } 83 | 84 | /** 85 | * Sets message type. 86 | * 87 | * @param string|null $type Message type. 88 | * 89 | * @return self Returns self. 90 | */ 91 | public function setType($type) 92 | { 93 | if ($type === null) { 94 | $type = self::TYPE_UNDEFINED; 95 | } 96 | 97 | $this->type = $type; 98 | 99 | return $this; 100 | } 101 | 102 | /** 103 | * {@inheritDoc} 104 | */ 105 | public function getType() 106 | { 107 | return $this->type; 108 | } 109 | 110 | /** 111 | * Sets message summary. 112 | * 113 | * @param string $summary Message summary. 114 | * 115 | * @return self Returns self. 116 | */ 117 | public function setSummary($summary) 118 | { 119 | $this->summary = $summary; 120 | 121 | return $this; 122 | } 123 | 124 | /** 125 | * {@inheritDoc} 126 | */ 127 | public function getSummary() 128 | { 129 | return $this->summary; 130 | } 131 | 132 | /** 133 | * Sets message details. 134 | * 135 | * @param string $details Message details. 136 | * 137 | * @return self Returns self. 138 | */ 139 | public function setDetails($details) 140 | { 141 | $this->details = $details; 142 | 143 | return $this; 144 | } 145 | 146 | /** 147 | * {@inheritDoc} 148 | */ 149 | public function getDetails() 150 | { 151 | return $this->details; 152 | } 153 | 154 | /** 155 | * Sets first line number. 156 | * 157 | * @param integer $firstLineNumber First line number. 158 | * 159 | * @return self Returns self. 160 | */ 161 | public function setFirstLineNumber($firstLineNumber) 162 | { 163 | $this->firstLineNumber = $firstLineNumber; 164 | 165 | return $this; 166 | } 167 | 168 | /** 169 | * {@inheritDoc} 170 | */ 171 | public function getFirstLineNumber() 172 | { 173 | return $this->firstLineNumber; 174 | } 175 | 176 | /** 177 | * Sets last line number. 178 | * 179 | * @param integer $lastLineNumber Last line number. 180 | * 181 | * @return self Returns self. 182 | */ 183 | public function setLastLineNumber($lastLineNumber) 184 | { 185 | $this->lastLineNumber = $lastLineNumber; 186 | 187 | return $this; 188 | } 189 | 190 | /** 191 | * {@inheritDoc} 192 | */ 193 | public function getLastLineNumber() 194 | { 195 | return $this->lastLineNumber; 196 | } 197 | 198 | /** 199 | * Sets markup. 200 | * 201 | * @param string $markup Markup. 202 | * 203 | * @return self Returns self. 204 | */ 205 | public function setMarkup($markup) 206 | { 207 | $this->markup = $markup; 208 | 209 | return $this; 210 | } 211 | 212 | /** 213 | * {@inheritDoc} 214 | */ 215 | public function getMarkup() 216 | { 217 | return $this->markup; 218 | } 219 | 220 | /** 221 | * Returns string representation template. 222 | * 223 | * @return string String representation template. 224 | */ 225 | protected function getStringTemplate() 226 | { 227 | return 228 | << 'https://validator.w3.org/', 24 | self::ENDPOINT_CONFIG_KEY => '/nu/', 25 | ); 26 | 27 | /** 28 | * HTTP client used to communicate with the W3C Markup Validation Service. 29 | * 30 | * @var Client 31 | */ 32 | private $httpClient; 33 | 34 | /** 35 | * Parameters of a HTTP request to the W3C Markup Validation Service. 36 | * 37 | * @var array 38 | */ 39 | private $httpRequestParameters; 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function __construct(array $configuration = array()) 45 | { 46 | parent::__construct($configuration); 47 | 48 | $this->initializeHttpClient(); 49 | $this->initializeHttpRequestParameters(); 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | public function validate($markup) 56 | { 57 | $validationData = $this->getValidationData($markup); 58 | $validationMessages = $this->getValidationMessages($validationData); 59 | 60 | return $validationMessages; 61 | } 62 | 63 | /** 64 | * Initializes HTTP client used to communicate with the W3C Markup Validation Service. 65 | */ 66 | private function initializeHttpClient() 67 | { 68 | $this->httpClient = new Client(array( 69 | 'base_uri' => $this->configuration[self::BASE_URI_CONFIG_KEY], 70 | )); 71 | } 72 | 73 | /** 74 | * Initializes parameters of a HTTP request to the W3C Markup Validation Service. 75 | */ 76 | private function initializeHttpRequestParameters() 77 | { 78 | $this->httpRequestParameters = array( 79 | 'headers' => array( 80 | 'Content-Type' => 'text/html; charset=UTF-8;', 81 | ), 82 | 'query' => array( 83 | 'out' => 'json', 84 | ), 85 | ); 86 | } 87 | 88 | /** 89 | * Sends a validation request to a W3C Markup Validation Service 90 | * and returns decoded validation data. 91 | * 92 | * @param string $markup Markup to get validation data for. 93 | * @return array Validation data for provided markup. 94 | */ 95 | private function getValidationData($markup) 96 | { 97 | $this->httpRequestParameters['body'] = $markup; 98 | 99 | $reponse = $this->httpClient->post( 100 | $this->configuration[self::ENDPOINT_CONFIG_KEY], 101 | $this->httpRequestParameters 102 | ); 103 | $responseData = $reponse->getBody()->getContents(); 104 | $validationData = json_decode($responseData, true); 105 | if ($validationData === null) { 106 | throw new Exception('Unable to parse W3C Markup Validation Service response.'); 107 | } 108 | 109 | return $validationData; 110 | } 111 | 112 | /** 113 | * Parses validation data and returns validation messages. 114 | * 115 | * @param array $validationData Validation data. 116 | * @return MarkupValidatorMessageInterface[] Validation messages. 117 | */ 118 | private function getValidationMessages(array $validationData) 119 | { 120 | $messages = array(); 121 | $messagesData = $validationData['messages']; 122 | foreach ($messagesData as $messageData) { 123 | $message = new W3CMarkupValidatorMessage($messageData); 124 | $messages[] = $message; 125 | } 126 | 127 | return $messages; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /sources/Lib/MarkupValidator/W3CMarkupValidatorMessage.php: -------------------------------------------------------------------------------- 1 | initializeType($data); 24 | $this->initializeSummary($data); 25 | $this->initializeFirstLineNumber($data); 26 | $this->initializeLastLineNumber($data); 27 | $this->initializeMarkup($data); 28 | } 29 | 30 | /** 31 | * Initializes message type. 32 | * 33 | * @param array $data Message data. 34 | */ 35 | private function initializeType(array $data) 36 | { 37 | if (isset($data['type']) === false) { 38 | return; 39 | } 40 | 41 | if ($data['type'] === 'error') { 42 | $this->type = self::TYPE_ERROR; 43 | } elseif ($data['type'] === 'info') { 44 | if (isset($data['subType']) === true && 45 | $data['subType'] === 'warning' 46 | ) { 47 | $this->type = self::TYPE_WARNING; 48 | } else { 49 | $this->type = self::TYPE_INFO; 50 | } 51 | } 52 | } 53 | 54 | /** 55 | * Initializes message summary. 56 | * 57 | * @param array $data Message data. 58 | */ 59 | private function initializeSummary(array $data) 60 | { 61 | if (isset($data['message']) === true) { 62 | $this->setSummary($data['message']); 63 | } 64 | } 65 | 66 | /** 67 | * Initializes first line number. 68 | * 69 | * @param array $data Message data. 70 | */ 71 | private function initializeFirstLineNumber(array $data) 72 | { 73 | if (isset($data['firstLine']) === true) { 74 | $this->setFirstLineNumber($data['firstLine']); 75 | } 76 | } 77 | 78 | /** 79 | * Initializes last line number. 80 | * 81 | * @param array $data Message data. 82 | */ 83 | private function initializeLastLineNumber(array $data) 84 | { 85 | if (isset($data['lastLine']) === true) { 86 | $this->setLastLineNumber($data['lastLine']); 87 | } 88 | } 89 | 90 | /** 91 | * Initializes message markup. 92 | * 93 | * @param array $data Message data. 94 | */ 95 | private function initializeMarkup(array $data) 96 | { 97 | if (isset($data['extract']) === true) { 98 | $this->setMarkup($data['extract']); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /sources/Module/MarkupValidator.php: -------------------------------------------------------------------------------- 1 | array( 37 | self::COMPONENT_CLASS_CONFIG_KEY => 'Kolyunya\Codeception\Lib\MarkupValidator\DefaultMarkupProvider', 38 | ), 39 | self::VALIDATOR_CONFIG_KEY => array( 40 | self::COMPONENT_CLASS_CONFIG_KEY => 'Kolyunya\Codeception\Lib\MarkupValidator\W3CMarkupValidator', 41 | ), 42 | self::FILTER_CONFIG_KEY => array( 43 | self::COMPONENT_CLASS_CONFIG_KEY => 'Kolyunya\Codeception\Lib\MarkupValidator\DefaultMessageFilter', 44 | ), 45 | self::PRINTER_CONFIG_KEY => array( 46 | self::COMPONENT_CLASS_CONFIG_KEY => 'Kolyunya\Codeception\Lib\MarkupValidator\DefaultMessagePrinter', 47 | ), 48 | ); 49 | 50 | /** 51 | * Markup provider. 52 | * 53 | * @var MarkupProviderInterface|object 54 | */ 55 | private $markupProvider; 56 | 57 | /** 58 | * Markup validator. 59 | * 60 | * @var MarkupValidatorInterface|object 61 | */ 62 | private $markupValidator; 63 | 64 | /** 65 | * Message filter. 66 | * 67 | * @var MessageFilterInterface|object 68 | */ 69 | private $messageFilter; 70 | 71 | /** 72 | * Message printer. 73 | * 74 | * @var MessagePrinterInterface|object 75 | */ 76 | private $messagePrinter; 77 | 78 | /** 79 | * {@inheritDoc} 80 | */ 81 | public function __construct(ModuleContainer $moduleContainer, $config = null) 82 | { 83 | parent::__construct($moduleContainer, $config); 84 | 85 | $this->initializeMarkupProvider(); 86 | $this->initializeMarkupValidator(); 87 | $this->initializeMessageFilter(); 88 | $this->initializeMessagePrinter(); 89 | } 90 | 91 | /** 92 | * Validates page markup via a markup validator. 93 | * Allows to recongigure message filter component. 94 | * 95 | * @param array $messageFilterConfiguration Message filter configuration. 96 | */ 97 | public function validateMarkup(array $messageFilterConfiguration = array()) 98 | { 99 | $markup = $this->markupProvider->getMarkup(); 100 | $messages = $this->markupValidator->validate($markup); 101 | 102 | $this->messageFilter->setConfiguration($messageFilterConfiguration); 103 | $filteredMessages = $this->messageFilter->filterMessages($messages); 104 | 105 | if (empty($filteredMessages) === false) { 106 | $messagesString = $this->messagePrinter->getMessagesString($filteredMessages); 107 | $this->fail($messagesString); 108 | } 109 | 110 | // Validation succeeded. 111 | $this->assertTrue(true); 112 | } 113 | 114 | /** 115 | * Initializes markup provider. 116 | */ 117 | private function initializeMarkupProvider() 118 | { 119 | $interface = 'Kolyunya\Codeception\Lib\MarkupValidator\MarkupProviderInterface'; 120 | $this->markupProvider = $this->instantiateComponent(self::PROVIDER_CONFIG_KEY, $interface, array( 121 | $this->moduleContainer, 122 | )); 123 | } 124 | 125 | /** 126 | * Initializes markup validator. 127 | */ 128 | private function initializeMarkupValidator() 129 | { 130 | $interface = 'Kolyunya\Codeception\Lib\MarkupValidator\MarkupValidatorInterface'; 131 | $this->markupValidator = $this->instantiateComponent(self::VALIDATOR_CONFIG_KEY, $interface); 132 | } 133 | 134 | /** 135 | * Initializes message filter. 136 | */ 137 | private function initializeMessageFilter() 138 | { 139 | $interface = 'Kolyunya\Codeception\Lib\MarkupValidator\MessageFilterInterface'; 140 | $this->messageFilter = $this->instantiateComponent(self::FILTER_CONFIG_KEY, $interface); 141 | } 142 | 143 | /** 144 | * Initializes message printer. 145 | */ 146 | private function initializeMessagePrinter() 147 | { 148 | $interface = 'Kolyunya\Codeception\Lib\MarkupValidator\MessagePrinterInterface'; 149 | $this->messagePrinter = $this->instantiateComponent(self::PRINTER_CONFIG_KEY, $interface); 150 | } 151 | 152 | /** 153 | * Instantiates and returns a module component. 154 | * 155 | * @param string $componentName Component name. 156 | * @param string $interface An interface component must implement. 157 | * @param array $arguments Component's constructor arguments. 158 | * 159 | * @throws Exception When component does not implement expected interface. 160 | * 161 | * @return object Instance of a module component. 162 | */ 163 | private function instantiateComponent($componentName, $interface, array $arguments = array()) 164 | { 165 | $componentClass = $this->getComponentClass($componentName); 166 | $componentReflectionClass = new ReflectionClass($componentClass); 167 | if ($componentReflectionClass->implementsInterface($interface) === false) { 168 | $errorMessageTemplate = 'Invalid class «%s» provided for component «%s». It must implement «%s».'; 169 | $errorMessage = sprintf($errorMessageTemplate, $componentClass, $componentName, $interface); 170 | throw new Exception($errorMessage); 171 | } 172 | 173 | /* @var $component ComponentInterface */ 174 | $component = $componentReflectionClass->newInstanceArgs($arguments); 175 | $componentConfiguration = $this->getComponentConfiguration($componentName); 176 | $component->setConfiguration($componentConfiguration); 177 | 178 | return $component; 179 | } 180 | 181 | /** 182 | * Returns component class name. 183 | * 184 | * @param string $componentName Component name. 185 | * 186 | * @return string Component class name. 187 | */ 188 | private function getComponentClass($componentName) 189 | { 190 | $componentClassKey = self::COMPONENT_CLASS_CONFIG_KEY; 191 | if (isset($this->config[$componentName][$componentClassKey]) === false || 192 | is_string($this->config[$componentName][$componentClassKey]) === false 193 | ) { 194 | $errorMessage = sprintf('Invalid class configuration of component «%s».', $componentName); 195 | throw new Exception($errorMessage); 196 | } 197 | 198 | $componentClass = $this->config[$componentName][$componentClassKey]; 199 | 200 | return $componentClass; 201 | } 202 | 203 | /** 204 | * Returns component configuration parameters. 205 | * 206 | * @param string $componentName Component name. 207 | * 208 | * @return array Component configuration parameters. 209 | */ 210 | private function getComponentConfiguration($componentName) 211 | { 212 | $componentConfig = array(); 213 | 214 | $componentConfigKey = self::COMPONENT_CONFIG_CONFIG_KEY; 215 | if (isset($this->config[$componentName][$componentConfigKey]) === true) { 216 | if (is_array($this->config[$componentName][$componentConfigKey]) === false) { 217 | $errorMessage = sprintf('Invalid configuration of component «%s».', $componentName); 218 | throw new Exception($errorMessage); 219 | } 220 | 221 | $componentConfig = $this->config[$componentName][$componentConfigKey]; 222 | } 223 | 224 | return $componentConfig; 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /tests/Base/TestCase.php: -------------------------------------------------------------------------------- 1 | customSetExpectedException($arguments); 18 | break; 19 | } 20 | } 21 | 22 | private function customSetExpectedException($arguments) 23 | { 24 | $exceptionClass = $arguments[0]; 25 | $this->expectException($exceptionClass); 26 | 27 | $exceptionMessage = $arguments[1]; 28 | $this->expectExceptionMessage($exceptionMessage); 29 | 30 | if (isset($arguments[2]) === true) { 31 | $exceptionCode = $arguments[2]; 32 | $this->expectExceptionCode($exceptionCode); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Lib/Base/ComponentTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($classNameActual, $classNameExpected); 34 | } 35 | 36 | public static function dataProviderGetClassName() 37 | { 38 | return array( 39 | array( 40 | 'Kolyunya\Codeception\Lib\Base\Component', 41 | Component::getClassName(), 42 | ), 43 | array( 44 | 'Kolyunya\Codeception\Lib\MarkupValidator\DefaultMarkupProvider', 45 | DefaultMarkupProvider::getClassName(), 46 | ), 47 | array( 48 | 'Kolyunya\Codeception\Lib\MarkupValidator\DefaultMessageFilter', 49 | DefaultMessageFilter::getClassName(), 50 | ), 51 | array( 52 | 'Kolyunya\Codeception\Lib\MarkupValidator\DefaultMessagePrinter', 53 | DefaultMessagePrinter::getClassName(), 54 | ), 55 | array( 56 | 'Kolyunya\Codeception\Lib\MarkupValidator\W3CMarkupValidator', 57 | W3CMarkupValidator::getClassName(), 58 | ), 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/Lib/MarkupValidator/DefaultMarkupProviderTest.php: -------------------------------------------------------------------------------- 1 | moduleContainer = $this 28 | ->getMockBuilder('Codeception\Lib\ModuleContainer') 29 | ->disableOriginalConstructor() 30 | ->getMock() 31 | ; 32 | 33 | $this->provider = new DefaultMarkupProvider($this->moduleContainer); 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | public function tearDown(): void 40 | { 41 | } 42 | 43 | public function testWithNoPhpBrowserNoWebDriver() 44 | { 45 | $this->setExpectedException('Exception', 'Unable to obtain current page markup.'); 46 | $this->provider->getMarkup(); 47 | } 48 | 49 | public function testWithPhpBrowser() 50 | { 51 | $expectedMarkup = 52 | << 54 | 55 | 56 | 57 | A valid page. 58 | 59 | 60 | 61 | HTML 62 | ; 63 | 64 | $phpBrowser = $this 65 | ->getMockBuilder('Codeception\Module') 66 | ->disableOriginalConstructor() 67 | ->addMethods(array( 68 | '_getResponseContent', 69 | )) 70 | ->getMock() 71 | ; 72 | $phpBrowser 73 | ->method('_getResponseContent') 74 | ->will($this->returnValue($expectedMarkup)) 75 | ; 76 | 77 | $this->moduleContainer 78 | ->method('hasModule') 79 | ->will($this->returnValueMap(array( 80 | array('PhpBrowser', true) 81 | ))) 82 | ; 83 | $this->moduleContainer 84 | ->method('getModule') 85 | ->will($this->returnValueMap(array( 86 | array('PhpBrowser', $phpBrowser) 87 | ))) 88 | ; 89 | 90 | $actualMarkup = $this->provider->getMarkup(); 91 | $this->assertEquals($expectedMarkup, $actualMarkup); 92 | } 93 | 94 | public function testWithWebDriver() 95 | { 96 | $expectedMarkup = 97 | << 99 | 100 | 101 | 102 | A valid page. 103 | 104 | 105 | 106 | HTML 107 | ; 108 | 109 | $remoteWebDriver = $this 110 | ->getMockBuilder('Codeception\Module') 111 | ->disableOriginalConstructor() 112 | ->addMethods(array( 113 | 'getPageSource', 114 | )) 115 | ->getMock() 116 | ; 117 | $remoteWebDriver 118 | ->method('getPageSource') 119 | ->will($this->returnValue($expectedMarkup)) 120 | ; 121 | 122 | $webDriver = $this 123 | ->getMockBuilder('Codeception\Module') 124 | ->disableOriginalConstructor() 125 | ->getMock() 126 | ; 127 | $webDriver->webDriver = $remoteWebDriver; 128 | 129 | $this->moduleContainer 130 | ->method('hasModule') 131 | ->will($this->returnValueMap(array( 132 | array('PhpBrowser', false), 133 | array('WebDriver', true) 134 | ))) 135 | ; 136 | $this->moduleContainer 137 | ->method('getModule') 138 | ->will($this->returnValueMap(array( 139 | array('WebDriver', $webDriver) 140 | ))) 141 | ; 142 | 143 | $actualMarkup = $this->provider->getMarkup(); 144 | $this->assertEquals($expectedMarkup, $actualMarkup); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /tests/Lib/MarkupValidator/DefaultMessageFilterTest.php: -------------------------------------------------------------------------------- 1 | filter = new DefaultMessageFilter(); 24 | } 25 | 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | public function tearDown(): void 30 | { 31 | } 32 | 33 | /** 34 | * @dataProvider dataProviderFilterMessages 35 | */ 36 | public function testFilterMessages($sourceMessages, $filteredMessagesExpected) 37 | { 38 | $this->filter->setConfiguration(array( 39 | 'ignoreWarnings' => false, 40 | 'ignoredErrors' => array(), 41 | )); 42 | 43 | $filteredMessagesActual = $this->filter->filterMessages($sourceMessages); 44 | 45 | $this->assertEquals(count($filteredMessagesExpected), count($filteredMessagesActual)); 46 | $this->assertArraySubset($filteredMessagesExpected, $filteredMessagesActual); 47 | } 48 | 49 | /** 50 | * @dataProvider dataProviderErrorCountThreshold 51 | */ 52 | public function testerrorCountThreshold($messages, $threshold, $filteredMessagesExpected) 53 | { 54 | $this->filter->setConfiguration(array( 55 | 'errorCountThreshold' => $threshold, 56 | )); 57 | 58 | $filteredMessagesActual = $this->filter->filterMessages($messages); 59 | 60 | $this->assertEquals(count($filteredMessagesExpected), count($filteredMessagesActual)); 61 | $this->assertArraySubset($filteredMessagesExpected, $filteredMessagesActual); 62 | } 63 | 64 | /** 65 | * @dataProvider dataProviderIgnoreWarnings 66 | */ 67 | public function testIgnoreWarnings($messages, $filteredMessagesExpected) 68 | { 69 | $this->filter->setConfiguration(array( 70 | 'ignoreWarnings' => true, 71 | )); 72 | 73 | $filteredMessagesActual = $this->filter->filterMessages($messages); 74 | 75 | $this->assertEquals(count($filteredMessagesExpected), count($filteredMessagesActual)); 76 | $this->assertArraySubset($filteredMessagesExpected, $filteredMessagesActual); 77 | } 78 | 79 | /** 80 | * @dataProvider dataProviderIgnoredErrors 81 | */ 82 | public function testIgnoredErrors($messages, $ignoredErrors, $filteredMessagesExpected) 83 | { 84 | $this->filter->setConfiguration(array( 85 | 'ignoredErrors' => $ignoredErrors, 86 | )); 87 | 88 | $filteredMessagesActual = $this->filter->filterMessages($messages); 89 | 90 | $this->assertEquals(count($filteredMessagesExpected), count($filteredMessagesActual)); 91 | $this->assertArraySubset($filteredMessagesExpected, $filteredMessagesActual); 92 | } 93 | 94 | public function testInvaliderrorCountThresholdConfig() 95 | { 96 | $this->setExpectedException('Exception', 'Invalid «errorCountThreshold» config key.'); 97 | 98 | $warning = new MarkupValidatorMessage(); 99 | $warning->setType(MarkupValidatorMessageInterface::TYPE_WARNING); 100 | 101 | $this->filter->setConfiguration(array( 102 | 'errorCountThreshold' => true, 103 | )); 104 | $this->filter->filterMessages(array($warning)); 105 | } 106 | 107 | public function testInvalidIgnoreWarningsConfig() 108 | { 109 | $this->setExpectedException('Exception', 'Invalid «ignoreWarnings» config key.'); 110 | 111 | $warning = new MarkupValidatorMessage(); 112 | $warning->setType(MarkupValidatorMessageInterface::TYPE_WARNING); 113 | 114 | $this->filter->setConfiguration(array( 115 | 'ignoreWarnings' => array( 116 | 'foo' => false, 117 | 'bar' => true, 118 | ), 119 | )); 120 | $this->filter->filterMessages(array($warning)); 121 | } 122 | 123 | public function testInvalidIgnoreErrorsConfig() 124 | { 125 | $this->setExpectedException('Exception', 'Invalid «ignoredErrors» config key.'); 126 | 127 | $error = new MarkupValidatorMessage(); 128 | $error->setType(MarkupValidatorMessageInterface::TYPE_ERROR); 129 | 130 | $this->filter->setConfiguration(array( 131 | 'ignoredErrors' => false, 132 | )); 133 | $this->filter->filterMessages(array($error)); 134 | } 135 | 136 | public static function dataProviderErrorCountThreshold() 137 | { 138 | return array( 139 | array( 140 | array( 141 | ), 142 | 0, 143 | array( 144 | 145 | ), 146 | ), 147 | array( 148 | array( 149 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 150 | ), 151 | 1, 152 | array( 153 | 154 | ), 155 | ), 156 | array( 157 | array( 158 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 159 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 160 | ), 161 | 2, 162 | array( 163 | 164 | ), 165 | ), 166 | array( 167 | array( 168 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 169 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 170 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 171 | ), 172 | 5, 173 | array( 174 | 175 | ), 176 | ), 177 | array( 178 | array( 179 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 180 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 181 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 182 | ), 183 | -1, 184 | array( 185 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 186 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 187 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 188 | ), 189 | ), 190 | array( 191 | array( 192 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 193 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 194 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 195 | ), 196 | 2, 197 | array( 198 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 199 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 200 | new MarkupValidatorMessage(MarkupValidatorMessageInterface::TYPE_ERROR), 201 | ), 202 | ), 203 | ); 204 | } 205 | 206 | public static function dataProviderFilterMessages() 207 | { 208 | return array( 209 | array( 210 | array( 211 | (new MarkupValidatorMessage()) 212 | ->setType(MarkupValidatorMessageInterface::TYPE_UNDEFINED) 213 | ), 214 | array( 215 | 216 | ), 217 | ), 218 | array( 219 | array( 220 | (new MarkupValidatorMessage()) 221 | ->setType(MarkupValidatorMessageInterface::TYPE_INFO) 222 | ), 223 | array( 224 | 225 | ), 226 | ), 227 | array( 228 | array( 229 | (new MarkupValidatorMessage()) 230 | ->setType(MarkupValidatorMessageInterface::TYPE_WARNING) 231 | ->setSummary('Warning text.') 232 | ->setMarkup('

') 233 | , 234 | ), 235 | array( 236 | (new MarkupValidatorMessage()) 237 | ->setType(MarkupValidatorMessageInterface::TYPE_WARNING) 238 | ->setSummary('Warning text.') 239 | ->setMarkup('

') 240 | , 241 | ), 242 | ), 243 | array( 244 | array( 245 | (new MarkupValidatorMessage()) 246 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 247 | ->setSummary('Error text.') 248 | ->setMarkup('') 249 | , 250 | ), 251 | array( 252 | (new MarkupValidatorMessage()) 253 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 254 | ->setSummary('Error text.') 255 | ->setMarkup('') 256 | , 257 | ), 258 | ), 259 | ); 260 | } 261 | 262 | public static function dataProviderIgnoreWarnings() 263 | { 264 | return array( 265 | array( 266 | array( 267 | (new MarkupValidatorMessage()) 268 | ->setType(MarkupValidatorMessageInterface::TYPE_WARNING) 269 | , 270 | (new MarkupValidatorMessage()) 271 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 272 | , 273 | ), 274 | array( 275 | (new MarkupValidatorMessage()) 276 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 277 | , 278 | ), 279 | ), 280 | array( 281 | array( 282 | (new MarkupValidatorMessage()) 283 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 284 | , 285 | (new MarkupValidatorMessage()) 286 | ->setType(MarkupValidatorMessageInterface::TYPE_WARNING) 287 | , 288 | (new MarkupValidatorMessage()) 289 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 290 | , 291 | ), 292 | array( 293 | (new MarkupValidatorMessage()) 294 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 295 | , 296 | (new MarkupValidatorMessage()) 297 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 298 | , 299 | ), 300 | ), 301 | array( 302 | array( 303 | (new MarkupValidatorMessage()) 304 | ->setType(MarkupValidatorMessageInterface::TYPE_WARNING) 305 | , 306 | (new MarkupValidatorMessage()) 307 | ->setType(MarkupValidatorMessageInterface::TYPE_WARNING) 308 | , 309 | (new MarkupValidatorMessage()) 310 | ->setType(MarkupValidatorMessageInterface::TYPE_WARNING) 311 | , 312 | ), 313 | array( 314 | 315 | ), 316 | ), 317 | ); 318 | } 319 | 320 | public static function dataProviderIgnoredErrors() 321 | { 322 | return array( 323 | array( 324 | array( 325 | (new MarkupValidatorMessage()) 326 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 327 | ->setSummary('Some error message.') 328 | , 329 | (new MarkupValidatorMessage()) 330 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 331 | ->setSummary('Some cryptic error message.') 332 | , 333 | ), 334 | array( 335 | '/some error/i', 336 | '/cryptic error/', 337 | '/other error/', 338 | ), 339 | array( 340 | 341 | ), 342 | ), 343 | array( 344 | array( 345 | (new MarkupValidatorMessage()) 346 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 347 | ->setSummary('Some cryptic error message.') 348 | , 349 | ), 350 | array( 351 | '/some error/', 352 | '/other error/', 353 | ), 354 | array( 355 | (new MarkupValidatorMessage()) 356 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 357 | ->setSummary('Some cryptic error message.') 358 | , 359 | ), 360 | ), 361 | array( 362 | array( 363 | (new MarkupValidatorMessage()) 364 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 365 | ->setSummary('Some cryptic error message.') 366 | , 367 | ), 368 | array( 369 | '/cryptic error/', 370 | ), 371 | array( 372 | 373 | ), 374 | ), 375 | array( 376 | array( 377 | (new MarkupValidatorMessage()) 378 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 379 | ->setSummary('Case insensitive error message.') 380 | , 381 | ), 382 | array( 383 | '/case insensitive error message./i', 384 | ), 385 | array( 386 | 387 | ), 388 | ), 389 | array( 390 | array( 391 | (new MarkupValidatorMessage()) 392 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 393 | ->setSummary('Текст ошибки в UTF-8.') 394 | , 395 | ), 396 | array( 397 | '/Текст ошибки в UTF-8./u', 398 | ), 399 | array( 400 | 401 | ), 402 | ), 403 | array( 404 | array( 405 | (new MarkupValidatorMessage()) 406 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 407 | , 408 | ), 409 | array( 410 | '/error/', 411 | ), 412 | array( 413 | (new MarkupValidatorMessage()) 414 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 415 | , 416 | ), 417 | ), 418 | ); 419 | } 420 | } 421 | -------------------------------------------------------------------------------- /tests/Lib/MarkupValidator/DefaultMessagePrinterTest.php: -------------------------------------------------------------------------------- 1 | printer = new DefaultMessagePrinter(); 23 | } 24 | 25 | /** 26 | * {@inheritDoc} 27 | */ 28 | public function tearDown(): void 29 | { 30 | } 31 | 32 | /** 33 | * @dataProvider dataProviderGetMessageString 34 | */ 35 | public function testGetMessageString($message, $stringExpected) 36 | { 37 | $stringActual = $this->printer->getMessageString($message); 38 | $this->assertEquals($stringExpected, $stringActual); 39 | } 40 | 41 | /** 42 | * @dataProvider dataProviderGetMessagesString 43 | */ 44 | public function testGetMessagesString(array $messages, $stringExpected) 45 | { 46 | $stringActual = $this->printer->getMessagesString($messages); 47 | $this->assertEquals($stringExpected, $stringActual); 48 | } 49 | 50 | public static function dataProviderGetMessageString() 51 | { 52 | return array( 53 | array( 54 | (new MarkupValidatorMessage()) 55 | , 56 | <<setType(MarkupValidatorMessageInterface::TYPE_UNDEFINED) 71 | , 72 | <<setType(MarkupValidatorMessageInterface::TYPE_ERROR) 87 | ->setSummary('Short error summary.') 88 | ->setDetails('Detailed error description.') 89 | ->setFirstLineNumber(103) 90 | ->setLastLineNumber(105) 91 | ->setMarkup('') 92 | , 93 | << 101 | 102 | TXT 103 | , 104 | ), 105 | ); 106 | } 107 | 108 | public static function dataProviderGetMessagesString() 109 | { 110 | return array( 111 | array( 112 | array( 113 | (new MarkupValidatorMessage()) 114 | , 115 | (new MarkupValidatorMessage()) 116 | ->setType(MarkupValidatorMessageInterface::TYPE_UNDEFINED) 117 | , 118 | (new MarkupValidatorMessage()) 119 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 120 | ->setSummary('Short error summary.') 121 | ->setDetails('Detailed error description.') 122 | ->setFirstLineNumber(103) 123 | ->setLastLineNumber(105) 124 | ->setMarkup('') 125 | , 126 | ), 127 | << 151 | 152 | TXT 153 | , 154 | ), 155 | array( 156 | array( 157 | (new MarkupValidatorMessage()) 158 | ->setType(MarkupValidatorMessageInterface::TYPE_UNDEFINED) 159 | , 160 | (new MarkupValidatorMessage()) 161 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 162 | ->setSummary('Short error summary.') 163 | ->setDetails('Detailed error description.') 164 | ->setFirstLineNumber(103) 165 | ->setLastLineNumber(105) 166 | ->setMarkup('') 167 | , 168 | ), 169 | << 185 | 186 | TXT 187 | , 188 | ), 189 | array( 190 | array( 191 | (new MarkupValidatorMessage()) 192 | ->setType(MarkupValidatorMessageInterface::TYPE_ERROR) 193 | ->setSummary('Short error summary.') 194 | ->setDetails('Detailed error description.') 195 | ->setFirstLineNumber(103) 196 | ->setLastLineNumber(105) 197 | ->setMarkup('') 198 | , 199 | ), 200 | << 208 | 209 | TXT 210 | , 211 | ), 212 | array( 213 | array( 214 | ), 215 | <<assertEquals( 30 | $message->getType(), 31 | MarkupValidatorMessageInterface::TYPE_UNDEFINED 32 | ); 33 | $this->assertNull($message->getSummary()); 34 | $this->assertNull($message->getDetails()); 35 | $this->assertNull($message->getFirstLineNumber()); 36 | $this->assertNull($message->getLastLineNumber()); 37 | $this->assertNull($message->getMarkup()); 38 | } 39 | 40 | /** 41 | * @dataProvider dataProviderCustomInitialization 42 | */ 43 | public function testCustomInitialization($type, $summary, $details, $markup, $firstLineNumber, $lastLineNumber) 44 | { 45 | $message = (new MarkupValidatorMessage()) 46 | ->setType($type) 47 | ->setSummary($summary) 48 | ->setDetails($details) 49 | ->setMarkup($markup) 50 | ->setFirstLineNumber($firstLineNumber) 51 | ->setLastLineNumber($lastLineNumber) 52 | ; 53 | 54 | if ($type === null) { 55 | $this->assertEquals(MarkupValidatorMessageInterface::TYPE_UNDEFINED, $message->getType()); 56 | } else { 57 | $this->assertEquals($type, $message->getType()); 58 | } 59 | $this->assertEquals($summary, $message->getSummary()); 60 | $this->assertEquals($details, $message->getDetails()); 61 | $this->assertEquals($firstLineNumber, $message->getFirstLineNumber()); 62 | $this->assertEquals($lastLineNumber, $message->getLastLineNumber()); 63 | $this->assertEquals($markup, $message->getMarkup()); 64 | } 65 | 66 | /** 67 | * @dataProvider dataProviderToString 68 | */ 69 | public function testToString($type, $summary, $details, $firstLineNumber, $lastLineNumber, $markup, $string) 70 | { 71 | $message = (new MarkupValidatorMessage()) 72 | ->setType($type) 73 | ->setSummary($summary) 74 | ->setDetails($details) 75 | ->setFirstLineNumber($firstLineNumber) 76 | ->setLastLineNumber($lastLineNumber) 77 | ->setMarkup($markup) 78 | ; 79 | $messageString = $message->__toString(); 80 | $this->assertEquals($string, $messageString); 81 | } 82 | 83 | public static function dataProviderCustomInitialization() 84 | { 85 | return array( 86 | array( 87 | 'type' => null, 88 | 'summary' => null, 89 | 'details' => null, 90 | 'markup' => null, 91 | 'firstLineNumber' => null, 92 | 'lastLineNumber' => null, 93 | ), 94 | array( 95 | 'type' => MarkupValidatorMessageInterface::TYPE_UNDEFINED, 96 | 'summary' => null, 97 | 'details' => null, 98 | 'markup' => null, 99 | 'firstLineNumber' => null, 100 | 'lastLineNumber' => null, 101 | ), 102 | array( 103 | 'type' => MarkupValidatorMessageInterface::TYPE_ERROR, 104 | 'summary' => 'Short error summary.', 105 | 'details' => 'Detailed error description.', 106 | 'markup' => '', 107 | 'firstLineNumber' => 42, 108 | 'lastLineNumber' => 43, 109 | ), 110 | ); 111 | } 112 | 113 | public static function dataProviderToString() 114 | { 115 | return array( 116 | array( 117 | 'type' => null, 118 | 'summary' => null, 119 | 'details' => null, 120 | 'firstLineNumber' => null, 121 | 'lastLineNumber' => null, 122 | 'markup' => null, 123 | << MarkupValidatorMessageInterface::TYPE_UNDEFINED, 137 | 'summary' => null, 138 | 'details' => null, 139 | 'firstLineNumber' => null, 140 | 'lastLineNumber' => null, 141 | 'markup' => null, 142 | << MarkupValidatorMessageInterface::TYPE_ERROR, 156 | 'summary' => 'Short error summary.', 157 | 'details' => 'Detailed error description.', 158 | 'firstLineNumber' => 103, 159 | 'lastLineNumber' => 105, 160 | 'markup' => '', 161 | << 169 | 170 | TXT 171 | , 172 | ), 173 | ); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /tests/Lib/MarkupValidator/W3CMarkupValidatorMessageTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($message->getType(), $type); 33 | $this->assertEquals($message->getSummary(), $summary); 34 | $this->assertEquals($message->getDetails(), $details); 35 | $this->assertEquals($message->getFirstLineNumber(), $firstLineNumber); 36 | $this->assertEquals($message->getLastLineNumber(), $lastLineNumber); 37 | $this->assertEquals($message->getMarkup(), $markup); 38 | } 39 | 40 | public static function dataProviderConstructor() 41 | { 42 | return array( 43 | array( 44 | 'data' => array( 45 | 'type' => 'error', 46 | 'lastLine' => 4, 47 | 'lastColumn' => 27, 48 | 'firstColumn' => 21, 49 | 'message' => 'Element “head” is missing a required instance of child element “title”.', 50 | 'extract' => '\n', 51 | 'hiliteStart' => 10, 52 | 'hiliteLength' => 6, 53 | ), 54 | 'type' => MarkupValidatorMessageInterface::TYPE_ERROR, 55 | 'summary' => 'Element “head” is missing a required instance of child element “title”.', 56 | 'details' => null, 57 | 'firstLineNumber' => null, 58 | 'lastLineNumber' => 4, 59 | 'markup' => '\n', 60 | ), 61 | array( 62 | 'data' => array( 63 | 'type' => 'info', 64 | 'lastLine' => 7, 65 | 'lastColumn' => 50, 66 | 'firstColumn' => 29, 67 | 'subType' => 'warning', 68 | 'message' => 'The “button” role is unnecessary for element “button”.', 69 | 'extract' => ' 111 | 112 | 113 | 114 | HTML 115 | , 116 | array( 117 | array( 118 | 'type' => MarkupValidatorMessageInterface::TYPE_ERROR, 119 | 'summary' => 'Element “head” is missing a required instance of child element “title”.', 120 | 'details' => null, 121 | 'markup' => '', 122 | 'firstLineNumber' => null, 123 | 'lastLineNumber' => 4, 124 | ), 125 | array( 126 | 'type' => MarkupValidatorMessageInterface::TYPE_WARNING, 127 | 'summary' => 'The “button” role is unnecessary for element “button”.', 128 | 'details' => null, 129 | 'markup' => ' 240 | 241 | 242 | 243 | HTML 244 | , 245 | false, 246 | ), 247 | array( 248 | << 250 | 251 | 252 | 253 | A page with a warning. 254 | 255 | 256 | 257 |
258 | 260 |
261 | 262 | 263 | HTML 264 | , 265 | false, 266 | ), 267 | ); 268 | } 269 | 270 | public static function dataProviderOverrideFilterConfigurationWarnings() 271 | { 272 | return array( 273 | array( 274 | << 276 | 277 | 278 | 279 | A page with a warning. 280 | 281 | 282 | 283 |
284 | 286 |
287 | 288 | 289 | HTML 290 | , 291 | ), 292 | ); 293 | } 294 | 295 | public static function dataProviderOverrideFilterConfigurationErrors() 296 | { 297 | return array( 298 | array( 299 | << 301 | 302 | 303 | 304 | 305 | HTML 306 | , 307 | array( 308 | '/Element “head” is missing a required instance of child element “title”./', 309 | ), 310 | ), 311 | ); 312 | } 313 | 314 | private function mockMarkup($markup) 315 | { 316 | $phpBrowser = $this 317 | ->getMockBuilder('Codeception\Module') 318 | ->disableOriginalConstructor() 319 | ->addMethods(array( 320 | '_getResponseContent', 321 | )) 322 | ->getMock() 323 | ; 324 | $phpBrowser 325 | ->method('_getResponseContent') 326 | ->will($this->returnValue($markup)) 327 | ; 328 | 329 | $this->moduleContainer 330 | ->method('hasModule') 331 | ->will($this->returnValueMap(array( 332 | array('PhpBrowser', true), 333 | ))) 334 | ; 335 | $this->moduleContainer 336 | ->method('getModule') 337 | ->will($this->returnValueMap(array( 338 | array('PhpBrowser', $phpBrowser), 339 | ))) 340 | ; 341 | } 342 | } 343 | --------------------------------------------------------------------------------