From 6643a2e1c2544e8c6a6edc71820f0f6b2ea44b23 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 09:52:47 +0100 Subject: [PATCH 01/24] Initial conversion to 3.x --- README.md | 19 ++++-- composer.json | 10 +-- .../Controller}/Component/SeoComponent.php | 64 ++++++++----------- {View => src/View}/Helper/SeoHelper.php | 55 ++++++++-------- {Test/Case => tests/TestCase}/AllSeoTest.php | 0 .../Controller/Component/SeoComponentTest.php | 0 .../TestCase}/View/Helper/SeoHelperTest.php | 0 7 files changed, 75 insertions(+), 73 deletions(-) rename {Controller => src/Controller}/Component/SeoComponent.php (72%) rename {View => src/View}/Helper/SeoHelper.php (65%) rename {Test/Case => tests/TestCase}/AllSeoTest.php (100%) rename {Test/Case => tests/TestCase}/Controller/Component/SeoComponentTest.php (100%) rename {Test/Case => tests/TestCase}/View/Helper/SeoHelperTest.php (100%) diff --git a/README.md b/README.md index 0b8e0f9..e357163 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,27 @@ I always need to add meta tags to my pages for SEO purposes and it was getting t I found that by containing all the functionality for SEO inside a component it makes it easier to manage. +# Requirements +* CakePHP 3 +* PHP 5.4.16+ + # Installation -## Git -Clone the repo into your `app/Plugin` folder. `git clone https://github.com/davidyell/CakePHP-Seo.git app/Plugin/Seo` -## Composer [https://packagist.org/packages/davidyell/seo](https://packagist.org/packages/davidyell/seo) +```bash +composer require 'davidyell/seo:dev-master' +``` + # Setup -Firstly you will need to load the plugin in your `app/Config/bootstrap.php`. -`CakePlugin::load('Seo');` +Firstly you will need to load the plugin in your `/config/bootstrap.php`. +```php +Plugin::load('Seo'); +``` Then you will need to attach it to the controller you want it to run on. I tend to attach it to my `AppController`. ```php -// app/Controller/AppController.php +// src/Controller/AppController.php public $components = [ 'Seo.Seo' => [ 'defaults' => [ diff --git a/composer.json b/composer.json index b92682a..9177bc4 100644 --- a/composer.json +++ b/composer.json @@ -9,11 +9,13 @@ "email": "neon1024@gmail.com" } ], - "minimum-stability": "dev", "require": { - "composer/installers": "~1.0" + "php": ">=5.4.16", + "cakephp/cakephp": "~3.0" }, - "extra": { - "installer-name": "Seo" + "autoload": { + "psr-4": { + "Seo\\": "src" + } } } diff --git a/Controller/Component/SeoComponent.php b/src/Controller/Component/SeoComponent.php similarity index 72% rename from Controller/Component/SeoComponent.php rename to src/Controller/Component/SeoComponent.php index eebc42d..da66250 100644 --- a/Controller/Component/SeoComponent.php +++ b/src/Controller/Component/SeoComponent.php @@ -1,7 +1,9 @@ */ -class SeoComponent extends Component implements CakeEventListener { +class SeoComponent extends Component implements EventListenerInterface { -/** - * Store component settings - * - * @var array - */ - public $settings = [ + /** + * Store component settings + * + * @var array + */ + protected $_defaultConfig = [ 'viewVar' => 'content', // Name of the view variable being used in views 'model' => 'Content', // Model containing the fields 'fields' => [ @@ -31,39 +33,27 @@ class SeoComponent extends Component implements CakeEventListener { 'keywords' => 'my, website, is, totally, awesome' ] ]; - -/** - * Merge component settings - * - * @param ComponentCollection $collection The component collection - * @param array $settings Array of component settings - */ - public function __construct(ComponentCollection $collection, $settings = array()) { - $settings = array_merge($this->settings, $settings); - - parent::__construct($collection, $settings); - } - -/** - * Setup the component - * Called after the Controller::beforeFilter() and before the controller action - * - * @param Controller $controller The controller instance - * @return void - */ - public function startup(Controller $controller) { - parent::startup($controller); + + /** + * Create the class + * + * @param array $config The component configuration array + * @return void + */ + public function initialize(array $config) + { if (!in_array($controller->request->prefix, $this->settings['noSeoPrefix'])) { $controller->getEventManager()->attach($this); } } -/** - * List of callable functions which are attached to system events - * - * @return array - */ - public function implementedEvents() { + /** + * List of callable functions which are attached to system events + * + * @return array + */ + public function implementedEvents() + { return array( 'View.beforeLayout' => 'writeSeo' ); diff --git a/View/Helper/SeoHelper.php b/src/View/Helper/SeoHelper.php similarity index 65% rename from View/Helper/SeoHelper.php rename to src/View/Helper/SeoHelper.php index 361ebbc..ac5d651 100644 --- a/View/Helper/SeoHelper.php +++ b/src/View/Helper/SeoHelper.php @@ -1,30 +1,32 @@ */ -class SeoHelper extends AppHelper { +class SeoHelper extends Helper { -/** - * Keep a list of all the controllers which generate paginated lists of items - * - * @var array - */ + /** + * Keep a list of all the controllers which generate paginated lists of items + * + * @var array + */ public $paginatedControllers = array(); -/** - * When using a paginated set of pages a link tag is used to show which pages - * are previous and next in the paginated series - * - * @param string $controller The name of the controller - * @return string - */ - public function pagination($controller) { + /** + * When using a paginated set of pages a link tag is used to show which pages + * are previous and next in the paginated series + * + * @param string $controller The name of the controller + * @return string + */ + public function pagination($controller) + { if (in_array($controller, $this->paginatedControllers)) { $className = Inflector::classify($controller); @@ -44,14 +46,15 @@ public function pagination($controller) { } } -/** - * Output a canonical tag for content with multiple pages or other dynamic data - * - * @param string $controller The name of the controller - * @param string $action The name of the action - * @return string - */ - public function canonical($controller, $action) { + /** + * Output a canonical tag for content with multiple pages or other dynamic data + * + * @param string $controller The name of the controller + * @param string $action The name of the action + * @return string + */ + public function canonical($controller, $action) + { $url = preg_replace("/page:[0-9]+/", '', $this->here); if (isset($this->request->params['sort'])) { diff --git a/Test/Case/AllSeoTest.php b/tests/TestCase/AllSeoTest.php similarity index 100% rename from Test/Case/AllSeoTest.php rename to tests/TestCase/AllSeoTest.php diff --git a/Test/Case/Controller/Component/SeoComponentTest.php b/tests/TestCase/Controller/Component/SeoComponentTest.php similarity index 100% rename from Test/Case/Controller/Component/SeoComponentTest.php rename to tests/TestCase/Controller/Component/SeoComponentTest.php diff --git a/Test/Case/View/Helper/SeoHelperTest.php b/tests/TestCase/View/Helper/SeoHelperTest.php similarity index 100% rename from Test/Case/View/Helper/SeoHelperTest.php rename to tests/TestCase/View/Helper/SeoHelperTest.php From eeb8540ec73417940e1e38c07281109c34e199d8 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 09:58:20 +0100 Subject: [PATCH 02/24] PHPCS fixes, added dev dependancies --- .gitignore | 2 + composer.json | 4 + composer.lock | 1404 +++++++++++++++++++++ src/Controller/Component/SeoComponent.php | 168 +-- src/View/Helper/SeoHelper.php | 107 +- 5 files changed, 1548 insertions(+), 137 deletions(-) create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index 1ffd740..8ea2256 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ nbproject +.idea +vendor diff --git a/composer.json b/composer.json index 9177bc4..e7eacb2 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,10 @@ "php": ">=5.4.16", "cakephp/cakephp": "~3.0" }, + "require-dev": { + "phpunit/phpunit": "*", + "cakephp/cakephp-codesniffer": "~2.0" + }, "autoload": { "psr-4": { "Seo\\": "src" diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..58d8529 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1404 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "3c8d7984bc05f7d7462a3fcadd8da2ad", + "packages": [ + { + "name": "aura/installer-default", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/auraphp/installer-default.git", + "reference": "52f8de3670cc1ef45a916f40f732937436d028c8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/installer-default/zipball/52f8de3670cc1ef45a916f40f732937436d028c8", + "reference": "52f8de3670cc1ef45a916f40f732937436d028c8", + "shasum": "" + }, + "type": "composer-installer", + "extra": { + "class": "Aura\\Composer\\DefaultInstaller" + }, + "autoload": { + "psr-0": { + "Aura\\Composer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Paul M. Jones", + "email": "pmjones88@gmail.com", + "homepage": "http://paul-m-jones.com" + } + ], + "description": "Installs Aura packages using the Composer defaults.", + "keywords": [ + "aura", + "installer" + ], + "time": "2012-11-26 21:35:57" + }, + { + "name": "aura/intl", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/auraphp/Aura.Intl.git", + "reference": "c5fe620167550ad6fa77dd3570fba2efc77a2a21" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/Aura.Intl/zipball/c5fe620167550ad6fa77dd3570fba2efc77a2a21", + "reference": "c5fe620167550ad6fa77dd3570fba2efc77a2a21", + "shasum": "" + }, + "require": { + "aura/installer-default": "1.0.*", + "php": ">=5.4.0" + }, + "type": "aura-package", + "extra": { + "aura": { + "type": "library", + "config": { + "common": "Aura\\Intl\\_Config\\Common" + } + }, + "branch-alias": { + "dev-develop": "1.1.x-dev" + } + }, + "autoload": { + "psr-0": { + "Aura\\Intl": "src/" + }, + "psr-4": { + "Aura\\Intl\\_Config\\": "config/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Paul M. Jones", + "email": "pmjones88@gmail.com", + "homepage": "http://paul-m-jones.com" + }, + { + "name": "Aura.Intl Contributors", + "homepage": "https://github.com/auraphp/Aura.Intl/contributors" + }, + { + "name": "Pascal Borreli", + "email": "pascal@borreli.com" + }, + { + "name": "Mapthegod", + "email": "mapthegod@gmail.com" + }, + { + "name": "Jose Lorenzo Rodriguez", + "email": "jose.zap@gmail.com" + } + ], + "description": "The Aura.Intl package provides internationalization (I18N) tools, specifically\npackage-oriented per-locale message translation.", + "homepage": "http://auraphp.com/Aura.Intl", + "keywords": [ + "g11n", + "globalization", + "i18n", + "internationalization", + "intl", + "l10n", + "localization" + ], + "time": "2014-08-24 00:00:00" + }, + { + "name": "cakephp/cakephp", + "version": "3.0.8", + "source": { + "type": "git", + "url": "https://github.com/cakephp/cakephp.git", + "reference": "29ca3d120c25d554ad5143adffdab0f76bc6c9b9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cakephp/cakephp/zipball/29ca3d120c25d554ad5143adffdab0f76bc6c9b9", + "reference": "29ca3d120c25d554ad5143adffdab0f76bc6c9b9", + "shasum": "" + }, + "require": { + "aura/intl": "1.1.*", + "ext-intl": "*", + "ext-mbstring": "*", + "ircmaxell/password-compat": "1.0.*", + "nesbot/carbon": "1.13.*", + "php": ">=5.4.16", + "psr/log": "1.0" + }, + "replace": { + "cakephp/cache": "self.version", + "cakephp/collection": "self.version", + "cakephp/core": "self.version", + "cakephp/database": "self.version", + "cakephp/datasource": "self.version", + "cakephp/event": "self.version", + "cakephp/filesystem": "self.version", + "cakephp/i18n": "self.version", + "cakephp/log": "self.version", + "cakephp/orm": "self.version", + "cakephp/utility": "self.version", + "cakephp/validation": "self.version" + }, + "require-dev": { + "cakephp/cakephp-codesniffer": "dev-master", + "phpunit/phpunit": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Cake\\": "src" + }, + "files": [ + "src/Core/functions.php", + "src/Collection/functions.php", + "src/I18n/functions.php", + "src/Utility/bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "CakePHP Community", + "homepage": "https://github.com/cakephp/cakephp/graphs/contributors" + } + ], + "description": "The CakePHP framework", + "homepage": "http://cakephp.org", + "keywords": [ + "framework" + ], + "time": "2015-06-28 17:00:48" + }, + { + "name": "ircmaxell/password-compat", + "version": "v1.0.4", + "source": { + "type": "git", + "url": "https://github.com/ircmaxell/password_compat.git", + "reference": "5c5cde8822a69545767f7c7f3058cb15ff84614c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ircmaxell/password_compat/zipball/5c5cde8822a69545767f7c7f3058cb15ff84614c", + "reference": "5c5cde8822a69545767f7c7f3058cb15ff84614c", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "type": "library", + "autoload": { + "files": [ + "lib/password.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anthony Ferrara", + "email": "ircmaxell@php.net", + "homepage": "http://blog.ircmaxell.com" + } + ], + "description": "A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash", + "homepage": "https://github.com/ircmaxell/password_compat", + "keywords": [ + "hashing", + "password" + ], + "time": "2014-11-20 16:49:30" + }, + { + "name": "nesbot/carbon", + "version": "1.13.0", + "source": { + "type": "git", + "url": "https://github.com/briannesbitt/Carbon.git", + "reference": "5cb6e71055f7b0b57956b73d324cc4de31278f42" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/5cb6e71055f7b0b57956b73d324cc4de31278f42", + "reference": "5cb6e71055f7b0b57956b73d324cc4de31278f42", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Carbon": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + } + ], + "description": "A simple API extension for DateTime.", + "homepage": "https://github.com/briannesbitt/Carbon", + "keywords": [ + "date", + "datetime", + "time" + ], + "time": "2014-09-26 02:52:02" + }, + { + "name": "psr/log", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-0": { + "Psr\\Log\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2012-12-21 11:40:51" + } + ], + "packages-dev": [ + { + "name": "cakephp/cakephp-codesniffer", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/cakephp/cakephp-codesniffer.git", + "reference": "149af3ec5525151543892221eb2945bb54fa4069" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cakephp/cakephp-codesniffer/zipball/149af3ec5525151543892221eb2945bb54fa4069", + "reference": "149af3ec5525151543892221eb2945bb54fa4069", + "shasum": "" + }, + "require": { + "squizlabs/php_codesniffer": "2.*" + }, + "require-dev": { + "phpunit/phpunit": "4.1.*" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "CakePHP Community", + "homepage": "https://github.com/cakephp/cakephp-codesniffer/graphs/contributors" + } + ], + "description": "CakePHP CodeSniffer Standards", + "homepage": "http://cakephp.org", + "keywords": [ + "codesniffer", + "framework" + ], + "time": "2015-03-17 01:11:58" + }, + { + "name": "doctrine/instantiator", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-06-14 21:17:01" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "phpDocumentor": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "mike.vanriel@naenius.com" + } + ], + "time": "2015-02-03 12:10:50" + }, + { + "name": "phpspec/prophecy", + "version": "v1.4.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2015-04-27 22:15:08" + }, + { + "name": "phpunit/php-code-coverage", + "version": "2.1.7", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "07e27765596d72c378a6103e80da5d84e802f1e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/07e27765596d72c378a6103e80da5d84e802f1e4", + "reference": "07e27765596d72c378a6103e80da5d84e802f1e4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2015-06-30 06:52:35" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2015-04-02 05:19:05" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21 13:50:34" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/83fe1bdc5d47658b727595c14da140da92b3d66d", + "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2015-06-13 07:35:30" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/7a9b0969488c3c54fd62b4d504b3ec758fd005d9", + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2015-06-19 03:43:16" + }, + { + "name": "phpunit/phpunit", + "version": "4.7.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "0ebabb4cda7d066be8391dfdbaf57fe70ac9a99b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0ebabb4cda7d066be8391dfdbaf57fe70ac9a99b", + "reference": "0ebabb4cda7d066be8391dfdbaf57fe70ac9a99b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpspec/prophecy": "~1.3,>=1.3.1", + "phpunit/php-code-coverage": "~2.1", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": ">=1.0.6", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.2", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.7.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-06-30 06:53:57" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/92408bb1968a81b3217a6fdf6c1a198da83caa35", + "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.2", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2015-06-11 15:55:48" + }, + { + "name": "sebastian/comparator", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2015-01-29 16:28:08" + }, + { + "name": "sebastian/diff", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-02-22 15:13:53" + }, + { + "name": "sebastian/environment", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2015-01-01 10:01:08" + }, + { + "name": "sebastian/exporter", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "84839970d05254c73cde183a721c7af13aede943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", + "reference": "84839970d05254c73cde183a721c7af13aede943", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2015-01-27 07:23:06" + }, + { + "name": "sebastian/global-state", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2014-10-06 09:23:50" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-01-24 09:48:32" + }, + { + "name": "sebastian/version", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-06-21 13:59:46" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "2.3.3", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "c1a26c729508f73560c1a4f767f60b8ab6b4a666" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/c1a26c729508f73560c1a4f767f60b8ab6b4a666", + "reference": "c1a26c729508f73560c1a4f767f60b8ab6b4a666", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.1.2" + }, + "bin": [ + "scripts/phpcs", + "scripts/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "CodeSniffer.php", + "CodeSniffer/CLI.php", + "CodeSniffer/Exception.php", + "CodeSniffer/File.php", + "CodeSniffer/Fixer.php", + "CodeSniffer/Report.php", + "CodeSniffer/Reporting.php", + "CodeSniffer/Sniff.php", + "CodeSniffer/Tokens.php", + "CodeSniffer/Reports/", + "CodeSniffer/Tokenizers/", + "CodeSniffer/DocGenerators/", + "CodeSniffer/Standards/AbstractPatternSniff.php", + "CodeSniffer/Standards/AbstractScopeSniff.php", + "CodeSniffer/Standards/AbstractVariableSniff.php", + "CodeSniffer/Standards/IncorrectPatternException.php", + "CodeSniffer/Standards/Generic/Sniffs/", + "CodeSniffer/Standards/MySource/Sniffs/", + "CodeSniffer/Standards/PEAR/Sniffs/", + "CodeSniffer/Standards/PSR1/Sniffs/", + "CodeSniffer/Standards/PSR2/Sniffs/", + "CodeSniffer/Standards/Squiz/Sniffs/", + "CodeSniffer/Standards/Zend/Sniffs/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2015-06-24 03:16:23" + }, + { + "name": "symfony/yaml", + "version": "v2.7.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/9808e75c609a14f6db02f70fccf4ca4aab53c160", + "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "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 Yaml Component", + "homepage": "https://symfony.com", + "time": "2015-06-10 15:30:22" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.4.16" + }, + "platform-dev": [] +} diff --git a/src/Controller/Component/SeoComponent.php b/src/Controller/Component/SeoComponent.php index da66250..a403a6b 100644 --- a/src/Controller/Component/SeoComponent.php +++ b/src/Controller/Component/SeoComponent.php @@ -11,93 +11,95 @@ * @author David Yell */ -class SeoComponent extends Component implements EventListenerInterface { +class SeoComponent extends Component implements EventListenerInterface +{ - /** - * Store component settings - * - * @var array - */ - protected $_defaultConfig = [ - 'viewVar' => 'content', // Name of the view variable being used in views - 'model' => 'Content', // Model containing the fields - 'fields' => [ - 'title' => 'seo_title', - 'description' => 'seo_description', - 'keywords' => 'seo_keywords' - ], - 'noSeoPrefix' => ['admin'], // Any routing prefixes you do not SEO - 'defaults' => [ - 'title' => 'The homepage | My Awesome Website', - 'description' => 'Find out about how awesome I am by reading my website', - 'keywords' => 'my, website, is, totally, awesome' - ] - ]; - - /** - * Create the class - * - * @param array $config The component configuration array - * @return void - */ - public function initialize(array $config) - { - if (!in_array($controller->request->prefix, $this->settings['noSeoPrefix'])) { - $controller->getEventManager()->attach($this); - } - } + /** + * Store component settings + * + * @var array + */ + protected $_defaultConfig = [ + 'viewVar' => 'content', // Name of the view variable being used in views + 'model' => 'Content', // Model containing the fields + 'fields' => [ + 'title' => 'seo_title', + 'description' => 'seo_description', + 'keywords' => 'seo_keywords' + ], + 'noSeoPrefix' => ['admin'], // Any routing prefixes you do not SEO + 'defaults' => [ + 'title' => 'The homepage | My Awesome Website', + 'description' => 'Find out about how awesome I am by reading my website', + 'keywords' => 'my, website, is, totally, awesome' + ] + ]; + + /** + * Create the class + * + * @param array $config The component configuration array + * @return void + */ + public function initialize(array $config) + { + if (!in_array($controller->request->prefix, $this->settings['noSeoPrefix'])) { + $controller->getEventManager()->attach($this); + } + } - /** - * List of callable functions which are attached to system events - * - * @return array - */ - public function implementedEvents() - { - return array( - 'View.beforeLayout' => 'writeSeo' - ); - } + /** + * List of callable functions which are attached to system events + * + * @return array + */ + public function implementedEvents() + { + return [ + 'View.beforeLayout' => 'writeSeo' + ]; + } -/** - * Inject the seo data into the view - * - * @param CakeEvent $event Event instance - * @return void - */ - public function writeSeo(CakeEvent $event) { - if (!empty($event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['title']])) { - $seoTitle = $event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['title']]; - $event->subject()->viewVars['title_for_layout'] = $seoTitle; - } + /** + * Inject the seo data into the view + * + * @param CakeEvent $event Event instance + * @return void + */ + public function writeSeo(CakeEvent $event) + { + if (!empty($event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['title']])) { + $seoTitle = $event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['title']]; + $event->subject()->viewVars['title_for_layout'] = $seoTitle; + } - if (!empty($event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['description']])) { - $seoDescription = $event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['description']]; - $event->subject()->Html->meta( - 'description', - $seoDescription, - ['block' => 'meta'] - ); - } + if (!empty($event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['description']])) { + $seoDescription = $event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['description']]; + $event->subject()->Html->meta( + 'description', + $seoDescription, + ['block' => 'meta'] + ); + } - if (!empty($event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['keywords']])) { - $seoKeywords = $event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['keywords']]; - $event->subject()->Html->meta( - 'keywords', - $seoKeywords, - ['block' => 'meta'] - ); - } + if (!empty($event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['keywords']])) { + $seoKeywords = $event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['keywords']]; + $event->subject()->Html->meta( + 'keywords', + $seoKeywords, + ['block' => 'meta'] + ); + } - // If no values can be found, fall back to the defaults - if (empty($seoTitle)) { - $event->subject()->viewVars['title_for_layout'] = $this->settings['defaults']['title']; - } - if (empty($seoDescription)) { - $event->subject()->Html->meta('description', $this->settings['defaults']['description'], ['block' => 'meta']); - } - if (empty($seoKeywords)) { - $event->subject()->Html->meta('keywords', $this->settings['defaults']['keywords'], ['block' => 'meta']); - } - } + // If no values can be found, fall back to the defaults + if (empty($seoTitle)) { + $event->subject()->viewVars['title_for_layout'] = $this->settings['defaults']['title']; + } + if (empty($seoDescription)) { + $event->subject()->Html->meta('description', $this->settings['defaults']['description'], ['block' => 'meta']); + } + if (empty($seoKeywords)) { + $event->subject()->Html->meta('keywords', $this->settings['defaults']['keywords'], ['block' => 'meta']); + } + } } diff --git a/src/View/Helper/SeoHelper.php b/src/View/Helper/SeoHelper.php index ac5d651..7c97cf9 100644 --- a/src/View/Helper/SeoHelper.php +++ b/src/View/Helper/SeoHelper.php @@ -9,64 +9,63 @@ * * @author David Yell */ -class SeoHelper extends Helper { +class SeoHelper extends Helper +{ - /** - * Keep a list of all the controllers which generate paginated lists of items - * - * @var array - */ - public $paginatedControllers = array(); + /** + * Keep a list of all the controllers which generate paginated lists of items + * + * @var array + */ + public $paginatedControllers = array(); - /** - * When using a paginated set of pages a link tag is used to show which pages - * are previous and next in the paginated series - * - * @param string $controller The name of the controller - * @return string - */ - public function pagination($controller) - { - if (in_array($controller, $this->paginatedControllers)) { + /** + * When using a paginated set of pages a link tag is used to show which pages + * are previous and next in the paginated series + * + * @param string $controller The name of the controller + * @return string + */ + public function pagination($controller) + { + if (in_array($controller, $this->paginatedControllers)) { + $className = Inflector::classify($controller); - $className = Inflector::classify($controller); + if (isset($this->request->params['paging'][$className])) { + $prev = " $controller, 'action' => 'index', 'page' => $this->request->params['paging'][$className]['page'] - 1)) . "'>"; + $next = " $controller, 'action' => 'index', 'page' => $this->request->params['paging'][$className]['page'] + 1)) . "'>"; - if (isset($this->request->params['paging'][$className])) { - $prev = " $controller, 'action' => 'index', 'page' => $this->request->params['paging'][$className]['page'] - 1)) . "'>"; - $next = " $controller, 'action' => 'index', 'page' => $this->request->params['paging'][$className]['page'] + 1)) . "'>"; + if ($this->request->params['paging'][$className]['prevPage'] === false) { // page 1 + return $next; + } elseif ($this->request->params['paging'][$className]['nextPage'] === false) { + return $prev; + } else { + return $next . $prev; + } + } + } + } - if ($this->request->params['paging'][$className]['prevPage'] === false) { // page 1 - return $next; - } elseif ($this->request->params['paging'][$className]['nextPage'] === false) { - return $prev; - } else { - return $next . $prev; - } - } - } - } + /** + * Output a canonical tag for content with multiple pages or other dynamic data + * + * @param string $controller The name of the controller + * @param string $action The name of the action + * @return string + */ + public function canonical($controller, $action) + { + $url = preg_replace("/page:[0-9]+/", '', $this->here); - /** - * Output a canonical tag for content with multiple pages or other dynamic data - * - * @param string $controller The name of the controller - * @param string $action The name of the action - * @return string - */ - public function canonical($controller, $action) - { - $url = preg_replace("/page:[0-9]+/", '', $this->here); + if (isset($this->request->params['sort'])) { + $url = str_replace($this->request->params['sort'], '', $url); + } + if (isset($this->request->params['dir'])) { + $url = str_replace($this->request->params['dir'], '', $url); + } + $url = rtrim($url, '/'); + $url = Router::fullbaseUrl() . $url; - if (isset($this->request->params['sort'])) { - $url = str_replace($this->request->params['sort'], '', $url); - } - if (isset($this->request->params['dir'])) { - $url = str_replace($this->request->params['dir'], '', $url); - } - $url = rtrim($url, '/'); - $url = Router::fullbaseUrl() . $url; - - return ""; - } - -} \ No newline at end of file + return ""; + } +} From 8baa823049983395754dd361bbc1d8a00380f265 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 10:21:02 +0100 Subject: [PATCH 03/24] Working on the tests --- composer.json | 7 ++++- src/Controller/Component/SeoComponent.php | 22 +++++++++++-- tests/TestCase/AllSeoTest.php | 22 ------------- .../Controller/Component/SeoComponentTest.php | 31 ++++++++++++------- 4 files changed, 44 insertions(+), 38 deletions(-) delete mode 100644 tests/TestCase/AllSeoTest.php diff --git a/composer.json b/composer.json index e7eacb2..6475602 100644 --- a/composer.json +++ b/composer.json @@ -21,5 +21,10 @@ "psr-4": { "Seo\\": "src" } - } + }, + "autoload-dev": { + "psr-4": { + "Seo\\Tests\\": "tests" + } + }, } diff --git a/src/Controller/Component/SeoComponent.php b/src/Controller/Component/SeoComponent.php index a403a6b..3361f52 100644 --- a/src/Controller/Component/SeoComponent.php +++ b/src/Controller/Component/SeoComponent.php @@ -4,6 +4,8 @@ use Cake\Controller\Component; use Cake\Event\EventListenerInterface; +use Cake\Controller\ComponentRegistry; +use Cake\Event\Event; /** * Component to find and load seo data and inject it into the view @@ -35,6 +37,18 @@ class SeoComponent extends Component implements EventListenerInterface ] ]; + /** + * Get the controller from the Registry during construction + * + * @param ComponentRegistry $registry The component registry + * @param array $config Component configuration array + */ + public function __construct(ComponentRegistry $registry, array $config = []) + { + parent::__construct($registry, $config); + $this->_controller = $registry->getController(); + } + /** * Create the class * @@ -43,7 +57,9 @@ class SeoComponent extends Component implements EventListenerInterface */ public function initialize(array $config) { - if (!in_array($controller->request->prefix, $this->settings['noSeoPrefix'])) { + var_dump($this->_controller); + + if (!in_array($this->_controller->request->prefix, $this->settings['noSeoPrefix'])) { $controller->getEventManager()->attach($this); } } @@ -63,10 +79,10 @@ public function implementedEvents() /** * Inject the seo data into the view * - * @param CakeEvent $event Event instance + * @param \Cake\Event\Event $event Event instance * @return void */ - public function writeSeo(CakeEvent $event) + public function writeSeo(Event $event) { if (!empty($event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['title']])) { $seoTitle = $event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['title']]; diff --git a/tests/TestCase/AllSeoTest.php b/tests/TestCase/AllSeoTest.php deleted file mode 100644 index edde589..0000000 --- a/tests/TestCase/AllSeoTest.php +++ /dev/null @@ -1,22 +0,0 @@ - - * @when 09/03/15 - * - */ -App::uses('CakePlugin', 'Core'); - -class AllSeoTest extends CakeTestSuite { - - public static function suite() { - $suite = new CakeTestSuite('All CakePHP-Seo plugin tests'); - $suite->addTestDirectory(CakePlugin::path('Seo') . 'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component'); - $suite->addTestDirectory(CakePlugin::path('Seo') . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper'); - return $suite; - } - -} \ No newline at end of file diff --git a/tests/TestCase/Controller/Component/SeoComponentTest.php b/tests/TestCase/Controller/Component/SeoComponentTest.php index 811256e..d4d1cbd 100644 --- a/tests/TestCase/Controller/Component/SeoComponentTest.php +++ b/tests/TestCase/Controller/Component/SeoComponentTest.php @@ -1,5 +1,7 @@ ComponentCollection = new ComponentCollection(); + public function setUp() + { $this->Controller = new Controller(); + $this->ComponentRegistry = new ComponentRegistry($this->Controller); } - public function testWriteSeo() { - $component = new SeoComponent($this->ComponentCollection); + public function testWriteSeo() + { + $component = new SeoComponent($this->ComponentRegistry); $view = $this->getMockBuilder('View') ->setConstructorArgs([$this->Controller]) @@ -39,7 +45,7 @@ public function testWriteSeo() { ] ]); - $event = new CakeEvent('view.beforeLayout', $view, []); + $event = new Event('view.beforeLayout', $view, []); $result = $component->writeSeo($event); @@ -47,8 +53,9 @@ public function testWriteSeo() { $this->assertEqual($title, 'Test SEO title'); } - public function testWriteSeoEmptyConfig() { - $component = new SeoComponent($this->ComponentCollection); + public function testWriteSeoEmptyConfig() + { + $component = new SeoComponent($this->ComponentRegistry); $view = $this->getMockBuilder('View') ->setConstructorArgs([$this->Controller]) From 74ce4112009d2a8026ce33446db9726212948650 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 10:29:16 +0100 Subject: [PATCH 04/24] Fixed json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6475602..e9485f4 100644 --- a/composer.json +++ b/composer.json @@ -26,5 +26,5 @@ "psr-4": { "Seo\\Tests\\": "tests" } - }, + } } From 861a405c3736b2bdcd589cdecc946ab036a353c4 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 11:43:03 +0100 Subject: [PATCH 05/24] Updated the component and helper and fixed the tests --- src/Controller/Component/SeoComponent.php | 46 ++++---- src/View/Helper/SeoHelper.php | 25 ++-- .../Controller/Component/SeoComponentTest.php | 88 +++++++------- tests/TestCase/View/Helper/SeoHelperTest.php | 109 ++++++++---------- 4 files changed, 121 insertions(+), 147 deletions(-) diff --git a/src/Controller/Component/SeoComponent.php b/src/Controller/Component/SeoComponent.php index 3361f52..6896999 100644 --- a/src/Controller/Component/SeoComponent.php +++ b/src/Controller/Component/SeoComponent.php @@ -15,6 +15,12 @@ class SeoComponent extends Component implements EventListenerInterface { + /** + * The controller instance + * + * @var \Cake\Controller\Controller + */ + protected $_controller; /** * Store component settings @@ -37,18 +43,6 @@ class SeoComponent extends Component implements EventListenerInterface ] ]; - /** - * Get the controller from the Registry during construction - * - * @param ComponentRegistry $registry The component registry - * @param array $config Component configuration array - */ - public function __construct(ComponentRegistry $registry, array $config = []) - { - parent::__construct($registry, $config); - $this->_controller = $registry->getController(); - } - /** * Create the class * @@ -57,10 +51,10 @@ public function __construct(ComponentRegistry $registry, array $config = []) */ public function initialize(array $config) { - var_dump($this->_controller); - - if (!in_array($this->_controller->request->prefix, $this->settings['noSeoPrefix'])) { - $controller->getEventManager()->attach($this); + $this->_controller = $this->_registry->getController(); + + if (!in_array($this->_controller->request->prefix, $this->config('noSeoPrefix'))) { + $this->_controller->eventManager()->on($this); } } @@ -84,13 +78,13 @@ public function implementedEvents() */ public function writeSeo(Event $event) { - if (!empty($event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['title']])) { - $seoTitle = $event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['title']]; - $event->subject()->viewVars['title_for_layout'] = $seoTitle; + if (!empty($event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.title')])) { + $seoTitle = $event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.title')]; + $event->subject()->viewVars['title'] = $seoTitle; } - if (!empty($event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['description']])) { - $seoDescription = $event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['description']]; + if (!empty($event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.description')])) { + $seoDescription = $event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.description')]; $event->subject()->Html->meta( 'description', $seoDescription, @@ -98,8 +92,8 @@ public function writeSeo(Event $event) ); } - if (!empty($event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['keywords']])) { - $seoKeywords = $event->subject()->viewVars[$this->settings['viewVar']][$this->settings['model']][$this->settings['fields']['keywords']]; + if (!empty($event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.keywords')])) { + $seoKeywords = $event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.keywords')]; $event->subject()->Html->meta( 'keywords', $seoKeywords, @@ -109,13 +103,13 @@ public function writeSeo(Event $event) // If no values can be found, fall back to the defaults if (empty($seoTitle)) { - $event->subject()->viewVars['title_for_layout'] = $this->settings['defaults']['title']; + $event->subject()->viewVars['title'] = $this->config('defaults.title'); } if (empty($seoDescription)) { - $event->subject()->Html->meta('description', $this->settings['defaults']['description'], ['block' => 'meta']); + $event->subject()->Html->meta('description', $this->config('defaults.description'), ['block' => 'meta']); } if (empty($seoKeywords)) { - $event->subject()->Html->meta('keywords', $this->settings['defaults']['keywords'], ['block' => 'meta']); + $event->subject()->Html->meta('keywords', $this->config('defaults.keywords'), ['block' => 'meta']); } } } diff --git a/src/View/Helper/SeoHelper.php b/src/View/Helper/SeoHelper.php index 7c97cf9..6e9be5f 100644 --- a/src/View/Helper/SeoHelper.php +++ b/src/View/Helper/SeoHelper.php @@ -2,6 +2,9 @@ namespace Seo\View\Helper; +use Cake\Core\Configure; +use Cake\Routing\Router; +use Cake\Utility\Inflector; use Cake\View\Helper; /** @@ -17,7 +20,7 @@ class SeoHelper extends Helper * * @var array */ - public $paginatedControllers = array(); + public $paginatedControllers = []; /** * When using a paginated set of pages a link tag is used to show which pages @@ -32,8 +35,8 @@ public function pagination($controller) $className = Inflector::classify($controller); if (isset($this->request->params['paging'][$className])) { - $prev = " $controller, 'action' => 'index', 'page' => $this->request->params['paging'][$className]['page'] - 1)) . "'>"; - $next = " $controller, 'action' => 'index', 'page' => $this->request->params['paging'][$className]['page'] + 1)) . "'>"; + $prev = " $controller, 'action' => 'index', 'page' => $this->request->params['paging'][$className]['page'] - 1]) . "'>"; + $next = " $controller, 'action' => 'index', 'page' => $this->request->params['paging'][$className]['page'] + 1]) . "'>"; if ($this->request->params['paging'][$className]['prevPage'] === false) { // page 1 return $next; @@ -49,22 +52,12 @@ public function pagination($controller) /** * Output a canonical tag for content with multiple pages or other dynamic data * - * @param string $controller The name of the controller - * @param string $action The name of the action * @return string */ - public function canonical($controller, $action) + public function canonical() { - $url = preg_replace("/page:[0-9]+/", '', $this->here); - - if (isset($this->request->params['sort'])) { - $url = str_replace($this->request->params['sort'], '', $url); - } - if (isset($this->request->params['dir'])) { - $url = str_replace($this->request->params['dir'], '', $url); - } - $url = rtrim($url, '/'); - $url = Router::fullbaseUrl() . $url; + $url = parse_url($this->request->here); + $url = Router::fullbaseUrl() . $url['path']; return ""; } diff --git a/tests/TestCase/Controller/Component/SeoComponentTest.php b/tests/TestCase/Controller/Component/SeoComponentTest.php index d4d1cbd..0fb25c5 100644 --- a/tests/TestCase/Controller/Component/SeoComponentTest.php +++ b/tests/TestCase/Controller/Component/SeoComponentTest.php @@ -5,71 +5,67 @@ /** * @category Seo * @package SeoComponentTest.php - * + * * @author David Yell * @when 09/03/15 * */ -use Seo\Controller\Component\SeoComponent; use Cake\Controller\ComponentRegistry; -use Cake\View\View; use Cake\Controller\Controller; use Cake\Event\Event; +use Seo\Controller\Component\SeoComponent; -class SeoComponentTest extends \PHPUnit_Framework_TestCase { - - public function setUp() - { - $this->Controller = new Controller(); - $this->ComponentRegistry = new ComponentRegistry($this->Controller); - } - - public function testWriteSeo() - { - $component = new SeoComponent($this->ComponentRegistry); +class SeoComponentTest extends \PHPUnit_Framework_TestCase +{ - $view = $this->getMockBuilder('View') - ->setConstructorArgs([$this->Controller]) - ->setMethods(['append']) - ->getMock(); + public function setUp() + { + $this->Controller = new Controller(); + $this->Controller->name = 'TestsController'; + $this->ComponentRegistry = new ComponentRegistry($this->Controller); + $this->Seo = new SeoComponent($this->ComponentRegistry); + } - $view->expects($this->exactly(2)) - ->method('append'); + public function testWriteSeo() + { + $view = $this->getMockBuilder('Cake\View\View') + ->setMethods(['append']) + ->getMock(); - $view->set('content', [ - 'Content' => [ - 'seo_title' => 'Test SEO title', - 'seo_description' => 'Test SEO description', - 'seo_keywords' => 'Test SEO keywords' - ] - ]); + $view->expects($this->exactly(2)) + ->method('append'); - $event = new Event('view.beforeLayout', $view, []); + $view->set('content', [ + 'Content' => [ + 'seo_title' => 'Test SEO title', + 'seo_description' => 'Test SEO description', + 'seo_keywords' => 'Test SEO keywords' + ] + ]); - $result = $component->writeSeo($event); + $event = new Event('view.beforeLayout', $view, []); - $title = $event->subject()->viewVars['title_for_layout']; - $this->assertEqual($title, 'Test SEO title'); - } + $this->Seo->writeSeo($event); - public function testWriteSeoEmptyConfig() - { - $component = new SeoComponent($this->ComponentRegistry); + $title = $event->subject()->viewVars['title']; + $this->assertEquals('Test SEO title', $title); + } - $view = $this->getMockBuilder('View') - ->setConstructorArgs([$this->Controller]) - ->setMethods(['append']) - ->getMock(); + public function testWriteSeoEmptyConfig() + { + $view = $this->getMockBuilder('Cake\View\View') + ->setMethods(['append']) + ->getMock(); - $view->expects($this->exactly(2)) - ->method('append'); + $view->expects($this->exactly(2)) + ->method('append'); - $event = new CakeEvent('view.beforeLayout', $view, []); + $event = new Event('view.beforeLayout', $view, []); - $result = $component->writeSeo($event); + $this->Seo->writeSeo($event); - $title = $event->subject()->viewVars['title_for_layout']; - $this->assertEqual($title, 'The homepage | My Awesome Website'); - } + $title = $event->subject()->viewVars['title']; + $this->assertEquals('The homepage | My Awesome Website', $title); + } } \ No newline at end of file diff --git a/tests/TestCase/View/Helper/SeoHelperTest.php b/tests/TestCase/View/Helper/SeoHelperTest.php index 6ef9cdb..ccbe534 100644 --- a/tests/TestCase/View/Helper/SeoHelperTest.php +++ b/tests/TestCase/View/Helper/SeoHelperTest.php @@ -1,5 +1,7 @@ true, 'nextPage' => true ]], - "" + "" ], [ ['Test' => [ @@ -31,7 +35,7 @@ public function paginationProvider() { 'prevPage' => false, 'nextPage' => true ]], - "" + "" ], [ ['Test' => [ @@ -39,94 +43,81 @@ public function paginationProvider() { 'prevPage' => true, 'nextPage' => false ]], - "" + "" ], ]; } -/** - * @param $pagingArray - * @param $expected - * @dataProvider paginationProvider - */ - public function testPagination($pagingArray, $expected) { - $this->Request = new CakeRequest(); + /** + * @param $pagingArray + * @param $expected + * @dataProvider paginationProvider + */ + public function testPagination($pagingArray, $expected) + { + $this->Request = new Request(); $this->Request->params['paging'] = $pagingArray; $this->Controller = new Controller($this->Request); $this->Controller->name = 'Tests'; - $this->View = new View($this->Controller); + $this->View = new View($this->Request); $helper = new SeoHelper($this->View); $helper->paginatedControllers = ['Tests']; $result = $helper->pagination($this->Controller->name); - $this->assertEqual($result, $expected); + $this->assertEquals($expected, $result); } - public function canonicalProvider() { + public function canonicalProvider() + { return [ [ - '/tests/index', - [], - "" + '/tests', + "" ], [ - '/tests/index/page:5', - [], - "" + '/tests?page=5', + "" ], [ - '/tests/index/page:5', - [ - 'sort' => 'id' - ], - "" + '/tests?sort=id&page=5', + "" ], [ - '/tests/index/page:5', - [ - 'dir' => 'desc' - ], - "" + '/tests?dir=desc&page=5', + "" ], [ - '/tests/index/page:5', - [ - 'sort' => 'id', - 'dir' => 'desc' - ], - "" - ], - [ - '/tests/index', - [ - 'sort' => 'id', - 'dir' => 'desc' - ], - "" + '/tests?sort=id&dir=desc', + "" ], + [ + '/tests?page=5&sort=id&dir=desc', + "" + ], ]; } -/** - * @param $paramsArray - * @param $expected - * @dataProvider canonicalProvider - */ - public function testCanonical($here, $paramsArray, $expected) { - $this->Request = new CakeRequest(); - $this->Request->params = $paramsArray; + /** + * @param $expected + * @dataProvider canonicalProvider + */ + public function testCanonical($here, $expected) + { + Configure::write('App.fullBaseUrl', 'http://localhost'); + + $this->Request = new Request(); $this->Request->here = $here; $this->Controller = new Controller($this->Request); $this->Controller->name = 'Tests'; - $this->View = new View($this->Controller); + $this->View = new View($this->Request); $helper = new SeoHelper($this->View); - $result = $helper->canonical('tests', 'index'); - $this->assertEqual($result, $expected); + $result = $helper->canonical('Tests', 'index'); + $this->assertEquals($expected, $result); } } \ No newline at end of file From 69165dbf16b8511d555c0c9c1f3c21e71202a671 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 11:46:00 +0100 Subject: [PATCH 06/24] Fix PHPCS --- src/Controller/Component/SeoComponent.php | 3 +- .../Controller/Component/SeoComponentTest.php | 2 +- tests/TestCase/View/Helper/SeoHelperTest.php | 158 +++++++++--------- 3 files changed, 82 insertions(+), 81 deletions(-) diff --git a/src/Controller/Component/SeoComponent.php b/src/Controller/Component/SeoComponent.php index 6896999..415a8ac 100644 --- a/src/Controller/Component/SeoComponent.php +++ b/src/Controller/Component/SeoComponent.php @@ -3,9 +3,8 @@ namespace Seo\Controller\Component; use Cake\Controller\Component; -use Cake\Event\EventListenerInterface; -use Cake\Controller\ComponentRegistry; use Cake\Event\Event; +use Cake\Event\EventListenerInterface; /** * Component to find and load seo data and inject it into the view diff --git a/tests/TestCase/Controller/Component/SeoComponentTest.php b/tests/TestCase/Controller/Component/SeoComponentTest.php index 0fb25c5..e413e1a 100644 --- a/tests/TestCase/Controller/Component/SeoComponentTest.php +++ b/tests/TestCase/Controller/Component/SeoComponentTest.php @@ -68,4 +68,4 @@ public function testWriteSeoEmptyConfig() $title = $event->subject()->viewVars['title']; $this->assertEquals('The homepage | My Awesome Website', $title); } -} \ No newline at end of file +} diff --git a/tests/TestCase/View/Helper/SeoHelperTest.php b/tests/TestCase/View/Helper/SeoHelperTest.php index ccbe534..37d3762 100644 --- a/tests/TestCase/View/Helper/SeoHelperTest.php +++ b/tests/TestCase/View/Helper/SeoHelperTest.php @@ -5,119 +5,121 @@ /** * @category Seo * @package SeoHelperTest.php - * + * * @author David Yell * @when 09/03/15 * */ +use Cake\Controller\Controller; use Cake\Core\Configure; use Cake\Network\Request; -use Cake\Controller\Controller; use Cake\View\View; use Seo\View\Helper\SeoHelper; -class SeoHelperTest extends \PHPUnit_Framework_TestCase { - - public function paginationProvider() { - return [ - [ - ['Test' => [ - 'page' => 5, - 'prevPage' => true, - 'nextPage' => true - ]], - "" - ], - [ - ['Test' => [ - 'page' => 1, - 'prevPage' => false, - 'nextPage' => true - ]], - "" - ], - [ - ['Test' => [ - 'page' => 6, - 'prevPage' => true, - 'nextPage' => false - ]], - "" - ], - ]; - } +class SeoHelperTest extends \PHPUnit_Framework_TestCase +{ + + public function paginationProvider() + { + return [ + [ + ['Test' => [ + 'page' => 5, + 'prevPage' => true, + 'nextPage' => true + ]], + "" + ], + [ + ['Test' => [ + 'page' => 1, + 'prevPage' => false, + 'nextPage' => true + ]], + "" + ], + [ + ['Test' => [ + 'page' => 6, + 'prevPage' => true, + 'nextPage' => false + ]], + "" + ], + ]; + } /** * @param $pagingArray * @param $expected * @dataProvider paginationProvider */ - public function testPagination($pagingArray, $expected) + public function testPagination($pagingArray, $expected) { - $this->Request = new Request(); - $this->Request->params['paging'] = $pagingArray; + $this->Request = new Request(); + $this->Request->params['paging'] = $pagingArray; - $this->Controller = new Controller($this->Request); - $this->Controller->name = 'Tests'; + $this->Controller = new Controller($this->Request); + $this->Controller->name = 'Tests'; - $this->View = new View($this->Request); + $this->View = new View($this->Request); - $helper = new SeoHelper($this->View); - $helper->paginatedControllers = ['Tests']; + $helper = new SeoHelper($this->View); + $helper->paginatedControllers = ['Tests']; - $result = $helper->pagination($this->Controller->name); - $this->assertEquals($expected, $result); - } + $result = $helper->pagination($this->Controller->name); + $this->assertEquals($expected, $result); + } - public function canonicalProvider() + public function canonicalProvider() { - return [ - [ - '/tests', - "" - ], - [ - '/tests?page=5', - "" - ], - [ - '/tests?sort=id&page=5', - "" - ], - [ - '/tests?dir=desc&page=5', - "" - ], - [ - '/tests?sort=id&dir=desc', - "" - ], + return [ + [ + '/tests', + "" + ], + [ + '/tests?page=5', + "" + ], + [ + '/tests?sort=id&page=5', + "" + ], + [ + '/tests?dir=desc&page=5', + "" + ], + [ + '/tests?sort=id&dir=desc', + "" + ], [ '/tests?page=5&sort=id&dir=desc', "" ], - ]; - } + ]; + } /** * @param $expected * @dataProvider canonicalProvider */ - public function testCanonical($here, $expected) + public function testCanonical($here, $expected) { Configure::write('App.fullBaseUrl', 'http://localhost'); - $this->Request = new Request(); - $this->Request->here = $here; + $this->Request = new Request(); + $this->Request->here = $here; - $this->Controller = new Controller($this->Request); - $this->Controller->name = 'Tests'; + $this->Controller = new Controller($this->Request); + $this->Controller->name = 'Tests'; - $this->View = new View($this->Request); + $this->View = new View($this->Request); - $helper = new SeoHelper($this->View); - $result = $helper->canonical('Tests', 'index'); - $this->assertEquals($expected, $result); - } -} \ No newline at end of file + $helper = new SeoHelper($this->View); + $result = $helper->canonical('Tests', 'index'); + $this->assertEquals($expected, $result); + } +} From 8a485c48d653c91a1b5ab9bb0a02e597cbe84074 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 11:46:42 +0100 Subject: [PATCH 07/24] Update .coveralls.yml Changed src folder --- .coveralls.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.coveralls.yml b/.coveralls.yml index 00f055f..e6c3bf6 100644 --- a/.coveralls.yml +++ b/.coveralls.yml @@ -1,3 +1,3 @@ -src_dir: Plugin/Seo +src_dir: vendor/davidyell/seo coverage_clover: build/logs/clover.xml -json_path: build/logs/coveralls-upload.json \ No newline at end of file +json_path: build/logs/coveralls-upload.json From 003e7db37be22977c625f80c557e4d70b99254c7 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 11:48:05 +0100 Subject: [PATCH 08/24] Update .travis.yml Updated Travis to test again Cake 3 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b65fbbb..947ec92 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,14 +9,14 @@ env: - PLUGIN_NAME=Seo matrix: - - CAKE_VERSION=2.5 - - CAKE_VERSION=2.6 + - CAKE_VERSION=3.0.8 + - CAKE_VERSION=3.0.0 matrix: include: - php: 5.5 env: - - CAKE_VERSION=2.6 + - CAKE_VERSION=3.0.8 - COVERALLS=1 - php: 5.4 env: From deb63797dc971d79b6f06da31ecda12999c1cf53 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 11:49:02 +0100 Subject: [PATCH 09/24] Update .travis.yml Copied in the new Travis file from FoC --- .travis.yml | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 947ec92..0d41c0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,36 +1,51 @@ +#This Travis config template file was taken from https://github.com/FriendsOfCake/travis language: php php: - 5.4 - 5.5 + - 5.6 -env: - global: - - PLUGIN_NAME=Seo +sudo: false +env: matrix: - - CAKE_VERSION=3.0.8 - - CAKE_VERSION=3.0.0 + - DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test' + - DB=pgsql db_dsn='postgres://travis@127.0.0.1/cakephp_test' + - DB=sqlite db_dsn='sqlite:///:memory:' + + global: + - DEFAULT=1 matrix: + fast_finish: true + include: - - php: 5.5 - env: - - CAKE_VERSION=3.0.8 - - COVERALLS=1 - - php: 5.4 - env: - - PHPCS=1 + - php: 5.4 + env: PHPCS=1 DEFAULT=0 + + - php: 5.4 + env: COVERALLS=1 DEFAULT=0 DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test' + +install: + - composer self-update + - composer install --prefer-dist --no-interaction --dev before_script: - - git clone -b master https://github.com/FriendsOfCake/travis.git --depth 1 ../travis - - ../travis/before_script.sh + - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi" + - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi" + - sh -c "if [ '$PHPCS' = '1' ]; then composer require cakephp/cakephp-codesniffer:dev-master; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi" -script: - - ../travis/script.sh + - phpenv rehash + - set +H -after_success: - - ../travis/after_success.sh +script: + - sh -c "if [ '$DEFAULT' = '1' ]; then phpunit --stderr; fi" + - sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then phpunit --stderr --coverage-clover build/logs/clover.xml; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi" notifications: email: false From 148b2a59691bb6410509d5d83006cb3106d2d6bb Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 12:11:52 +0100 Subject: [PATCH 10/24] Update README.md --- README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e357163..efcd4b4 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,12 @@ Plugin::load('Seo'); Then you will need to attach it to the controller you want it to run on. I tend to attach it to my `AppController`. ```php -// src/Controller/AppController.php -public $components = [ - 'Seo.Seo' => [ - 'defaults' => [ - 'title' => 'Dave is epic', - 'description' => 'This is an epic plugin for epic people', - 'keywords' => 'epic,plugin' - ] +// src/Controller/AppController.php initialize() method +$this->loadComponent('Seo.Seo' => [ + 'defaults' => [ + 'title' => 'Dave is epic', + 'description' => 'This is an epic plugin for epic people', + 'keywords' => 'epic,plugin' ] ]; ``` From a7d959ae590be0cdfbe58aa63ebea5fc52510909 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 12:28:08 +0100 Subject: [PATCH 11/24] Fixed the title block assignment --- src/Controller/Component/SeoComponent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/Component/SeoComponent.php b/src/Controller/Component/SeoComponent.php index 415a8ac..263a38b 100644 --- a/src/Controller/Component/SeoComponent.php +++ b/src/Controller/Component/SeoComponent.php @@ -102,7 +102,7 @@ public function writeSeo(Event $event) // If no values can be found, fall back to the defaults if (empty($seoTitle)) { - $event->subject()->viewVars['title'] = $this->config('defaults.title'); + $event->subject()->assign('title', $this->config('defaults.title')); } if (empty($seoDescription)) { $event->subject()->Html->meta('description', $this->config('defaults.description'), ['block' => 'meta']); From a4724fd49a0d8ea650d76cc3e83a5d6a022bdbca Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 12:49:57 +0100 Subject: [PATCH 12/24] Fixed the viewVars, as they're entities and not arrays --- src/Controller/Component/SeoComponent.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Controller/Component/SeoComponent.php b/src/Controller/Component/SeoComponent.php index 263a38b..6b193ed 100644 --- a/src/Controller/Component/SeoComponent.php +++ b/src/Controller/Component/SeoComponent.php @@ -28,7 +28,6 @@ class SeoComponent extends Component implements EventListenerInterface */ protected $_defaultConfig = [ 'viewVar' => 'content', // Name of the view variable being used in views - 'model' => 'Content', // Model containing the fields 'fields' => [ 'title' => 'seo_title', 'description' => 'seo_description', @@ -77,13 +76,13 @@ public function implementedEvents() */ public function writeSeo(Event $event) { - if (!empty($event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.title')])) { - $seoTitle = $event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.title')]; - $event->subject()->viewVars['title'] = $seoTitle; + if (!empty($event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.title')))) { + $seoTitle = $event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.title')); + $event->subject()->assign('title', $seoTitle); } - if (!empty($event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.description')])) { - $seoDescription = $event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.description')]; + if (!empty($event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.description')))) { + $seoDescription = $event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.description')); $event->subject()->Html->meta( 'description', $seoDescription, @@ -91,8 +90,8 @@ public function writeSeo(Event $event) ); } - if (!empty($event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.keywords')])) { - $seoKeywords = $event->subject()->viewVars[$this->config('viewVar')][$this->config('model')][$this->config('fields.keywords')]; + if (!empty($event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.keywords')))) { + $seoKeywords = $event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.keywords')); $event->subject()->Html->meta( 'keywords', $seoKeywords, From 90d4e34a7105756dd8bbc5a8a2544dab2a741b8f Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 13:12:33 +0100 Subject: [PATCH 13/24] Fixed some minor bugs --- src/Controller/Component/SeoComponent.php | 6 ++--- .../Controller/Component/SeoComponentTest.php | 23 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Controller/Component/SeoComponent.php b/src/Controller/Component/SeoComponent.php index 6b193ed..d5423a9 100644 --- a/src/Controller/Component/SeoComponent.php +++ b/src/Controller/Component/SeoComponent.php @@ -76,12 +76,12 @@ public function implementedEvents() */ public function writeSeo(Event $event) { - if (!empty($event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.title')))) { + if (!empty($event->subject()->viewVars[$this->config('viewVar')])) { $seoTitle = $event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.title')); $event->subject()->assign('title', $seoTitle); } - if (!empty($event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.description')))) { + if (!empty($event->subject()->viewVars[$this->config('viewVar')])) { $seoDescription = $event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.description')); $event->subject()->Html->meta( 'description', @@ -90,7 +90,7 @@ public function writeSeo(Event $event) ); } - if (!empty($event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.keywords')))) { + if (!empty($event->subject()->viewVars[$this->config('viewVar')])) { $seoKeywords = $event->subject()->viewVars[$this->config('viewVar')]->get($this->config('fields.keywords')); $event->subject()->Html->meta( 'keywords', diff --git a/tests/TestCase/Controller/Component/SeoComponentTest.php b/tests/TestCase/Controller/Component/SeoComponentTest.php index e413e1a..1b381cd 100644 --- a/tests/TestCase/Controller/Component/SeoComponentTest.php +++ b/tests/TestCase/Controller/Component/SeoComponentTest.php @@ -14,6 +14,7 @@ use Cake\Controller\ComponentRegistry; use Cake\Controller\Controller; use Cake\Event\Event; +use Cake\ORM\Entity; use Seo\Controller\Component\SeoComponent; class SeoComponentTest extends \PHPUnit_Framework_TestCase @@ -36,20 +37,18 @@ public function testWriteSeo() $view->expects($this->exactly(2)) ->method('append'); - $view->set('content', [ - 'Content' => [ - 'seo_title' => 'Test SEO title', - 'seo_description' => 'Test SEO description', - 'seo_keywords' => 'Test SEO keywords' - ] - ]); + $view->set('content', new Entity([ + 'seo_title' => 'Test SEO title', + 'seo_description' => 'Test SEO description', + 'seo_keywords' => 'Test SEO keywords' + ])); $event = new Event('view.beforeLayout', $view, []); $this->Seo->writeSeo($event); - $title = $event->subject()->viewVars['title']; - $this->assertEquals('Test SEO title', $title); + $this->assertEquals(true, $event->subject()->exists('title')); + $this->assertEquals('Test SEO title', $event->subject()->fetch('title')); } public function testWriteSeoEmptyConfig() @@ -65,7 +64,9 @@ public function testWriteSeoEmptyConfig() $this->Seo->writeSeo($event); - $title = $event->subject()->viewVars['title']; - $this->assertEquals('The homepage | My Awesome Website', $title); + $this->assertEquals(true, $event->subject()->exists('title')); + $this->assertEquals('The homepage | My Awesome Website', $event->subject()->fetch('title')); + + } } From 7cd0c75fd00d70bcd111ff5080c8ffe048cee6f8 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 13:30:39 +0100 Subject: [PATCH 14/24] Added a phpunit config --- phpunit.xml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 phpunit.xml diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..9111fbe --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,32 @@ + + cacheTokens="false" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + forceCoversAnnotation="false" + mapTestClassNameToCoveredClassName="false" + printerClass="PHPUnit_TextUI_ResultPrinter" + + processIsolation="false" + stopOnError="false" + stopOnFailure="false" + stopOnIncomplete="false" + stopOnSkipped="false" + testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader" + + timeoutForSmallTests="1" + timeoutForMediumTests="10" + timeoutForLargeTests="60" + verbose="false"> + + + /tests/*.php + + + \ No newline at end of file From 0865598aab7bf4bfe793fae90258b6bea2a79119 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 13:31:26 +0100 Subject: [PATCH 15/24] Fixes to phpunit config --- phpunit.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 9111fbe..6719f6e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,7 +3,6 @@ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd" backupGlobals="true" backupStaticAttributes="false" - cacheTokens="false" colors="true" convertErrorsToExceptions="true" @@ -12,14 +11,12 @@ forceCoversAnnotation="false" mapTestClassNameToCoveredClassName="false" printerClass="PHPUnit_TextUI_ResultPrinter" - processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader" - timeoutForSmallTests="1" timeoutForMediumTests="10" timeoutForLargeTests="60" From 7d4a33006576486c84fd25995a31ecac98e6905d Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 14:47:01 +0100 Subject: [PATCH 16/24] Something --- composer.lock | 2 +- tests/TestCase/View/Helper/SeoHelperTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index 58d8529..cb5090f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "3c8d7984bc05f7d7462a3fcadd8da2ad", + "hash": "53dc77aaca3379e331890e9265ca0569", "packages": [ { "name": "aura/installer-default", diff --git a/tests/TestCase/View/Helper/SeoHelperTest.php b/tests/TestCase/View/Helper/SeoHelperTest.php index 37d3762..2afe848 100644 --- a/tests/TestCase/View/Helper/SeoHelperTest.php +++ b/tests/TestCase/View/Helper/SeoHelperTest.php @@ -16,6 +16,7 @@ use Cake\Network\Request; use Cake\View\View; use Seo\View\Helper\SeoHelper; +use Cake\Routing\Router; class SeoHelperTest extends \PHPUnit_Framework_TestCase { From 6e162fc8e5d52be08675a42ca44f8d0626541811 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 30 Jun 2015 14:47:30 +0100 Subject: [PATCH 17/24] Update .travis.yml --- .travis.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0d41c0e..b1a07cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,11 +9,6 @@ php: sudo: false env: - matrix: - - DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test' - - DB=pgsql db_dsn='postgres://travis@127.0.0.1/cakephp_test' - - DB=sqlite db_dsn='sqlite:///:memory:' - global: - DEFAULT=1 @@ -25,15 +20,13 @@ matrix: env: PHPCS=1 DEFAULT=0 - php: 5.4 - env: COVERALLS=1 DEFAULT=0 DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test' + env: COVERALLS=1 DEFAULT=0 install: - composer self-update - composer install --prefer-dist --no-interaction --dev before_script: - - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi" - - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi" - sh -c "if [ '$PHPCS' = '1' ]; then composer require cakephp/cakephp-codesniffer:dev-master; fi" - sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi" - sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi" @@ -42,7 +35,7 @@ before_script: - set +H script: - - sh -c "if [ '$DEFAULT' = '1' ]; then phpunit --stderr; fi" + - sh -c "if [ '$DEFAULT' = '1' ]; then ./vendor/bin/phpunit tests/TestCase --stderr; fi" - sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi" - sh -c "if [ '$COVERALLS' = '1' ]; then phpunit --stderr --coverage-clover build/logs/clover.xml; fi" - sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi" From 7649585c1e1830bffd0dc71c3d1eb7ca726e738c Mon Sep 17 00:00:00 2001 From: David Yell Date: Fri, 24 Jul 2015 15:08:46 +0100 Subject: [PATCH 18/24] Got the tests working independantly of an application --- phpunit.xml | 29 ------------ phpunit.xml.dist | 23 ++++++++++ src/View/Helper/SeoHelper.php | 29 +++++++++++- tests/TestCase/View/Helper/SeoHelperTest.php | 46 +++++++++++++++++--- 4 files changed, 89 insertions(+), 38 deletions(-) delete mode 100644 phpunit.xml create mode 100644 phpunit.xml.dist diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 6719f6e..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - /tests/*.php - - - \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..4c16042 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,23 @@ + + + + + + ./tests/ + + + + + + + ./vendor/ + ./vendor/ + + ./tests/ + ./tests/ + + + \ No newline at end of file diff --git a/src/View/Helper/SeoHelper.php b/src/View/Helper/SeoHelper.php index 6e9be5f..698f4d3 100644 --- a/src/View/Helper/SeoHelper.php +++ b/src/View/Helper/SeoHelper.php @@ -35,8 +35,8 @@ public function pagination($controller) $className = Inflector::classify($controller); if (isset($this->request->params['paging'][$className])) { - $prev = " $controller, 'action' => 'index', 'page' => $this->request->params['paging'][$className]['page'] - 1]) . "'>"; - $next = " $controller, 'action' => 'index', 'page' => $this->request->params['paging'][$className]['page'] + 1]) . "'>"; + $prev = ""; + $next = ""; if ($this->request->params['paging'][$className]['prevPage'] === false) { // page 1 return $next; @@ -61,4 +61,29 @@ public function canonical() return ""; } + + /** + * Build a url link for the previous and next pages + * + * @param string $controller The name of the controller + * @param int $page The current page + * @param string $type 'prev' or 'next' + * @param bool $full Include the fullBaseUrl? + * @return string Complete url string + */ + public function pageLink($controller, $page, $type, $full = false) + { + if ($type == 'next') { + $p = ['page' => $page + 1]; + } else { + $p = ['page' => $page - 1]; + } + + $url = array_merge( + ['controller' => $controller, 'action' => 'index'], + $p + ); + + return Router::url($url, $full); + } } diff --git a/tests/TestCase/View/Helper/SeoHelperTest.php b/tests/TestCase/View/Helper/SeoHelperTest.php index 2afe848..347afec 100644 --- a/tests/TestCase/View/Helper/SeoHelperTest.php +++ b/tests/TestCase/View/Helper/SeoHelperTest.php @@ -16,10 +16,14 @@ use Cake\Network\Request; use Cake\View\View; use Seo\View\Helper\SeoHelper; -use Cake\Routing\Router; class SeoHelperTest extends \PHPUnit_Framework_TestCase { + protected function setUp() + { + parent::setUp(); + Configure::write('App.fullBaseUrl', 'http://localhost'); + } public function paginationProvider() { @@ -30,6 +34,10 @@ public function paginationProvider() 'prevPage' => true, 'nextPage' => true ]], + [ + 'next' => '/tests?page=6', + 'prev' => '/tests?page=4' + ], "" ], [ @@ -38,6 +46,9 @@ public function paginationProvider() 'prevPage' => false, 'nextPage' => true ]], + [ + 'next' => '/tests?page=2' + ], "" ], [ @@ -46,17 +57,21 @@ public function paginationProvider() 'prevPage' => true, 'nextPage' => false ]], + [ + 'prev' => '/tests?page=5' + ], "" ], ]; } /** - * @param $pagingArray - * @param $expected + * @param array $pagingArray + * @param array $urls + * @param string $expected * @dataProvider paginationProvider */ - public function testPagination($pagingArray, $expected) + public function testPagination(array $pagingArray, array $urls, $expected) { $this->Request = new Request(); $this->Request->params['paging'] = $pagingArray; @@ -66,7 +81,25 @@ public function testPagination($pagingArray, $expected) $this->View = new View($this->Request); - $helper = new SeoHelper($this->View); + $helper = $this->getMockBuilder('Seo\View\Helper\SeoHelper') + ->setConstructorArgs([$this->View]) + ->setMethods(['pageLink']) + ->getMock(); + + if ($pagingArray['Test']['prevPage']) { + $helper->expects($this->at(0)) + ->method('pageLink') + ->with($this->Controller->name, $pagingArray['Test']['page'], 'prev') + ->willReturn($urls['prev']); + } + + if ($pagingArray['Test']['nextPage']) { + $helper->expects($this->at(1)) + ->method('pageLink') + ->with($this->Controller->name, $pagingArray['Test']['page'], 'next') + ->willReturn($urls['next']); + } + $helper->paginatedControllers = ['Tests']; $result = $helper->pagination($this->Controller->name); @@ -109,8 +142,6 @@ public function canonicalProvider() */ public function testCanonical($here, $expected) { - Configure::write('App.fullBaseUrl', 'http://localhost'); - $this->Request = new Request(); $this->Request->here = $here; @@ -123,4 +154,5 @@ public function testCanonical($here, $expected) $result = $helper->canonical('Tests', 'index'); $this->assertEquals($expected, $result); } + } From c5a5597dc77975994065778d9c0947d35f1a8aa2 Mon Sep 17 00:00:00 2001 From: David Yell Date: Fri, 24 Jul 2015 15:19:23 +0100 Subject: [PATCH 19/24] Fix phpcs errors --- tests/TestCase/Controller/Component/SeoComponentTest.php | 2 -- tests/TestCase/View/Helper/SeoHelperTest.php | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/TestCase/Controller/Component/SeoComponentTest.php b/tests/TestCase/Controller/Component/SeoComponentTest.php index 1b381cd..544fb44 100644 --- a/tests/TestCase/Controller/Component/SeoComponentTest.php +++ b/tests/TestCase/Controller/Component/SeoComponentTest.php @@ -66,7 +66,5 @@ public function testWriteSeoEmptyConfig() $this->assertEquals(true, $event->subject()->exists('title')); $this->assertEquals('The homepage | My Awesome Website', $event->subject()->fetch('title')); - - } } diff --git a/tests/TestCase/View/Helper/SeoHelperTest.php b/tests/TestCase/View/Helper/SeoHelperTest.php index 347afec..a6c0ab9 100644 --- a/tests/TestCase/View/Helper/SeoHelperTest.php +++ b/tests/TestCase/View/Helper/SeoHelperTest.php @@ -19,11 +19,13 @@ class SeoHelperTest extends \PHPUnit_Framework_TestCase { + // @codingStandardsIgnoreStart protected function setUp() { parent::setUp(); Configure::write('App.fullBaseUrl', 'http://localhost'); } + // @codingStandardsIgnoreEnd public function paginationProvider() { @@ -154,5 +156,4 @@ public function testCanonical($here, $expected) $result = $helper->canonical('Tests', 'index'); $this->assertEquals($expected, $result); } - } From 584a153e7e75b569c2ded6622670fde490f0f27f Mon Sep 17 00:00:00 2001 From: David Yell Date: Mon, 27 Jul 2015 09:07:07 +0100 Subject: [PATCH 20/24] Updated the path of src --- .coveralls.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.coveralls.yml b/.coveralls.yml index e6c3bf6..09bbb25 100644 --- a/.coveralls.yml +++ b/.coveralls.yml @@ -1,3 +1,3 @@ -src_dir: vendor/davidyell/seo +src_dir: src coverage_clover: build/logs/clover.xml json_path: build/logs/coveralls-upload.json From 2db2de4504b7ef92b51149353bb1ae05f8615f1b Mon Sep 17 00:00:00 2001 From: David Yell Date: Mon, 27 Jul 2015 09:18:27 +0100 Subject: [PATCH 21/24] Updated to latest phpunit --- composer.json | 2 +- composer.lock | 129 +++++++++++++++++++++++++------------------------- 2 files changed, 66 insertions(+), 65 deletions(-) diff --git a/composer.json b/composer.json index e9485f4..f4e9dac 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "cakephp/cakephp": "~3.0" }, "require-dev": { - "phpunit/phpunit": "*", + "phpunit/phpunit": "4.7.*", "cakephp/cakephp-codesniffer": "~2.0" }, "autoload": { diff --git a/composer.lock b/composer.lock index cb5090f..dd43ce0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "53dc77aaca3379e331890e9265ca0569", + "hash": "182de19fadd91bba3ebc71fe4d6d34d1", "packages": [ { "name": "aura/installer-default", @@ -127,16 +127,16 @@ }, { "name": "cakephp/cakephp", - "version": "3.0.8", + "version": "3.0.10", "source": { "type": "git", "url": "https://github.com/cakephp/cakephp.git", - "reference": "29ca3d120c25d554ad5143adffdab0f76bc6c9b9" + "reference": "2bb38807a5a0ba91d27ec80e702dea6a3bb21e53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cakephp/cakephp/zipball/29ca3d120c25d554ad5143adffdab0f76bc6c9b9", - "reference": "29ca3d120c25d554ad5143adffdab0f76bc6c9b9", + "url": "https://api.github.com/repos/cakephp/cakephp/zipball/2bb38807a5a0ba91d27ec80e702dea6a3bb21e53", + "reference": "2bb38807a5a0ba91d27ec80e702dea6a3bb21e53", "shasum": "" }, "require": { @@ -198,7 +198,7 @@ "keywords": [ "framework" ], - "time": "2015-06-28 17:00:48" + "time": "2015-07-21 20:55:01" }, { "name": "ircmaxell/password-compat", @@ -330,20 +330,20 @@ "packages-dev": [ { "name": "cakephp/cakephp-codesniffer", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/cakephp/cakephp-codesniffer.git", - "reference": "149af3ec5525151543892221eb2945bb54fa4069" + "reference": "a1438a101ae11ac43383c4f4114f17d6cb8f53c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cakephp/cakephp-codesniffer/zipball/149af3ec5525151543892221eb2945bb54fa4069", - "reference": "149af3ec5525151543892221eb2945bb54fa4069", + "url": "https://api.github.com/repos/cakephp/cakephp-codesniffer/zipball/a1438a101ae11ac43383c4f4114f17d6cb8f53c4", + "reference": "a1438a101ae11ac43383c4f4114f17d6cb8f53c4", "shasum": "" }, "require": { - "squizlabs/php_codesniffer": "2.*" + "squizlabs/php_codesniffer": "^2.3.1" }, "require-dev": { "phpunit/phpunit": "4.1.*" @@ -365,7 +365,7 @@ "codesniffer", "framework" ], - "time": "2015-03-17 01:11:58" + "time": "2015-07-10 20:33:06" }, { "name": "doctrine/instantiator", @@ -532,16 +532,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "2.1.7", + "version": "2.1.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "07e27765596d72c378a6103e80da5d84e802f1e4" + "reference": "5bd48b86cd282da411bb80baac1398ce3fefac41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/07e27765596d72c378a6103e80da5d84e802f1e4", - "reference": "07e27765596d72c378a6103e80da5d84e802f1e4", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/5bd48b86cd282da411bb80baac1398ce3fefac41", + "reference": "5bd48b86cd282da411bb80baac1398ce3fefac41", "shasum": "" }, "require": { @@ -590,20 +590,20 @@ "testing", "xunit" ], - "time": "2015-06-30 06:52:35" + "time": "2015-07-26 12:54:47" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", "shasum": "" }, "require": { @@ -637,7 +637,7 @@ "filesystem", "iterator" ], - "time": "2015-04-02 05:19:05" + "time": "2015-06-21 13:08:43" }, { "name": "phpunit/php-text-template", @@ -682,16 +682,16 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.6", + "version": "1.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d" + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/83fe1bdc5d47658b727595c14da140da92b3d66d", - "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", "shasum": "" }, "require": { @@ -719,7 +719,7 @@ "keywords": [ "timer" ], - "time": "2015-06-13 07:35:30" + "time": "2015-06-21 08:01:12" }, { "name": "phpunit/php-token-stream", @@ -772,16 +772,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.7.6", + "version": "4.7.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "0ebabb4cda7d066be8391dfdbaf57fe70ac9a99b" + "reference": "9b97f9d807b862c2de2a36e86690000801c85724" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0ebabb4cda7d066be8391dfdbaf57fe70ac9a99b", - "reference": "0ebabb4cda7d066be8391dfdbaf57fe70ac9a99b", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9b97f9d807b862c2de2a36e86690000801c85724", + "reference": "9b97f9d807b862c2de2a36e86690000801c85724", "shasum": "" }, "require": { @@ -840,26 +840,27 @@ "testing", "xunit" ], - "time": "2015-06-30 06:53:57" + "time": "2015-07-13 11:28:34" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.3.4", + "version": "2.3.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35" + "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/92408bb1968a81b3217a6fdf6c1a198da83caa35", - "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/18dfbcb81d05e2296c0bcddd4db96cade75e6f42", + "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42", "shasum": "" }, "require": { "doctrine/instantiator": "~1.0,>=1.0.2", "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2" + "phpunit/php-text-template": "~1.2", + "sebastian/exporter": "~1.2" }, "require-dev": { "phpunit/phpunit": "~4.4" @@ -895,20 +896,20 @@ "mock", "xunit" ], - "time": "2015-06-11 15:55:48" + "time": "2015-07-10 06:54:24" }, { "name": "sebastian/comparator", - "version": "1.1.1", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + "reference": "937efb279bd37a375bcadf584dec0726f84dbf22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22", + "reference": "937efb279bd37a375bcadf584dec0726f84dbf22", "shasum": "" }, "require": { @@ -922,7 +923,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { @@ -959,7 +960,7 @@ "compare", "equality" ], - "time": "2015-01-29 16:28:08" + "time": "2015-07-26 15:48:44" }, { "name": "sebastian/diff", @@ -1015,16 +1016,16 @@ }, { "name": "sebastian/environment", - "version": "1.2.2", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + "reference": "4fe0a44cddd8cc19583a024bdc7374eb2fef0b87" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4fe0a44cddd8cc19583a024bdc7374eb2fef0b87", + "reference": "4fe0a44cddd8cc19583a024bdc7374eb2fef0b87", "shasum": "" }, "require": { @@ -1061,20 +1062,20 @@ "environment", "hhvm" ], - "time": "2015-01-01 10:01:08" + "time": "2015-07-26 06:42:57" }, { "name": "sebastian/exporter", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "84839970d05254c73cde183a721c7af13aede943" + "reference": "7ae5513327cb536431847bcc0c10edba2701064e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", - "reference": "84839970d05254c73cde183a721c7af13aede943", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", + "reference": "7ae5513327cb536431847bcc0c10edba2701064e", "shasum": "" }, "require": { @@ -1127,7 +1128,7 @@ "export", "exporter" ], - "time": "2015-01-27 07:23:06" + "time": "2015-06-21 07:55:53" }, { "name": "sebastian/global-state", @@ -1182,16 +1183,16 @@ }, { "name": "sebastian/recursion-context", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + "reference": "994d4a811bafe801fb06dccbee797863ba2792ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba", + "reference": "994d4a811bafe801fb06dccbee797863ba2792ba", "shasum": "" }, "require": { @@ -1231,7 +1232,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-01-24 09:48:32" + "time": "2015-06-21 08:04:50" }, { "name": "sebastian/version", @@ -1344,16 +1345,16 @@ }, { "name": "symfony/yaml", - "version": "v2.7.1", + "version": "v2.7.2", "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160" + "reference": "4bfbe0ed3909bfddd75b70c094391ec1f142f860" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/9808e75c609a14f6db02f70fccf4ca4aab53c160", - "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/4bfbe0ed3909bfddd75b70c094391ec1f142f860", + "reference": "4bfbe0ed3909bfddd75b70c094391ec1f142f860", "shasum": "" }, "require": { @@ -1389,7 +1390,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-06-10 15:30:22" + "time": "2015-07-01 11:25:50" } ], "aliases": [], From 39a4473c9da0b3eacf3b010a94b4f68edceb1864 Mon Sep 17 00:00:00 2001 From: David Yell Date: Mon, 27 Jul 2015 09:34:32 +0100 Subject: [PATCH 22/24] Updated the path of phpunit for the coverage clover --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b1a07cf..c34e930 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ before_script: script: - sh -c "if [ '$DEFAULT' = '1' ]; then ./vendor/bin/phpunit tests/TestCase --stderr; fi" - sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi" - - sh -c "if [ '$COVERALLS' = '1' ]; then phpunit --stderr --coverage-clover build/logs/clover.xml; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then ./vendor/bin/phpunit tests/TestCase --stderr --coverage-clover build/logs/clover.xml; fi" - sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi" notifications: From 4f21396e054336136370de20695d52727e66a8d7 Mon Sep 17 00:00:00 2001 From: David Yell Date: Mon, 27 Jul 2015 09:58:48 +0100 Subject: [PATCH 23/24] Updated the argument ordering for phpunit coverage --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c34e930..874a1e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ before_script: script: - sh -c "if [ '$DEFAULT' = '1' ]; then ./vendor/bin/phpunit tests/TestCase --stderr; fi" - sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi" - - sh -c "if [ '$COVERALLS' = '1' ]; then ./vendor/bin/phpunit tests/TestCase --stderr --coverage-clover build/logs/clover.xml; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then ./vendor/bin/phpunit --stderr --coverage-xml build/logs tests/TestCase; fi" - sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi" notifications: From 0b98cc8698c826c646320c1a7ffddccd5e0664d4 Mon Sep 17 00:00:00 2001 From: David Yell Date: Mon, 27 Jul 2015 10:03:09 +0100 Subject: [PATCH 24/24] Updated coverage filename --- .coveralls.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.coveralls.yml b/.coveralls.yml index 09bbb25..f320313 100644 --- a/.coveralls.yml +++ b/.coveralls.yml @@ -1,3 +1,3 @@ src_dir: src -coverage_clover: build/logs/clover.xml +coverage_clover: build/logs/index.xml json_path: build/logs/coveralls-upload.json