Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed errors in '_checkPageTags()'. #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions _test/topic_and_tagrefine.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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');
}

Expand Down
2 changes: 2 additions & 0 deletions _test/topic_sort.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions _test/topic_tag.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
33 changes: 30 additions & 3 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down