1<?php
2
3if (!defined('DOKU_INC')) die();
4
5/**
6 * Tests the tagRefine function of the tag plugin
7 */
8class plugin_tag_topic_sorting_test extends DokuWikiTest {
9    private $pages = array(
10        'a',
11        'aa',
12        'a:a',
13        'a:aa',
14        'a:a:c',
15        'a:a:b:a',
16        'a:b:c'
17    );
18    /** @var helper_plugin_tag $helper */
19    private $helper;
20
21    public function setUp() : void {
22        global $conf;
23        $this->pluginsEnabled[] = 'tag';
24        parent::setUp();
25
26        $conf['plugin']['tag']['sortkey'] = 'ns';
27
28        $this->helper = plugin_load('helper', 'tag');
29
30
31        foreach ($this->pages as $page) {
32            saveWikiText(
33                $page,
34                '{{tag>mytag}}', 'Test'
35            );
36            idx_addPage($page);
37        }
38    }
39
40    public function test_ns_sort() {
41        $this->assertEquals($this->pages, $this->extract_ids($this->helper->getTopic('', null, 'mytag')));
42    }
43
44
45    /**
46     * Extract the id attribute of the supplied pages
47     *
48     * @param array $pages The pages that shall be used
49     * @return array The ids of the pages
50     */
51    private function extract_ids($pages) {
52        $result = array();
53        foreach ($pages as $page) {
54            $result[] = $page['id'];
55        }
56        return $result;
57    }
58
59}
60