From 15170b516429341ae8e1a9ad2111be5ef90bf6aa Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 2 Aug 2016 11:02:20 +0200 Subject: Parse plugin parameters description with the PluginManager Plugin parameter can contain a description in their meta file under the key: parameter.="" --- tests/plugins/test/test.meta | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/plugins') diff --git a/tests/plugins/test/test.meta b/tests/plugins/test/test.meta index ab999ed4..26f243f0 100644 --- a/tests/plugins/test/test.meta +++ b/tests/plugins/test/test.meta @@ -1,2 +1,4 @@ description="test plugin" -parameters="pop;hip" \ No newline at end of file +parameters="pop;hip" +parameter.pop="pop description" +parameter.hip= \ No newline at end of file -- cgit v1.2.3 From 5e148f8a529abf72256ef74ed149d56a5b27bd72 Mon Sep 17 00:00:00 2001 From: Teromene Date: Tue, 11 Oct 2016 16:37:42 +0100 Subject: Archive.org plugin: do not propose archival of private notes Fixes #637 --- tests/plugins/PluginArchiveorgTest.php | 102 +++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 4 deletions(-) (limited to 'tests/plugins') diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php index dbc52bc8..4daa4c9d 100644 --- a/tests/plugins/PluginArchiveorgTest.php +++ b/tests/plugins/PluginArchiveorgTest.php @@ -7,8 +7,8 @@ require_once 'plugins/archiveorg/archiveorg.php'; /** - * Class PlugQrcodeTest - * Unit test for the QR-Code plugin + * Class PluginArchiveorgTest + * Unit test for the archiveorg plugin */ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase { @@ -21,21 +21,25 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase } /** - * Test render_linklist hook. + * Test render_linklist hook on external links. */ - function testArchiveorgLinklist() + function testArchiveorgLinklistOnExternalLinks() { $str = 'http://randomstr.com/test'; + $data = array( 'title' => $str, 'links' => array( array( 'url' => $str, + 'private' => 0, + 'real_url' => $str ) ) ); $data = hook_archiveorg_render_linklist($data); + $link = $data['links'][0]; // data shouldn't be altered $this->assertEquals($str, $data['title']); @@ -44,5 +48,95 @@ class PluginArchiveorgTest extends PHPUnit_Framework_TestCase // plugin data $this->assertEquals(1, count($link['link_plugin'])); $this->assertNotFalse(strpos($link['link_plugin'][0], $str)); + + } + + /** + * Test render_linklist hook on internal links. + */ + function testArchiveorgLinklistOnInternalLinks() + { + $internalLink1 = 'http://shaarli.shaarli/?qvMAqg'; + $internalLinkRealURL1 = '?qvMAqg'; + + $internalLink2 = 'http://shaarli.shaarli/?2_7zww'; + $internalLinkRealURL2 = '?2_7zww'; + + $internalLink3 = 'http://shaarli.shaarli/?z7u-_Q'; + $internalLinkRealURL3 = '?z7u-_Q'; + + $data = array( + 'title' => $internalLink1, + 'links' => array( + array( + 'url' => $internalLink1, + 'private' => 0, + 'real_url' => $internalLinkRealURL1 + ), + array( + 'url' => $internalLink1, + 'private' => 1, + 'real_url' => $internalLinkRealURL1 + ), + array( + 'url' => $internalLink2, + 'private' => 0, + 'real_url' => $internalLinkRealURL2 + ), + array( + 'url' => $internalLink2, + 'private' => 1, + 'real_url' => $internalLinkRealURL2 + ), + array( + 'url' => $internalLink3, + 'private' => 0, + 'real_url' => $internalLinkRealURL3 + ), + array( + 'url' => $internalLink3, + 'private' => 1, + 'real_url' => $internalLinkRealURL3 + ) + ) + ); + + + $data = hook_archiveorg_render_linklist($data); + + // Case n°1: first link type, public + $link = $data['links'][0]; + + $this->assertEquals(1, count($link['link_plugin'])); + $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink1)); + + // Case n°2: first link type, private + $link = $data['links'][1]; + + $this->assertArrayNotHasKey('link_plugin', $link); + + // Case n°3: second link type, public + $link = $data['links'][2]; + + $this->assertEquals(1, count($link['link_plugin'])); + $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink2)); + + // Case n°4: second link type, private + $link = $data['links'][3]; + + $this->assertArrayNotHasKey('link_plugin', $link); + + // Case n°5: third link type, public + $link = $data['links'][4]; + + $this->assertEquals(1, count($link['link_plugin'])); + $this->assertNotFalse(strpos($link['link_plugin'][0], $internalLink3)); + + // Case n°6: third link type, private + $link = $data['links'][5]; + + $this->assertArrayNotHasKey('link_plugin', $link); + } + } -- cgit v1.2.3 From 7fde6de1212323418401c15efba06026c704ca87 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 14 Oct 2016 13:22:58 +0200 Subject: New init function for plugins, supports errors reporting All plugins can optionally add an init function named `pluginname_init()` which is called when the plugin is loaded. This function is aware of the config, and can return initialization errors, which are displayed in the header template. Note that the previous error system hack no longer work. --- tests/plugins/PluginReadityourselfTest.php | 23 +++++++++++++++++++++-- tests/plugins/PluginWallabagTest.php | 23 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) (limited to 'tests/plugins') diff --git a/tests/plugins/PluginReadityourselfTest.php b/tests/plugins/PluginReadityourselfTest.php index d73e666a..532db146 100644 --- a/tests/plugins/PluginReadityourselfTest.php +++ b/tests/plugins/PluginReadityourselfTest.php @@ -4,8 +4,6 @@ * PluginReadityourselfTest.php.php */ -// FIXME! add an init method. -$conf = new ConfigManager(''); require_once 'plugins/readityourself/readityourself.php'; /** @@ -22,6 +20,27 @@ class PluginReadityourselfTest extends PHPUnit_Framework_TestCase PluginManager::$PLUGINS_PATH = 'plugins'; } + /** + * Test Readityourself init without errors. + */ + function testReadityourselfInitNoError() + { + $conf = new ConfigManager(''); + $conf->set('plugins.READITYOUSELF_URL', 'value'); + $errors = readityourself_init($conf); + $this->assertEmpty($errors); + } + + /** + * Test Readityourself init with errors. + */ + function testReadityourselfInitError() + { + $conf = new ConfigManager(''); + $errors = readityourself_init($conf); + $this->assertNotEmpty($errors); + } + /** * Test render_linklist hook. */ diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php index 302ee296..2c268cbd 100644 --- a/tests/plugins/PluginWallabagTest.php +++ b/tests/plugins/PluginWallabagTest.php @@ -4,8 +4,6 @@ * PluginWallabagTest.php.php */ -// FIXME! add an init method. -$conf = new ConfigManager(''); require_once 'plugins/wallabag/wallabag.php'; /** @@ -22,6 +20,27 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase PluginManager::$PLUGINS_PATH = 'plugins'; } + /** + * Test wallabag init without errors. + */ + function testWallabagInitNoError() + { + $conf = new ConfigManager(''); + $conf->set('plugins.WALLABAG_URL', 'value'); + $errors = wallabag_init($conf); + $this->assertEmpty($errors); + } + + /** + * Test wallabag init with errors. + */ + function testWallabagInitError() + { + $conf = new ConfigManager(''); + $errors = wallabag_init($conf); + $this->assertNotEmpty($errors); + } + /** * Test render_linklist hook. */ -- cgit v1.2.3 From bf26e7ebcb5ee69523b93a5ec7b7a65b39acb916 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 3 Oct 2016 09:43:49 +0200 Subject: Isso comments plugin Use Isso client to let visitors comments on permalinks --- tests/plugins/PluginIssoTest.php | 136 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 tests/plugins/PluginIssoTest.php (limited to 'tests/plugins') diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php new file mode 100644 index 00000000..1f545c7d --- /dev/null +++ b/tests/plugins/PluginIssoTest.php @@ -0,0 +1,136 @@ +set('plugins.ISSO_SERVER', 'value'); + $errors = isso_init($conf); + $this->assertEmpty($errors); + } + + /** + * Test Isso init with errors. + */ + function testWallabagInitError() + { + $conf = new ConfigManager(''); + $errors = isso_init($conf); + $this->assertNotEmpty($errors); + } + + /** + * Test render_linklist hook with valid settings to display the comment form. + */ + function testIssoDisplayed() + { + $conf = new ConfigManager(''); + $conf->set('plugins.ISSO_SERVER', 'value'); + + $str = 'http://randomstr.com/test'; + $data = array( + 'title' => $str, + 'links' => array( + array( + 'url' => $str, + 'linkdate' => 'abc', + ) + ) + ); + + $data = hook_isso_render_linklist($data, $conf); + + // data shouldn't be altered + $this->assertEquals($str, $data['title']); + $this->assertEquals($str, $data['links'][0]['url']); + + // plugin data + $this->assertEquals(1, count($data['plugin_end_zone'])); + $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'abc')); + $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js')); + } + + /** + * Test isso plugin when multiple links are displayed (shouldn't be displayed). + */ + function testIssoMultipleLinks() + { + $conf = new ConfigManager(''); + $conf->set('plugins.ISSO_SERVER', 'value'); + + $str = 'http://randomstr.com/test'; + $data = array( + 'title' => $str, + 'links' => array( + array( + 'url' => $str, + 'linkdate' => 'abc', + ), + array( + 'url' => $str . '2', + 'linkdate' => 'abc2', + ), + ) + ); + + $processed = hook_isso_render_linklist($data, $conf); + // data shouldn't be altered + $this->assertEquals($data, $processed); + } + + /** + * Test isso plugin when using search (shouldn't be displayed). + */ + function testIssoNotDisplayedWhenSearch() + { + $conf = new ConfigManager(''); + $conf->set('plugins.ISSO_SERVER', 'value'); + + $str = 'http://randomstr.com/test'; + $data = array( + 'title' => $str, + 'links' => array( + array( + 'url' => $str, + 'linkdate' => 'abc', + ) + ), + 'search_term' => $str + ); + + $processed = hook_isso_render_linklist($data, $conf); + + // data shouldn't be altered + $this->assertEquals($data, $processed); + } + + /** + * Test isso plugin without server configuration (shouldn't be displayed). + */ + function testIssoWithoutConf() + { + $data = 'abc'; + $conf = new ConfigManager(''); + $processed = hook_isso_render_linklist($data, $conf); + $this->assertEquals($data, $processed); + } +} -- cgit v1.2.3 From c5941f316a49c94eff354b63e75b3add98ac4aea Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 21 Oct 2016 12:38:38 +0200 Subject: Fix an issue with links not being reversed in code blocks Fixes #672 + Markdown to HTML unit test --- tests/plugins/PluginMarkdownTest.php | 13 +++++++++++++ tests/plugins/resources/markdown.html | 24 ++++++++++++++++++++++++ tests/plugins/resources/markdown.md | 24 ++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/plugins/resources/markdown.html create mode 100644 tests/plugins/resources/markdown.md (limited to 'tests/plugins') diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index 3593a556..12bdda24 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php @@ -151,4 +151,17 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase $data = hook_markdown_render_daily($data); $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']); } + + /** + * Test hashtag links processed with markdown. + */ + function testMarkdownHashtagLinks() + { + $md = file_get_contents('tests/plugins/resources/markdown.md'); + $md = format_description($md); + $html = file_get_contents('tests/plugins/resources/markdown.html'); + + $data = process_markdown($md); + $this->assertEquals($html, $data); + } } diff --git a/tests/plugins/resources/markdown.html b/tests/plugins/resources/markdown.html new file mode 100644 index 00000000..c0fbe7f4 --- /dev/null +++ b/tests/plugins/resources/markdown.html @@ -0,0 +1,24 @@ +
+
    +
  1. zero +
      +
    1. two
    2. +
    3. three
    4. +
    5. four
    6. +
    7. foo #foobar
    8. +
  2. +
+

#foobar foo lol #foo #bar

+

fsdfs http://link.tld #foobar http://link.tld

+
http://link.tld #foobar
+next #foo
+

Block:

+
lorem ipsum #foobar http://link.tld
+#foobar http://link.tld
\ No newline at end of file diff --git a/tests/plugins/resources/markdown.md b/tests/plugins/resources/markdown.md new file mode 100644 index 00000000..0b8be7c5 --- /dev/null +++ b/tests/plugins/resources/markdown.md @@ -0,0 +1,24 @@ +* test: + * [zero](http://link.tld) + + [two](http://link.tld) + - [three](http://link.tld) + +1. [zero](http://link.tld) + 2. [two](http://link.tld) + 3. [three](http://link.tld) + 4. [four](http://link.tld) + 5. foo #foobar + +#foobar foo `lol #foo` #bar + +fsdfs http://link.tld #foobar `http://link.tld` + + http://link.tld #foobar + next #foo + +Block: + +``` +lorem ipsum #foobar http://link.tld +#foobar http://link.tld +``` \ No newline at end of file -- cgit v1.2.3 From 266e3fe5c8961aaf089bad16b9e4c54de1aaff40 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 13 Nov 2016 16:51:21 +0100 Subject: Markdown: fixes feed rendering with nomarkdown tag * make sure we match exactly `nomarkdown` tag * pass the whole link data to stripNoMarkdownTag() to: * strip the noMD tag in taglist (array) * strip the tag in tags (string) Fixes #689 tmp --- tests/plugins/PluginMarkdownTest.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'tests/plugins') diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index 12bdda24..17ef2280 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php @@ -8,8 +8,8 @@ require_once 'application/Utils.php'; require_once 'plugins/markdown/markdown.php'; /** - * Class PlugQrcodeTest - * Unit test for the QR-Code plugin + * Class PluginMarkdownTest + * Unit test for the Markdown plugin */ class PluginMarkdownTest extends PHPUnit_Framework_TestCase { @@ -130,8 +130,11 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase )) ); - $data = hook_markdown_render_linklist($data); - $this->assertEquals($str, $data['links'][0]['description']); + $processed = hook_markdown_render_linklist($data); + $this->assertEquals($str, $processed['links'][0]['description']); + + $processed = hook_markdown_render_feed($data); + $this->assertEquals($str, $processed['links'][0]['description']); $data = array( // Columns data @@ -152,6 +155,24 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']); } + /** + * Test that a close value to nomarkdown is not understand as nomarkdown (previous value `.nomarkdown`). + */ + function testNoMarkdownNotExcactlyMatching() + { + $str = 'All _work_ and `no play` makes Jack a *dull* boy.'; + $data = array( + 'links' => array(array( + 'description' => $str, + 'tags' => '.' . NO_MD_TAG, + 'taglist' => array('.'. NO_MD_TAG), + )) + ); + + $data = hook_markdown_render_feed($data); + $this->assertContains('', $data['links'][0]['description']); + } + /** * Test hashtag links processed with markdown. */ -- cgit v1.2.3 From c3dfd8995921083ff7250c25d0b6ab1184b91aff Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 28 Nov 2016 16:17:25 +0100 Subject: Unit Test for the new ID system --- tests/plugins/PluginIssoTest.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tests/plugins') diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php index 1f545c7d..ea86a05c 100644 --- a/tests/plugins/PluginIssoTest.php +++ b/tests/plugins/PluginIssoTest.php @@ -47,12 +47,13 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase $conf->set('plugins.ISSO_SERVER', 'value'); $str = 'http://randomstr.com/test'; + $date = '20161118_100001'; $data = array( 'title' => $str, 'links' => array( array( 'url' => $str, - 'linkdate' => 'abc', + 'created' => DateTime::createFromFormat('Ymd_His', $date), ) ) ); @@ -65,7 +66,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase // plugin data $this->assertEquals(1, count($data['plugin_end_zone'])); - $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'abc')); + $this->assertNotFalse(strpos($data['plugin_end_zone'][0], $date)); $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js')); } @@ -78,16 +79,18 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase $conf->set('plugins.ISSO_SERVER', 'value'); $str = 'http://randomstr.com/test'; + $date1 = '20161118_100001'; + $date2 = '20161118_100002'; $data = array( 'title' => $str, 'links' => array( array( 'url' => $str, - 'linkdate' => 'abc', + 'created' => DateTime::createFromFormat('Ymd_His', $date1), ), array( 'url' => $str . '2', - 'linkdate' => 'abc2', + 'created' => DateTime::createFromFormat('Ymd_His', $date2), ), ) ); @@ -106,12 +109,13 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase $conf->set('plugins.ISSO_SERVER', 'value'); $str = 'http://randomstr.com/test'; + $date = '20161118_100001'; $data = array( 'title' => $str, 'links' => array( array( 'url' => $str, - 'linkdate' => 'abc', + 'created' => DateTime::createFromFormat('Ymd_His', $date), ) ), 'search_term' => $str -- cgit v1.2.3 From d592daea8343bb4dfecff5d97e93699581ccc58c Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 28 Nov 2016 18:24:15 +0100 Subject: Add a persistent 'shorturl' key to all links All existing link will keep their permalinks. New links will have smallhash generated with date+id. The purpose of this is to avoid collision between links due to their creation date. --- tests/plugins/PluginIssoTest.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'tests/plugins') diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php index ea86a05c..6b7904dd 100644 --- a/tests/plugins/PluginIssoTest.php +++ b/tests/plugins/PluginIssoTest.php @@ -52,8 +52,9 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase 'title' => $str, 'links' => array( array( + 'id' => 12, 'url' => $str, - 'created' => DateTime::createFromFormat('Ymd_His', $date), + 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date), ) ) ); @@ -66,7 +67,14 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase // plugin data $this->assertEquals(1, count($data['plugin_end_zone'])); - $this->assertNotFalse(strpos($data['plugin_end_zone'][0], $date)); + $this->assertNotFalse(strpos( + $data['plugin_end_zone'][0], + 'data-isso-id="'. $data['links'][0]['id'] .'"' + )); + $this->assertNotFalse(strpos( + $data['plugin_end_zone'][0], + 'data-title="'. $data['links'][0]['id'] .'"' + )); $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js')); } @@ -85,12 +93,14 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase 'title' => $str, 'links' => array( array( + 'id' => 12, 'url' => $str, - 'created' => DateTime::createFromFormat('Ymd_His', $date1), + 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1), ), array( + 'id' => 13, 'url' => $str . '2', - 'created' => DateTime::createFromFormat('Ymd_His', $date2), + 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2), ), ) ); @@ -114,8 +124,9 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase 'title' => $str, 'links' => array( array( + 'id' => 12, 'url' => $str, - 'created' => DateTime::createFromFormat('Ymd_His', $date), + 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date), ) ), 'search_term' => $str -- cgit v1.2.3