]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/plugins/PluginDefaultColorsTest.php
Fix default_colors plugin: update CSS file on color change
[github/shaarli/Shaarli.git] / tests / plugins / PluginDefaultColorsTest.php
index 9835dfa39ac7de4706d0f62b63cf86ed35f9d974..54e97612538858d08f47e7a145f824399ad23805 100644 (file)
@@ -2,10 +2,10 @@
 
 namespace Shaarli\Plugin\DefaultColors;
 
-use PHPUnit\Framework\TestCase;
 use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
 use Shaarli\Plugin\PluginManager;
+use Shaarli\TestCase;
 
 require_once 'plugins/default_colors/default_colors.php';
 
@@ -19,7 +19,7 @@ class PluginDefaultColorsTest extends TestCase
     /**
      * Reset plugin path
      */
-    public function setUp()
+    protected function setUp(): void
     {
         PluginManager::$PLUGINS_PATH = 'sandbox';
         mkdir(PluginManager::$PLUGINS_PATH . '/default_colors/');
@@ -32,7 +32,7 @@ class PluginDefaultColorsTest extends TestCase
     /**
      * Remove sandbox files and folder
      */
-    public function tearDown()
+    protected function tearDown(): void
     {
         if (file_exists('sandbox/default_colors/default_colors.css.template')) {
             unlink('sandbox/default_colors/default_colors.css.template');
@@ -193,4 +193,27 @@ class PluginDefaultColorsTest extends TestCase
         $result = default_colors_format_css_rule($data, '');
         $this->assertEmpty($result);
     }
+
+    /**
+     * Make sure that a new CSS file is generated when save_plugin_parameters hook is triggered.
+     */
+    public function testHookSavePluginParameters(): void
+    {
+        $params = [
+            'other1' => true,
+            'DEFAULT_COLORS_BACKGROUND' => 'pink',
+            'other2' => ['yep'],
+            'DEFAULT_COLORS_DARK_MAIN' => '',
+        ];
+
+        hook_default_colors_save_plugin_parameters($params);
+        $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css');
+        $content = file_get_contents($file);
+        $expected = ':root {
+  --background-color: pink;
+
+}
+';
+        $this->assertEquals($expected, $content);
+    }
 }