aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'tests/plugins')
-rw-r--r--tests/plugins/PluginAddlinkTest.php10
-rw-r--r--tests/plugins/PluginArchiveorgTest.php5
-rw-r--r--tests/plugins/PluginDefaultColorsTest.php195
-rw-r--r--tests/plugins/PluginIssoTest.php7
-rw-r--r--tests/plugins/PluginMarkdownTest.php8
-rw-r--r--tests/plugins/PluginPlayvideosTest.php7
-rw-r--r--tests/plugins/PluginPubsubhubbubTest.php7
-rw-r--r--tests/plugins/PluginQrcodeTest.php8
-rw-r--r--tests/plugins/PluginWallabagTest.php9
-rw-r--r--tests/plugins/WallabagInstanceTest.php5
10 files changed, 237 insertions, 24 deletions
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php
index b6239e7f..d052f8b9 100644
--- a/tests/plugins/PluginAddlinkTest.php
+++ b/tests/plugins/PluginAddlinkTest.php
@@ -1,17 +1,15 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Addlink;
2 3
3/** 4use Shaarli\Plugin\PluginManager;
4 * PluginPlayvideosTest.php 5use Shaarli\Router;
5 */
6 6
7require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; 7require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
8require_once 'application/Router.php';
9 8
10/** 9/**
11 * Class PluginAddlinkTest
12 * Unit test for the Addlink toolbar plugin 10 * Unit test for the Addlink toolbar plugin
13 */ 11 */
14class PluginAddlinkTest extends PHPUnit_Framework_TestCase 12class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
15{ 13{
16 /** 14 /**
17 * Reset plugin path. 15 * Reset plugin path.
diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php
index fecd5f2c..510288bb 100644
--- a/tests/plugins/PluginArchiveorgTest.php
+++ b/tests/plugins/PluginArchiveorgTest.php
@@ -1,16 +1,19 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Archiveorg;
2 3
3/** 4/**
4 * PluginArchiveorgTest.php 5 * PluginArchiveorgTest.php
5 */ 6 */
6 7
8use Shaarli\Plugin\PluginManager;
9
7require_once 'plugins/archiveorg/archiveorg.php'; 10require_once 'plugins/archiveorg/archiveorg.php';
8 11
9/** 12/**
10 * Class PluginArchiveorgTest 13 * Class PluginArchiveorgTest
11 * Unit test for the archiveorg plugin 14 * Unit test for the archiveorg plugin
12 */ 15 */
13class PluginArchiveorgTest extends PHPUnit_Framework_TestCase 16class PluginArchiveorgTest extends \PHPUnit\Framework\TestCase
14{ 17{
15 /** 18 /**
16 * Reset plugin path 19 * Reset plugin path
diff --git a/tests/plugins/PluginDefaultColorsTest.php b/tests/plugins/PluginDefaultColorsTest.php
new file mode 100644
index 00000000..b9951cca
--- /dev/null
+++ b/tests/plugins/PluginDefaultColorsTest.php
@@ -0,0 +1,195 @@
1<?php
2
3namespace Shaarli\Plugin\DefaultColors;
4
5use DateTime;
6use PHPUnit\Framework\TestCase;
7use Shaarli\Bookmark\LinkDB;
8use Shaarli\Config\ConfigManager;
9use Shaarli\Plugin\PluginManager;
10
11require_once 'plugins/default_colors/default_colors.php';
12
13/**
14 * Class PluginDefaultColorsTest
15 *
16 * Test the DefaultColors plugin (allowing to override default template colors).
17 */
18class PluginDefaultColorsTest extends TestCase
19{
20 /**
21 * Reset plugin path
22 */
23 public function setUp()
24 {
25 PluginManager::$PLUGINS_PATH = 'sandbox';
26 mkdir(PluginManager::$PLUGINS_PATH . '/default_colors/');
27 copy(
28 'plugins/default_colors/default_colors.css.template',
29 PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css.template'
30 );
31 }
32
33 /**
34 * Remove sandbox files and folder
35 */
36 public function tearDown()
37 {
38 if (file_exists('sandbox/default_colors/default_colors.css.template')) {
39 unlink('sandbox/default_colors/default_colors.css.template');
40 }
41
42 if (file_exists('sandbox/default_colors/default_colors.css')) {
43 unlink('sandbox/default_colors/default_colors.css');
44 }
45
46 if (is_dir('sandbox/default_colors')) {
47 rmdir('sandbox/default_colors');
48 }
49 }
50
51 /**
52 * Test DefaultColors init without errors.
53 */
54 public function testDefaultColorsInitNoError()
55 {
56 $conf = new ConfigManager('');
57 $conf->set('plugins.DEFAULT_COLORS_BACKGROUND', 'value');
58 $errors = default_colors_init($conf);
59 $this->assertEmpty($errors);
60 }
61
62 /**
63 * Test DefaultColors init with errors.
64 */
65 public function testDefaultColorsInitError()
66 {
67 $conf = new ConfigManager('');
68 $errors = default_colors_init($conf);
69 $this->assertNotEmpty($errors);
70 }
71
72 /**
73 * Test the save plugin parameters hook with all colors specified.
74 */
75 public function testSavePluginParametersAll()
76 {
77 $post = [
78 'other1' => true,
79 'DEFAULT_COLORS_MAIN' => 'blue',
80 'DEFAULT_COLORS_BACKGROUND' => 'pink',
81 'other2' => ['yep'],
82 'DEFAULT_COLORS_DARK_MAIN' => 'green',
83 ];
84
85 hook_default_colors_save_plugin_parameters($post);
86 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css');
87 $content = file_get_contents($file);
88 $expected = ':root {
89 --main-color: blue;
90 --background-color: pink;
91 --dark-main-color: green;
92
93}
94';
95 $this->assertEquals($expected, $content);
96 }
97
98 /**
99 * Test the save plugin parameters hook with only one color specified.
100 */
101 public function testSavePluginParametersSingle()
102 {
103 $post = [
104 'other1' => true,
105 'DEFAULT_COLORS_BACKGROUND' => 'pink',
106 'other2' => ['yep'],
107 'DEFAULT_COLORS_DARK_MAIN' => '',
108 ];
109
110 hook_default_colors_save_plugin_parameters($post);
111 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css');
112 $content = file_get_contents($file);
113 $expected = ':root {
114 --background-color: pink;
115
116}
117';
118 $this->assertEquals($expected, $content);
119 }
120
121 /**
122 * Test the save plugin parameters hook with no color specified.
123 */
124 public function testSavePluginParametersNone()
125 {
126 hook_default_colors_save_plugin_parameters([]);
127 $this->assertFileNotExists($file = 'sandbox/default_colors/default_colors.css');
128 }
129
130 /**
131 * Make sure that the CSS is properly included by the include hook.
132 */
133 public function testIncludeWithFile()
134 {
135 $data = [
136 'css_files' => ['file1'],
137 'js_files' => ['file2'],
138 ];
139 touch($file = 'sandbox/default_colors/default_colors.css');
140 $processedData = hook_default_colors_render_includes($data);
141
142 $this->assertCount(2, $processedData['css_files']);
143 $this->assertEquals($file, $processedData['css_files'][1]);
144 $this->assertCount(1, $processedData['js_files']);
145 }
146
147 /**
148 * Make sure that the CSS is not included by the include hook if the CSS file does not exist.
149 */
150 public function testIncludeWithoutFile()
151 {
152 $data = [
153 'css_files' => ['file1'],
154 'js_files' => ['file2'],
155 ];
156 $processedData = hook_default_colors_render_includes($data);
157
158 $this->assertEquals($data, $processedData);
159 }
160
161 /**
162 * Test helper function which generates CSS rules with valid input.
163 */
164 public function testFormatCssRuleValid()
165 {
166 $data = [
167 'other1' => true,
168 'DEFAULT_COLORS_BLIP_BLOP' => 'shinyColor',
169 'other2' => ['yep'],
170 ];
171 $result = default_colors_format_css_rule($data, 'DEFAULT_COLORS_BLIP_BLOP');
172 $this->assertEquals(' --blip-blop-color: shinyColor', $result);
173
174 $data = ['unknown-parameter' => true];
175 $result = default_colors_format_css_rule($data, 'unknown-parameter');
176 $this->assertEquals(' --unknown-parameter-color: 1', $result);
177 }
178
179 /**
180 * Test helper function which generates CSS rules with invalid input.
181 */
182 public function testFormatCssRuleInvalid()
183 {
184 $result = default_colors_format_css_rule([], 'DEFAULT_COLORS_BLIP_BLOP');
185 $this->assertEmpty($result);
186
187 $data = [
188 'other1' => true,
189 'DEFAULT_COLORS_BLIP_BLOP' => 'shinyColor',
190 'other2' => ['yep'],
191 ];
192 $result = default_colors_format_css_rule($data, '');
193 $this->assertEmpty($result);
194 }
195}
diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php
index 2c9efbcd..bdfab439 100644
--- a/tests/plugins/PluginIssoTest.php
+++ b/tests/plugins/PluginIssoTest.php
@@ -1,5 +1,10 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Isso;
3
4use DateTime;
5use Shaarli\Bookmark\LinkDB;
2use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\Plugin\PluginManager;
3 8
4require_once 'plugins/isso/isso.php'; 9require_once 'plugins/isso/isso.php';
5 10
@@ -8,7 +13,7 @@ require_once 'plugins/isso/isso.php';
8 * 13 *
9 * Test the Isso plugin (comment system). 14 * Test the Isso plugin (comment system).
10 */ 15 */
11class PluginIssoTest extends PHPUnit_Framework_TestCase 16class PluginIssoTest extends \PHPUnit\Framework\TestCase
12{ 17{
13 /** 18 /**
14 * Reset plugin path 19 * Reset plugin path
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php
index 44364b05..9ddbc558 100644
--- a/tests/plugins/PluginMarkdownTest.php
+++ b/tests/plugins/PluginMarkdownTest.php
@@ -1,10 +1,14 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Markdown;
3
2use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5use Shaarli\Plugin\PluginManager;
3 6
4/** 7/**
5 * PluginMarkdownTest.php 8 * PluginMarkdownTest.php
6 */ 9 */
7 10
11require_once 'application/bookmark/LinkUtils.php';
8require_once 'application/Utils.php'; 12require_once 'application/Utils.php';
9require_once 'plugins/markdown/markdown.php'; 13require_once 'plugins/markdown/markdown.php';
10 14
@@ -12,7 +16,7 @@ require_once 'plugins/markdown/markdown.php';
12 * Class PluginMarkdownTest 16 * Class PluginMarkdownTest
13 * Unit test for the Markdown plugin 17 * Unit test for the Markdown plugin
14 */ 18 */
15class PluginMarkdownTest extends PHPUnit_Framework_TestCase 19class PluginMarkdownTest extends \PHPUnit\Framework\TestCase
16{ 20{
17 /** 21 /**
18 * @var ConfigManager instance. 22 * @var ConfigManager instance.
@@ -103,7 +107,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
103 public function testReverseText2clickable() 107 public function testReverseText2clickable()
104 { 108 {
105 $text = 'stuff http://hello.there/is=someone#here otherstuff'; 109 $text = 'stuff http://hello.there/is=someone#here otherstuff';
106 $clickableText = text2clickable($text, ''); 110 $clickableText = text2clickable($text);
107 $reversedText = reverse_text2clickable($clickableText); 111 $reversedText = reverse_text2clickable($clickableText);
108 $this->assertEquals($text, $reversedText); 112 $this->assertEquals($text, $reversedText);
109 } 113 }
diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php
index 29ad047f..51472617 100644
--- a/tests/plugins/PluginPlayvideosTest.php
+++ b/tests/plugins/PluginPlayvideosTest.php
@@ -1,17 +1,20 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Playvideos;
2 3
3/** 4/**
4 * PluginPlayvideosTest.php 5 * PluginPlayvideosTest.php
5 */ 6 */
6 7
8use Shaarli\Plugin\PluginManager;
9use Shaarli\Router;
10
7require_once 'plugins/playvideos/playvideos.php'; 11require_once 'plugins/playvideos/playvideos.php';
8require_once 'application/Router.php';
9 12
10/** 13/**
11 * Class PluginPlayvideosTest 14 * Class PluginPlayvideosTest
12 * Unit test for the PlayVideos plugin 15 * Unit test for the PlayVideos plugin
13 */ 16 */
14class PluginPlayvideosTest extends PHPUnit_Framework_TestCase 17class PluginPlayvideosTest extends \PHPUnit\Framework\TestCase
15{ 18{
16 /** 19 /**
17 * Reset plugin path 20 * Reset plugin path
diff --git a/tests/plugins/PluginPubsubhubbubTest.php b/tests/plugins/PluginPubsubhubbubTest.php
index 69d00936..a7bd8fc9 100644
--- a/tests/plugins/PluginPubsubhubbubTest.php
+++ b/tests/plugins/PluginPubsubhubbubTest.php
@@ -1,14 +1,17 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Pubsubhubbub;
3
2use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5use Shaarli\Plugin\PluginManager;
6use Shaarli\Router;
3 7
4require_once 'plugins/pubsubhubbub/pubsubhubbub.php'; 8require_once 'plugins/pubsubhubbub/pubsubhubbub.php';
5require_once 'application/Router.php';
6 9
7/** 10/**
8 * Class PluginPubsubhubbubTest 11 * Class PluginPubsubhubbubTest
9 * Unit test for the pubsubhubbub plugin 12 * Unit test for the pubsubhubbub plugin
10 */ 13 */
11class PluginPubsubhubbubTest extends PHPUnit_Framework_TestCase 14class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase
12{ 15{
13 /** 16 /**
14 * @var string Config file path (without extension). 17 * @var string Config file path (without extension).
diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php
index dd632eee..0c61e14a 100644
--- a/tests/plugins/PluginQrcodeTest.php
+++ b/tests/plugins/PluginQrcodeTest.php
@@ -1,16 +1,20 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Qrcode;
3
2/** 4/**
3 * PluginQrcodeTest.php 5 * PluginQrcodeTest.php
4 */ 6 */
5 7
8use Shaarli\Plugin\PluginManager;
9use Shaarli\Router;
10
6require_once 'plugins/qrcode/qrcode.php'; 11require_once 'plugins/qrcode/qrcode.php';
7require_once 'application/Router.php';
8 12
9/** 13/**
10 * Class PluginQrcodeTest 14 * Class PluginQrcodeTest
11 * Unit test for the QR-Code plugin 15 * Unit test for the QR-Code plugin
12 */ 16 */
13class PluginQrcodeTest extends PHPUnit_Framework_TestCase 17class PluginQrcodeTest extends \PHPUnit\Framework\TestCase
14{ 18{
15 /** 19 /**
16 * Reset plugin path 20 * Reset plugin path
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php
index 76b7887e..79751921 100644
--- a/tests/plugins/PluginWallabagTest.php
+++ b/tests/plugins/PluginWallabagTest.php
@@ -1,9 +1,8 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager; 2namespace Shaarli\Plugin\Wallabag;
3 3
4/** 4use Shaarli\Config\ConfigManager;
5 * PluginWallabagTest.php.php 5use Shaarli\Plugin\PluginManager;
6 */
7 6
8require_once 'plugins/wallabag/wallabag.php'; 7require_once 'plugins/wallabag/wallabag.php';
9 8
@@ -11,7 +10,7 @@ require_once 'plugins/wallabag/wallabag.php';
11 * Class PluginWallabagTest 10 * Class PluginWallabagTest
12 * Unit test for the Wallabag plugin 11 * Unit test for the Wallabag plugin
13 */ 12 */
14class PluginWallabagTest extends PHPUnit_Framework_TestCase 13class PluginWallabagTest extends \PHPUnit\Framework\TestCase
15{ 14{
16 /** 15 /**
17 * Reset plugin path 16 * Reset plugin path
diff --git a/tests/plugins/WallabagInstanceTest.php b/tests/plugins/WallabagInstanceTest.php
index 2c466871..a3cd9076 100644
--- a/tests/plugins/WallabagInstanceTest.php
+++ b/tests/plugins/WallabagInstanceTest.php
@@ -1,11 +1,10 @@
1<?php 1<?php
2 2namespace Shaarli\Plugin\Wallabag;
3require_once 'plugins/wallabag/WallabagInstance.php';
4 3
5/** 4/**
6 * Class WallabagInstanceTest 5 * Class WallabagInstanceTest
7 */ 6 */
8class WallabagInstanceTest extends PHPUnit_Framework_TestCase 7class WallabagInstanceTest extends \PHPUnit\Framework\TestCase
9{ 8{
10 /** 9 /**
11 * @var string wallabag url. 10 * @var string wallabag url.