diff --git a/_test/topic_and_tagrefine.test.php b/_test/topic_and_tagrefine.test.php index b466eb3..b6864e1 100644 --- a/_test/topic_and_tagrefine.test.php +++ b/_test/topic_and_tagrefine.test.php @@ -4,6 +4,8 @@ /** * Tests the tagRefine function of the tag plugin + * + * @group plugin_tag */ class plugin_tag_topic_and_tagrefine_test extends DokuWikiTest { private $all_pages = array( @@ -44,7 +46,10 @@ public function testOnlyNegative() { public function testMixed() { $this->assertTopicRefine(array('tagged_page'), 'mytag -negative_tag'); + } + public function testMixedReversed() { + $this->assertTopicRefine(array('tagged_page', 'negative_page', 'third_page'), '-negative_tag mytag'); } public function testAnd() { @@ -97,6 +102,7 @@ private function hasPages($expected, $actual, $msg_prefix = '') { break; } } + $this->assertTrue((count($actual) > 0), $msg_prefix.'Result list is empty!'); $this->assertTrue($found, $msg_prefix.'Page '.$id.' expected but not found in the result'); } diff --git a/_test/topic_sort.test.php b/_test/topic_sort.test.php index aca59f4..767b671 100644 --- a/_test/topic_sort.test.php +++ b/_test/topic_sort.test.php @@ -4,6 +4,8 @@ /** * Tests the tagRefine function of the tag plugin + * + * @group plugin_tag */ class plugin_tag_topic_sorting_test extends DokuWikiTest { private $pages = array( diff --git a/_test/topic_tag.test.php b/_test/topic_tag.test.php index 63908aa..58e1c73 100644 --- a/_test/topic_tag.test.php +++ b/_test/topic_tag.test.php @@ -2,6 +2,8 @@ /** * Tests the basic functionality of the tag and topic syntax + * + * @group plugin_tag */ class topic_tag_test extends DokuWikiTest { function setup() { diff --git a/helper.php b/helper.php index 251e093..75ed517 100644 --- a/helper.php +++ b/helper.php @@ -507,12 +507,39 @@ function _tagCompare($tag1, $tag2) { * @return bool */ function _checkPageTags($pagetags, $tags) { + if (count($tags) == 0) return true; $result = false; - foreach($tags as $tag) { - if ($tag{0} == "+" and !in_array(substr($tag, 1), $pagetags)) $result = false; - if ($tag{0} == "-" and in_array(substr($tag, 1), $pagetags)) $result = false; + $NOTs = 0; + $falseNOTs = 0; + foreach($tags as $i => $tag) { + if ($tag{0} == "+") { + if (!in_array(substr($tag, 1), $pagetags)) { + $result = false; + } else if ($i == 0) { + // This can happen e.g. in case of a tag list like "+tag1" + // or "+tag1 tag2". If the first tag has a '+' handle + // it like a normal tag, so we set $result to 'true'. + // Also solves situations like "+tag1 +tag2". + $result = true; + } + } + if ($tag{0} == "-") { + $NOTs++; + if (in_array(substr($tag, 1), $pagetags)) { + $result = false; + $falseNOTs++; + } else if ($i == 0) { + $result = true; + } + } if (in_array($tag, $pagetags)) $result = true; } + if ($falseNOTs == 0 && count($tags) == $NOTs) { + // None of the NOT(-) tags were found (OK) and ALL + // tags are NOT tags. Set true because there is no + // tag which could cause $result to become true! + $result = true; + } return $result; }