diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b31a804 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/.buildpath +/.project +/.idea +/.settings/ +/vendor/ +/composer.lock +/nbproject/ +/phpunit.xml +/tmp +/.phpunit.result.cache diff --git a/composer.json b/composer.json index 8039422..84bb967 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,12 @@ } ], "require": { - "cakephp/cakephp": "~3.0", + "cakephp/cakephp": "^4.0", "tijsverkoyen/css-to-inline-styles": "^1.5" }, + "require-dev": { + "phpunit/phpunit": "^8" + }, "autoload": { "psr-4": { "InlineCss\\": "src" diff --git a/readme.md b/readme.md index 00e2453..41fa176 100644 --- a/readme.md +++ b/readme.md @@ -6,14 +6,14 @@ This plugin provides a CakePHP helper that uses [CssToInlineStyles](https://gith ## Requirements -* CakePHP 3.x +* CakePHP 4.x ## Installation This plugin should be installed using Composer:- ``` -composer require drmonkeyninja/cakephp-inline-css:3.0.* +composer require drmonkeyninja/cakephp-inline-css:4.0.* ``` Then add the following line to your bootstrap.php to load the plugin. diff --git a/src/View/Helper/InlineCssHelper.php b/src/View/Helper/InlineCssHelper.php index 50307af..4e31e91 100644 --- a/src/View/Helper/InlineCssHelper.php +++ b/src/View/Helper/InlineCssHelper.php @@ -10,12 +10,14 @@ class InlineCssHelper extends Helper /** * After layout logic. * - * @param \Cake\Event\Event $event Event - * @param string $layoutFile Layout filename + * @param \Cake\Event\Event $event Event + * @param string $layoutFile Layout filename + * + * @throws \TijsVerkoyen\CssToInlineStyles\Exception */ public function afterLayout(\Cake\Event\Event $event, $layoutFile) { - $content = $this->_View->Blocks->get('content'); + $content = $this->_View->fetch('content'); if (!isset($this->InlineCss)) { $this->InlineCss = new CssToInlineStyles(); @@ -26,7 +28,7 @@ public function afterLayout(\Cake\Event\Event $event, $layoutFile) $this->InlineCss->setUseInlineStylesBlock(true); $content = $this->InlineCss->convert(); - $this->_View->Blocks->set('content', $content); + $this->_View->assign('content', $content); return; } diff --git a/tests/TestCase/View/Helper/InlineCssHelperTest.php b/tests/TestCase/View/Helper/InlineCssHelperTest.php index cd05d30..f372489 100644 --- a/tests/TestCase/View/Helper/InlineCssHelperTest.php +++ b/tests/TestCase/View/Helper/InlineCssHelperTest.php @@ -1,17 +1,17 @@ View->Blocks->set('content', '

Test

'); + $this->View->assign('content', '

Test

'); $this->InlineCss->afterLayout(new \Cake\Event\Event(''), null); $expected = '

Test

'; - $this->assertContains($expected, $this->View->Blocks->get('content')); + $this->assertStringContainsString($expected, $this->View->fetch('content')); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 8452188..8c15ac9 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,6 +1,11 @@ 'App' + 'namespace' => 'App', ]); Cake\Core\Configure::write('debug', true); $cache = [ 'default' => [ 'engine' => 'File', - 'path' => CACHE + 'path' => CACHE, ], '_cake_core_' => [ 'className' => 'File', 'prefix' => 'crud_myapp_cake_core_', - 'path' => CACHE . 'persistent/', + 'path' => CACHE.'persistent/', 'serialize' => true, - 'duration' => '+10 seconds' + 'duration' => '+10 seconds', ], '_cake_model_' => [ 'className' => 'File', 'prefix' => 'crud_my_app_cake_model_', - 'path' => CACHE . 'models/', + 'path' => CACHE.'models/', 'serialize' => 'File', - 'duration' => '+10 seconds' - ] + 'duration' => '+10 seconds', + ], ]; -Cake\Cache\Cache::config($cache); -Cake\Core\Plugin::load('SocialShare', ['path' => ROOT . DS]); +Cache::setConfig($cache); // Ensure default test connection is defined if (!getenv('db_class')) { putenv('db_class=Cake\Database\Driver\Sqlite'); putenv('db_dsn=sqlite::memory:'); } -Cake\Datasource\ConnectionManager::config('test', [ +ConnectionManager::setConfig('test', [ 'className' => 'Cake\Database\Connection', - 'driver' => getenv('db_class'), - 'dsn' => getenv('db_dsn'), - 'database' => getenv('db_database'), - 'username' => getenv('db_username'), - 'password' => getenv('db_password'), - 'timezone' => 'UTC', - 'quoteIdentifiers' => true, + 'driver' => 'Cake\Database\Driver\Sqlite', + 'database' => TMP.'test.sqlite', + 'encoding' => 'utf8', 'cacheMetadata' => true, + 'quoteIdentifiers' => false, ]);