xref: /plugin/struct/_test/types/TagTest.php (revision 8fed17f342cc190557a6ce94d1787f9e2f63cb6c)
1<?php
2
3namespace dokuwiki\plugin\struct\test\types;
4
5use dokuwiki\plugin\struct\meta\Schema;
6use dokuwiki\plugin\struct\test\StructTest;
7
8/**
9 * @group plugin_struct
10 * @group plugins
11 */
12class TagTest extends StructTest
13{
14
15    public function setUp(): void
16    {
17        parent::setUp();
18        $this->loadSchemaJSON('tag');
19
20        $this->waitForTick();
21        $this->saveData('page1', 'tag', ['tag' => 'Aragorn', 'tags' => ['Faramir', 'Gollum']], time());
22        $this->saveData('page2', 'tag', ['tag' => 'Eldarion', 'tags' => ['Saruman', 'Arwen']], time());
23        $this->waitForTick();
24        $this->saveData('page1', 'tag', ['tag' => 'Treebeard', 'tags' => ['Frodo', 'Arwen']], time());
25    }
26
27
28    public function test_autocomplete()
29    {
30        global $INPUT;
31        $schema = new Schema('tag');
32
33        // search tag field, should not find Aragon because tag is not in current revision
34        $INPUT->set('search', 'ar');
35        $tag = $schema->findColumn('tag')->getType();
36        $return = $tag->handleAjax();
37        $expect = [
38            ['label' => 'Eldarion', 'value' => 'Eldarion'],
39            ['label' => 'Treebeard', 'value' => 'Treebeard'],
40        ];
41        $this->assertEquals($expect, $return);
42
43        // multi value
44        $INPUT->set('search', 'ar');
45        $tag = $schema->findColumn('tags')->getType();
46        $return = $tag->handleAjax();
47        $expect = [
48            ['label' => 'Arwen', 'value' => 'Arwen'],
49            ['label' => 'Saruman', 'value' => 'Saruman'],
50        ];
51        $this->assertEquals($expect, $return);
52
53    }
54}
55