summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/tag/_test/topic_sort.test.php
blob: aca59f4aa65749f390b5e5886a6f5fcefe4aed9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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;
    }

}