summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/tag/_test
diff options
context:
space:
mode:
Diffstat (limited to 'platform/www/lib/plugins/tag/_test')
-rw-r--r--platform/www/lib/plugins/tag/_test/topic_and_tagrefine.test.php107
-rw-r--r--platform/www/lib/plugins/tag/_test/topic_sort.test.php59
-rw-r--r--platform/www/lib/plugins/tag/_test/topic_tag.test.php36
3 files changed, 202 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/tag/_test/topic_and_tagrefine.test.php b/platform/www/lib/plugins/tag/_test/topic_and_tagrefine.test.php
new file mode 100644
index 0000000..b466eb3
--- /dev/null
+++ b/platform/www/lib/plugins/tag/_test/topic_and_tagrefine.test.php
@@ -0,0 +1,107 @@
+<?php
+
+if (!defined('DOKU_INC')) die();
+
+/**
+ * Tests the tagRefine function of the tag plugin
+ */
+class plugin_tag_topic_and_tagrefine_test extends DokuWikiTest {
+ private $all_pages = array(
+ 'tagged_page' => array('id' => 'tagged_page'),
+ 'negative_page' => array('id' => 'negative_page'),
+ 'third_page' => array('id' => 'third_page')
+ );
+ public function setUp() {
+ $this->pluginsEnabled[] = 'tag';
+ parent::setUp();
+
+ saveWikiText(
+ 'tagged_page',
+ '{{tag>mytag test2tag}}', 'Test'
+ );
+ saveWikiText(
+ 'negative_page',
+ '{{tag>negative_tag mytag}}',
+ 'Test setup'
+ );
+ saveWikiText(
+ 'third_page',
+ '{{tag>third_tag}}',
+ 'Test setup'
+ );
+ idx_addPage('tagged_page');
+ idx_addPage('negative_page');
+ idx_addPage('third_page');
+ }
+
+ public function testEmptyTag() {
+ $this->assertTopicRefine(array('tagged_page', 'negative_page', 'third_page'), '');
+ }
+
+ public function testOnlyNegative() {
+ $this->assertTopicRefine(array('tagged_page', 'third_page'), '-negative_tag');
+ }
+
+ public function testMixed() {
+ $this->assertTopicRefine(array('tagged_page'), 'mytag -negative_tag');
+
+ }
+
+ public function testAnd() {
+ $this->assertTopicRefine(array('tagged_page'), '+mytag +test2tag');
+ }
+
+ public function testAndOr() {
+ $this->assertTopicRefine(array('tagged_page', 'third_page'), '+test2tag third_tag');
+ }
+
+ public function testOrAnd() {
+ $this->assertTopicRefine(array('tagged_page'), 'mytag +test2tag');
+ }
+
+ public function testRefineDoesntAdd() {
+ /** @var helper_plugin_tag $helper */
+ $helper = plugin_load('helper', 'tag');
+ $pages = $helper->tagRefine(array(), 'mytag');
+ $this->hasPages(array(), $pages, 'Refine with empty input array and "mytag" query: ');
+ }
+
+ /**
+ * Test if the getTopic and the tagRefine function with all pages as input both return the expected pages
+ *
+ * @param array $expected expected page ids
+ * @param string $query the query for the tagRefine/getTopic-functions
+ */
+ private function assertTopicRefine($expected, $query) {
+ /** @var helper_plugin_tag $helper */
+ $helper = plugin_load('helper', 'tag');
+ $pages = $helper->tagRefine($this->all_pages, $query);
+ $this->hasPages($expected, $pages, 'Refine: '.$query.': ');
+ $pages = $helper->getTopic('', '', $query);
+ $this->hasPages($expected, $pages, 'Topic: '.$query.': ');
+ }
+
+ /**
+ * Makes sure that all pages were found and not more
+ *
+ * @param array $expected List of page ids
+ * @param array $actual Result list from getTopic/tagRefine
+ * @param string $msg_prefix A prefix that is prepended to all messages
+ */
+ private function hasPages($expected, $actual, $msg_prefix = '') {
+ foreach ($expected as $id) {
+ $found = false;
+ foreach ($actual as $page) {
+ if ($page['id'] === $id) {
+ $found = true;
+ break;
+ }
+ }
+ $this->assertTrue($found, $msg_prefix.'Page '.$id.' expected but not found in the result');
+ }
+
+ foreach ($actual as $page) {
+ $this->assertTrue(in_array($page['id'], $expected), $msg_prefix.'Page '.$page['id'].' is in the result but wasn\'t expected');
+ }
+ }
+}
diff --git a/platform/www/lib/plugins/tag/_test/topic_sort.test.php b/platform/www/lib/plugins/tag/_test/topic_sort.test.php
new file mode 100644
index 0000000..aca59f4
--- /dev/null
+++ b/platform/www/lib/plugins/tag/_test/topic_sort.test.php
@@ -0,0 +1,59 @@
+<?php
+
+if (!defined('DOKU_INC')) die();
+
+/**
+ * Tests the tagRefine function of the tag plugin
+ */
+class plugin_tag_topic_sorting_test extends DokuWikiTest {
+ private $pages = array(
+ 'a',
+ 'aa',
+ 'a:a',
+ 'a:aa',
+ 'a:a:c',
+ 'a:a:b:a',
+ 'a:b:c'
+ );
+ /** @var helper_plugin_tag $helper */
+ private $helper;
+
+ public function setUp() {
+ global $conf;
+ $this->pluginsEnabled[] = 'tag';
+ parent::setUp();
+
+ $conf['plugin']['tag']['sortkey'] = 'ns';
+
+ $this->helper = plugin_load('helper', 'tag');
+
+
+ foreach ($this->pages as $page) {
+ saveWikiText(
+ $page,
+ '{{tag>mytag}}', 'Test'
+ );
+ idx_addPage($page);
+ }
+ }
+
+ public function test_ns_sort() {
+ $this->assertEquals($this->pages, $this->extract_ids($this->helper->getTopic('', null, 'mytag')));
+ }
+
+
+ /**
+ * Extract the id attribute of the supplied pages
+ *
+ * @param array $pages The pages that shall be used
+ * @return array The ids of the pages
+ */
+ private function extract_ids($pages) {
+ $result = array();
+ foreach ($pages as $page) {
+ $result[] = $page['id'];
+ }
+ return $result;
+ }
+
+}
diff --git a/platform/www/lib/plugins/tag/_test/topic_tag.test.php b/platform/www/lib/plugins/tag/_test/topic_tag.test.php
new file mode 100644
index 0000000..63908aa
--- /dev/null
+++ b/platform/www/lib/plugins/tag/_test/topic_tag.test.php
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * Tests the basic functionality of the tag and topic syntax
+ */
+class topic_tag_test extends DokuWikiTest {
+ function setup() {
+ $this->pluginsEnabled[] = 'tag';
+ $this->pluginsEnabled[] = 'pagelist';
+ parent::setup();
+ }
+
+ function test_topic_tag() {
+ saveWikiText(
+ 'tagged_page',
+ '{{tag>mytag test2tag}}', 'Test'
+ );
+ saveWikiText(
+ 'topic_page',
+ '{{topic>mytag}}'.DOKU_LF.DOKU_LF.'{{tag>topictag mytag}}'.DOKU_LF, 'Test'
+ );
+ idx_addPage('topic_page');
+ idx_addPage('tagged_page');
+ $this->assertContains('tag:topictag', p_wiki_xhtml('topic_page'), 'Page with tag syntax doesn\'t contain tag output');
+ $this->assertNotContains('tag:test2tag', p_wiki_xhtml('topic_page'), 'Page with tag and topic syntax tag which is listed in a page that is listed in the topic syntax but not on the page itself');
+ $this->assertContains('topic_page', p_wiki_xhtml('topic_page'), 'Page with topic and tag syntax doesn\'t list itself in the topic syntax');
+ $this->assertContains('tagged_page', p_wiki_xhtml('topic_page'), 'Page with topic syntax doesn\'t list matching page');
+ $this->assertContains('tag:mytag', p_wiki_xhtml('tagged_page'), 'Page with tag syntax doesn\'t contain tag output');
+ $this->assertContains('tag:test2tag', p_wiki_xhtml('tagged_page'), 'Page with tag syntax doesn\'t contain tag output');
+ $this->assertNotContains('tag:topictag', p_wiki_xhtml('tagged_page'), 'Page with tag syntax contains tag from a page in which it is listed in the topic syntax');
+ saveWikiText('tagged_page', '{{tag>test2tag}}', 'Deleted mytag');
+ $this->assertNotContains('tagged_page', p_wiki_xhtml('topic_page'), 'Page that no longer contains the tag is still listed in the topic syntax (caching problems?)');
+ $this->assertNotContains('tag:mytag', p_wiki_xhtml('tagged_page'), 'Removed tag is still listed in XHTML output');
+
+ }
+}