From b8c8390689f1d6eef339d206b9f6dc492f745b98 Mon Sep 17 00:00:00 2001 From: miya0001 Date: Tue, 15 Nov 2016 01:32:05 +0900 Subject: [PATCH 01/12] update package.json --- package.json | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/package.json b/package.json index 4fe6555..66b6ad9 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,4 @@ { - "name": "wordpress-extension", "scripts": { "install-wp": "curl https://raw.githubusercontent.com/vccw-team/install-wp/master/install-wp.sh | /usr/bin/env bash", "wp": "curl https://raw.githubusercontent.com/vccw-team/install-wp/master/run-wp.sh | /usr/bin/env bash", @@ -7,16 +6,6 @@ "behat": "/usr/bin/env node bin/run-tests.js", "test": "npm run phpspec && npm run behat" }, - "repository": { - "type": "git", - "url": "git+https://github.com/vccw-team/wordpress-extension.git" - }, - "author": "", - "license": "MIT", - "bugs": { - "url": "https://github.com/vccw-team/wordpress-extension/issues" - }, - "homepage": "https://github.com/vccw-team/wordpress-extension#readme", "devDependencies": { "phantomjs-prebuilt": "^2.1.13" } From 5e785a7f7d5ca523a5eb49b801ed6869346be2ba Mon Sep 17 00:00:00 2001 From: miya0001 Date: Thu, 17 Nov 2016 18:56:04 +0900 Subject: [PATCH 02/12] add .envrc --- .envrc | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a1ee1c0 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +export WP_VERSION=latest +export WP_THEME=twentysixteen +export WP_PATH=/tmp/wp-tests From b3ac8881c02b4ed07fdbcc82cb788785f6343271 Mon Sep 17 00:00:00 2001 From: miya0001 Date: Fri, 25 Nov 2016 17:12:16 +0900 Subject: [PATCH 03/12] add .editorconfig --- .editorconfig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f56bb8c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.php] +indent_style = tab +indent_size = 4 + +[*.yml] +indent_style = space +indent_size = 4 From f6ecd364b4f5219fff207759469e4882c6bf7b81 Mon Sep 17 00:00:00 2001 From: miya0001 Date: Fri, 25 Nov 2016 17:14:00 +0900 Subject: [PATCH 04/12] update editorconfig --- .editorconfig | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.editorconfig b/.editorconfig index f56bb8c..6dda443 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,7 +11,3 @@ trim_trailing_whitespace = true [*.php] indent_style = tab indent_size = 4 - -[*.yml] -indent_style = space -indent_size = 4 From ecdcfb81fbeea56250f1546e8d37659e5ab8ae80 Mon Sep 17 00:00:00 2001 From: miya0001 Date: Fri, 25 Nov 2016 19:53:10 +0900 Subject: [PATCH 05/12] remove twentyseventeen --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 24f9370..dec7cad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ php: env: matrix: - - WP_VERSION=nightly WP_THEME=twentyseventeen + - WP_VERSION=nightly WP_THEME=twentysixteen - WP_VERSION=latest WP_THEME=twentysixteen before_install: From 5ecd2a198460cc246228367b777f561da5094dc5 Mon Sep 17 00:00:00 2001 From: miya0001 Date: Thu, 1 Dec 2016 11:49:51 -0500 Subject: [PATCH 06/12] add wp-cli.yml to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fda5ca4..1aba98f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ behat.yml node_modules/ npm-debug.log vendor/ +wp-cli.yml wp-cli-nightly.phar From f9924c255aa03827e44f2a677dd2e321192768ed Mon Sep 17 00:00:00 2001 From: miya0001 Date: Thu, 1 Dec 2016 13:54:14 -0500 Subject: [PATCH 07/12] improve tests for roles --- features/login-as-the-role.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/login-as-the-role.feature b/features/login-as-the-role.feature index 3e3b5fa..6a06417 100644 --- a/features/login-as-the-role.feature +++ b/features/login-as-the-role.feature @@ -22,4 +22,4 @@ Feature: I login as the specfic role Then I should see "Dashboard" When I am on "/wp-admin/plugins.php" - Then I should see a "#error-page" element + Then I should see "Sorry, you are not allowed to access this page." From 197cccb1d4714762b9637fcdc3acfda472855929 Mon Sep 17 00:00:00 2001 From: hideokamoto Date: Sun, 4 Dec 2016 13:21:31 -0500 Subject: [PATCH 08/12] #8 fix readme command about see context --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a91135..a947996 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Feature: I login as the specfic role Run to see contexts. ``` -$ vendor/bin/behat --di --lang=en +$ vendor/bin/behat -di --lang=en ``` ### Install headless browser From 983bf8aa70af1b4bd2172e9287ff379968c107fe Mon Sep 17 00:00:00 2001 From: miya0001 Date: Sat, 24 Dec 2016 03:02:27 +0900 Subject: [PATCH 09/12] goutte driver support --- composer.json | 4 +- composer.lock | 498 +++++++++++++++++++++++++++- features/http-status.feature | 10 + src/Context/RawWordPressContext.php | 28 ++ src/Context/WordPressContext.php | 16 + 5 files changed, 553 insertions(+), 3 deletions(-) create mode 100644 features/http-status.feature diff --git a/composer.json b/composer.json index 0975c6a..7904c01 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,9 @@ "behat/mink": "~1.7", "behat/mink-extension": "~2.2", "behat/mink-selenium2-driver": "~1.3.1", - "phpunit/phpunit": "^5.6" + "phpunit/phpunit": "^5.6", + "behat/mink-goutte-driver": "^1.2", + "guzzlehttp/guzzle": "^6.2" }, "require-dev": { "phpspec/phpspec": "^3.1" diff --git a/composer.lock b/composer.lock index d92f610..3d28b9a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "f55a34e59c772ce5b911d53d43b11614", - "content-hash": "6ce99aac3774fe2b3c9f6b88a5368def", + "hash": "cc1373da7ac4b695a9161f6b620698f2", + "content-hash": "97eeb6d00cbd5356dc76a08380fe887f", "packages": [ { "name": "behat/behat", @@ -205,6 +205,62 @@ ], "time": "2016-03-05 08:26:18" }, + { + "name": "behat/mink-browserkit-driver", + "version": "v1.3.2", + "source": { + "type": "git", + "url": "https://github.com/minkphp/MinkBrowserKitDriver.git", + "reference": "10e67fb4a295efcd62ea0bf16025a85ea19534fb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/minkphp/MinkBrowserKitDriver/zipball/10e67fb4a295efcd62ea0bf16025a85ea19534fb", + "reference": "10e67fb4a295efcd62ea0bf16025a85ea19534fb", + "shasum": "" + }, + "require": { + "behat/mink": "^1.7.1@dev", + "php": ">=5.3.6", + "symfony/browser-kit": "~2.3|~3.0", + "symfony/dom-crawler": "~2.3|~3.0" + }, + "require-dev": { + "silex/silex": "~1.2", + "symfony/phpunit-bridge": "~2.7|~3.0" + }, + "type": "mink-driver", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Behat\\Mink\\Driver\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + } + ], + "description": "Symfony2 BrowserKit driver for Mink framework", + "homepage": "http://mink.behat.org/", + "keywords": [ + "Mink", + "Symfony2", + "browser", + "testing" + ], + "time": "2016-03-05 08:59:47" + }, { "name": "behat/mink-extension", "version": "v2.2", @@ -264,6 +320,61 @@ ], "time": "2016-02-15 07:55:18" }, + { + "name": "behat/mink-goutte-driver", + "version": "v1.2.1", + "source": { + "type": "git", + "url": "https://github.com/minkphp/MinkGoutteDriver.git", + "reference": "8b9ad6d2d95bc70b840d15323365f52fcdaea6ca" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/minkphp/MinkGoutteDriver/zipball/8b9ad6d2d95bc70b840d15323365f52fcdaea6ca", + "reference": "8b9ad6d2d95bc70b840d15323365f52fcdaea6ca", + "shasum": "" + }, + "require": { + "behat/mink": "~1.6@dev", + "behat/mink-browserkit-driver": "~1.2@dev", + "fabpot/goutte": "~1.0.4|~2.0|~3.1", + "php": ">=5.3.1" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7|~3.0" + }, + "type": "mink-driver", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Behat\\Mink\\Driver\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + } + ], + "description": "Goutte driver for Mink framework", + "homepage": "http://mink.behat.org/", + "keywords": [ + "browser", + "goutte", + "headless", + "testing" + ], + "time": "2016-03-05 09:04:22" + }, { "name": "behat/mink-selenium2-driver", "version": "v1.3.1", @@ -419,6 +530,226 @@ ], "time": "2015-06-14 21:17:01" }, + { + "name": "fabpot/goutte", + "version": "v3.2.0", + "source": { + "type": "git", + "url": "https://github.com/FriendsOfPHP/Goutte.git", + "reference": "8cc89de5e71daf84051859616891d3320d88a9e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FriendsOfPHP/Goutte/zipball/8cc89de5e71daf84051859616891d3320d88a9e8", + "reference": "8cc89de5e71daf84051859616891d3320d88a9e8", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.0", + "php": ">=5.5.0", + "symfony/browser-kit": "~2.1|~3.0", + "symfony/css-selector": "~2.1|~3.0", + "symfony/dom-crawler": "~2.1|~3.0" + }, + "type": "application", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Goutte\\": "Goutte" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "A simple PHP Web Scraper", + "homepage": "https://github.com/FriendsOfPHP/Goutte", + "keywords": [ + "scraper" + ], + "time": "2016-11-15 16:27:29" + }, + { + "name": "guzzlehttp/guzzle", + "version": "6.2.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ebf29dee597f02f09f4d5bbecc68230ea9b08f60", + "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.3.1", + "php": ">=5.5" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0", + "psr/log": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.2-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2016-10-08 15:01:37" + }, + { + "name": "guzzlehttp/promises", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-12-20 10:07:11" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", + "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "PSR-7 message implementation", + "keywords": [ + "http", + "message", + "stream", + "uri" + ], + "time": "2016-06-24 23:00:38" + }, { "name": "instaclick/php-webdriver", "version": "1.4.3", @@ -1112,6 +1443,56 @@ ], "time": "2016-10-09 07:01:45" }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06 14:39:51" + }, { "name": "psr/log", "version": "1.0.2", @@ -1672,6 +2053,63 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-02-04 12:56:52" }, + { + "name": "symfony/browser-kit", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/browser-kit.git", + "reference": "34348c2691ce6254e8e008026f4c5e72c22bb318" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/browser-kit/zipball/34348c2691ce6254e8e008026f4c5e72c22bb318", + "reference": "34348c2691ce6254e8e008026f4c5e72c22bb318", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/dom-crawler": "~2.8|~3.0" + }, + "require-dev": { + "symfony/css-selector": "~2.8|~3.0", + "symfony/process": "~2.8|~3.0" + }, + "suggest": { + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\BrowserKit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony BrowserKit Component", + "homepage": "https://symfony.com", + "time": "2016-10-13 13:35:11" + }, { "name": "symfony/class-loader", "version": "v3.1.6", @@ -2012,6 +2450,62 @@ "homepage": "https://symfony.com", "time": "2016-10-24 15:52:44" }, + { + "name": "symfony/dom-crawler", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/dom-crawler.git", + "reference": "1638c7534a8a2fa0bf9e979f9aacb6d7e8e9e24e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/1638c7534a8a2fa0bf9e979f9aacb6d7e8e9e24e", + "reference": "1638c7534a8a2fa0bf9e979f9aacb6d7e8e9e24e", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "symfony/css-selector": "~2.8|~3.0" + }, + "suggest": { + "symfony/css-selector": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DomCrawler\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DomCrawler Component", + "homepage": "https://symfony.com", + "time": "2016-12-10 14:24:53" + }, { "name": "symfony/event-dispatcher", "version": "v3.1.6", diff --git a/features/http-status.feature b/features/http-status.feature new file mode 100644 index 0000000..02262fc --- /dev/null +++ b/features/http-status.feature @@ -0,0 +1,10 @@ +Feature: HTTP status + + Scenario: Check http status code + + When I am on "/" + Then the HTTP status should be 200 + + When I am on "/the-page-not-found" + Then the HTTP status should be 404 + diff --git a/src/Context/RawWordPressContext.php b/src/Context/RawWordPressContext.php index 45b9d9c..0bee54c 100644 --- a/src/Context/RawWordPressContext.php +++ b/src/Context/RawWordPressContext.php @@ -59,6 +59,18 @@ public function get_variables( $key ) } } + /** + * Get http status code from the current page. + * + * @param string $user The user name. + * @param string $password The password. + */ + protected function get_http_status() + { + $session = $this->get_goutte_session(); + return $session->getStatusCode(); + } + /** * Log in into the WordPress * @@ -340,4 +352,20 @@ protected function assertFalse( $condition, $message = '' ) { \PHPUnit_Framework_Assert::assertFalse( $condition, $message = '' ); } + + protected function get_goutte_session() + { + $current_url = $this->getSession()->getCurrentUrl(); + + $goutteClient = new \Behat\Mink\Driver\Goutte\Client(); + $guzzleClient = new \GuzzleHttp\Client(); + $goutteClient->setClient($guzzleClient); + + $driver = new \Behat\Mink\Driver\GoutteDriver( $goutteClient ); + $session = new \Behat\Mink\Session( $driver ); + $session->start(); + $session->visit( $current_url ); + + return $session; + } } diff --git a/src/Context/WordPressContext.php b/src/Context/WordPressContext.php index e2c9c36..7c82456 100644 --- a/src/Context/WordPressContext.php +++ b/src/Context/WordPressContext.php @@ -23,6 +23,22 @@ public function save_env_as_var( $env, $var ) $this->set_variables( $var, getenv( $env ) ); } + /** + * Check http status code. + * Example: Given save env $WP_VERSION as {WP_VERSION} + * + * @then /^the HTTP status should be (?P[0-9]+)$/ + */ + public function the_http_status_should_be( $expect ) + { + $status = $this->get_http_status(); + $this->assertSame( $status, intval( $expect ), sprintf( + 'The HTTP status is %1$s, but it should be %2$s', + $status, + $expect + ) ); + } + /** * Check status of plugins * Example: From 3e87dd028fae69b169d5410a325bd65fada2a27e Mon Sep 17 00:00:00 2001 From: miya0001 Date: Sat, 24 Dec 2016 03:07:18 +0900 Subject: [PATCH 10/12] update readme --- src/Context/RawWordPressContext.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Context/RawWordPressContext.php b/src/Context/RawWordPressContext.php index 0bee54c..6198bc4 100644 --- a/src/Context/RawWordPressContext.php +++ b/src/Context/RawWordPressContext.php @@ -62,13 +62,12 @@ public function get_variables( $key ) /** * Get http status code from the current page. * - * @param string $user The user name. - * @param string $password The password. + * @return int HTTP status code. */ protected function get_http_status() { $session = $this->get_goutte_session(); - return $session->getStatusCode(); + return intval( $session->getStatusCode() ); } /** @@ -353,6 +352,11 @@ protected function assertFalse( $condition, $message = '' ) \PHPUnit_Framework_Assert::assertFalse( $condition, $message = '' ); } + /** + * Create and return session with goutte driver. + * + * @return object The session object of a goutte driver. + */ protected function get_goutte_session() { $current_url = $this->getSession()->getCurrentUrl(); From 7d13393875307955e11fe9124f965acbe9dc4ff2 Mon Sep 17 00:00:00 2001 From: miya0001 Date: Sat, 24 Dec 2016 03:28:05 +0900 Subject: [PATCH 11/12] add php -d args --- bin/run-tests.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/run-tests.js b/bin/run-tests.js index 6eed03c..0045a0d 100644 --- a/bin/run-tests.js +++ b/bin/run-tests.js @@ -5,12 +5,19 @@ const argv = process.argv argv.shift() argv.shift() +args = [ + 'php', + '-d', + 'memory_limit=-1', + 'vendor/bin/behat' +] + phantomjs.run( '--webdriver=4444', '--ignore-ssl-errors=yes', '--cookies-file=/tmp/webdriver_cookie.txt' ).then( program => { - const behat = spawn( 'vendor/bin/behat', argv, { stdio: "inherit" } ) + const behat = spawn( '/usr/bin/env', args.concat( argv ), { stdio: "inherit" } ) behat.on( 'exit', ( code ) => { program.kill() process.exit( code ); From eb1a79e49f0ea2efa2d762a04b72de4ca161875f Mon Sep 17 00:00:00 2001 From: miya0001 Date: Sat, 24 Dec 2016 04:08:24 +0900 Subject: [PATCH 12/12] add context that checks the resonse headers --- features/http-response.feature | 18 +++++++++ features/http-status.feature | 10 ----- features/plugins.feature | 14 +++---- src/Context/RawWordPressContext.php | 11 ++++++ src/Context/WordPressContext.php | 60 ++++++++++++++++++++++------- 5 files changed, 83 insertions(+), 30 deletions(-) create mode 100644 features/http-response.feature delete mode 100644 features/http-status.feature diff --git a/features/http-response.feature b/features/http-response.feature new file mode 100644 index 0000000..264a063 --- /dev/null +++ b/features/http-response.feature @@ -0,0 +1,18 @@ +Feature: HTTP response + + Scenario: Check http status code + + When I am on "/" + Then the HTTP status should be 200 + + When I am on "/the-page-not-found" + Then the HTTP status should be 404 + + Scenario: Check http response headers + + When I am on "/" + Then the HTTP headers should be: + | header | value | + | Content-Type | text/html; charset=UTF-8 | + | Connection | close | + | Host | 127.0.0.1:8080 | diff --git a/features/http-status.feature b/features/http-status.feature deleted file mode 100644 index 02262fc..0000000 --- a/features/http-status.feature +++ /dev/null @@ -1,10 +0,0 @@ -Feature: HTTP status - - Scenario: Check http status code - - When I am on "/" - Then the HTTP status should be 200 - - When I am on "/the-page-not-found" - Then the HTTP status should be 404 - diff --git a/features/plugins.feature b/features/plugins.feature index f14077b..a643b34 100644 --- a/features/plugins.feature +++ b/features/plugins.feature @@ -3,16 +3,16 @@ Feature: Get statuses of plugins Scenario: Get plugins When I login as the "administrator" role - Then plugins should be: + Then the plugins should be: | slug | status | | akismet | inactive | | hello-dolly | inactive | | wordpress-importer | active | - Scenario Outline: Plugins should be installed. + Scenario Outline: Plugin should be installed. When I login as the "administrator" role - Then the "" plugins should be installed + Then the "" plugin should be installed Examples: | slug | @@ -23,21 +23,21 @@ Feature: Get statuses of plugins Scenario Outline: Plugins should be activated. When I login as the "administrator" role - Then the "" plugins should be activated + Then the "" plugin should be activated Examples: | slug | | wordpress-importer | - Scenario: Plugins should not be installed. + Scenario: Plugin should not be installed. When I login as the "administrator" role - Then the "my-plugin" plugins should not be installed + Then the "my-plugin" plugin should not be installed Scenario Outline: Plugins should not be activated. When I login as the "administrator" role - Then the "" plugins should not be activated + Then the "" plugin should not be activated Examples: | slug | diff --git a/src/Context/RawWordPressContext.php b/src/Context/RawWordPressContext.php index 6198bc4..165c135 100644 --- a/src/Context/RawWordPressContext.php +++ b/src/Context/RawWordPressContext.php @@ -70,6 +70,17 @@ protected function get_http_status() return intval( $session->getStatusCode() ); } + /** + * Get http response headers from the current page. + * + * @return array HTTP response headers. + */ + protected function get_http_headers() + { + $session = $this->get_goutte_session(); + return $session->getResponseHeaders(); + } + /** * Log in into the WordPress * diff --git a/src/Context/WordPressContext.php b/src/Context/WordPressContext.php index 7c82456..819e435 100644 --- a/src/Context/WordPressContext.php +++ b/src/Context/WordPressContext.php @@ -13,7 +13,7 @@ class WordPressContext extends RawWordPressContext { /** - * Save env to variable + * Save env to variable. * Example: Given save env $WP_VERSION as {WP_VERSION} * * @Given /^save env \$(?P[A-Z_]+) as \{(?P[A-Z_]+)\}$/ @@ -39,22 +39,56 @@ public function the_http_status_should_be( $expect ) ) ); } + /** + * Check HTTP response headers. + * Example: + * Then the HTTP headers should be: + * | header | value | + * | Content-Type | text/html; charset=UTF-8 | + * | Connection | close | + * | Host | 127.0.0.1:8080 | + * + * @then /^the HTTP headers should be:$/ + */ + public function the_http_headers_should_be( TableNode $table ) + { + $headers = $this->get_http_headers(); + + foreach ( $table->getHash() as $row ) { + if ( ! empty( $headers[ $row['header'] ] ) ) { + $value = $headers[ $row['header'] ][0]; + $this->assertSame( $row['value'], $value, sprintf( + 'The value of "%1$s" header is "%1$s", but it should be "%3$s".', + $row['header'], + $value, + $row['value'] + ) ); + } else { + throw new \Exception( sprintf( + 'The value of "%1$s" header is empty, but it should be "%2$s".', + $row['header'], + $row['value'] + ) ); + } + } + } + /** * Check status of plugins * Example: - * Then there are plugins: + * Then the plugins should be: * | slug | status | * | akismet | inactive | * | hello-dolly | inactive | * | wordpress-importer | active | * - * @then /^plugins should be:$/ + * @then /^the plugins should be:$/ */ - public function there_are_plugins( TableNode $table ) + public function the_plugins_should_be( TableNode $table ) { $plugins = $this->get_plugins(); - foreach ($table->getHash() as $row) { + foreach ( $table->getHash() as $row ) { if ( ! empty( $plugins[ $row['slug'] ] ) ) { $status = $plugins[ $row['slug'] ]['status']; $this->assertSame( $row['status'], $status, sprintf( @@ -72,9 +106,9 @@ public function there_are_plugins( TableNode $table ) } /** - * Check status of plugins + * Check status of plugins. * - * @then /^the "(?P[^"]*)" plugins should be (?P(installed|activated))$/ + * @then /^the "(?P[^"]*)" plugin should be (?P(installed|activated))$/ */ public function the_plugin_should_be( $slug, $expect ) { @@ -97,9 +131,9 @@ public function the_plugin_should_be( $slug, $expect ) } /** - * Check status of plugins + * Check status of plugins. * - * @then /^the "(?P[^"]*)" plugins should not be (?P(installed|activated))$/ + * @then /^the "(?P[^"]*)" plugin should not be (?P(installed|activated))$/ */ public function the_plugin_should_not_be( $slug, $expect ) { @@ -122,7 +156,7 @@ public function the_plugin_should_not_be( $slug, $expect ) } /** - * Check the theme is activated + * Check the theme is activated. * Example: Given the "twentysixteen" theme should be activated * * @Then /^the "(?P[^"]*)" theme should be activated$/ @@ -140,7 +174,7 @@ public function theme_should_be_activated( $theme ) } /** - * Check WordPress version + * Check WordPress version. * Example: Given the WordPress version should be "4.6" * * @Given /^the WordPress version should be "(?P[^"]*)"$/ @@ -174,7 +208,7 @@ public function wordpress_version_should_be( $version ) } /** - * Return exception if user is not logged in + * Return exception if user is not logged-in. * Example: Then I should be logged in * * @Then I should be logged in @@ -187,7 +221,7 @@ public function i_should_be_logged_in() } /** - * Return exception if user is logged in + * Return exception if user is logged-in. * Example: I should not be logged in * * @Then I should not be logged in