5 class media_searchlist_test
extends DokuWikiTest
9 * @var string namespace used for testing
11 protected $upload_ns = 'media_searchlist_test';
16 * @param string $name name of saving file
17 * @param string $copy file used as a content of uploaded file
19 protected function save($name, $copy)
21 $media_id = $this->upload_ns
. ':' . $name;
22 media_save(array('name' => $copy), $media_id, true, AUTH_UPLOAD
, 'copy');
26 * Called for each test
30 function setUp() : void
34 //create some files to search
35 $png = mediaFN('wiki:kind_zu_katze.png');
36 $ogv = mediaFN('wiki:kind_zu_katze.ogv');
37 $webm = mediaFN('wiki:kind_zu_katze.webm');
39 $this->save('a.png', $png);
40 $this->save('aa.png', $png);
41 $this->save('ab.png', $png);
43 $this->save('a.ogv', $ogv);
44 $this->save('aa.ogv', $ogv);
45 $this->save('ab.ogv', $ogv);
47 $this->save('a:a.png', $png);
48 $this->save('b:a.png', $png);
50 $this->save('0.webm', $webm);
55 * Wrap around media_searchlist: return the result
56 * Reset media_printfile static variables afterwards
62 protected function media_searchlist($query, $ns)
65 media_searchlist($query, $ns);
66 $out = ob_get_contents();
75 public function provideSearch()
78 ['a.png', ['a:a.png', 'b:a.png', 'a.png', 'aa.png']], // no globbing
79 ['a*.png', ['a:a.png', 'b:a.png', 'a.png', 'aa.png', 'ab.png']], // globbing asterisk
80 ['*.ogv', ['a.ogv', 'aa.ogv', 'ab.ogv']], // globbing find by ext
81 ['a?.png', ['aa.png', 'ab.png']], // globbing question mark
82 ['a?.*', ['aa.ogv', 'aa.png', 'ab.ogv', 'ab.png']], // globbing question mark and asterisk
83 ['?.png', ['a:a.png', 'b:a.png', 'a.png']], // globbing question mark on the beginning
84 ['??.png', ['aa.png', 'ab.png']], // globbing two question marks on the beginning
85 ['??.*', ['aa.ogv', 'aa.png', 'ab.ogv', 'ab.png']], // globbing two letter file names
86 ['0', ['0.webm']], // zero search
91 * @dataProvider provideSearch
92 * @param string $query The query to use
93 * @param string[] $expected The expected media IDs in the result HTML
96 public function testSearch($query, $expected)
98 $result = $this->media_searchlist($query, $this->upload_ns
);
99 $pq = (new Document())->html($result);
101 $elements = $pq->find('a.mediafile');
103 foreach ($elements as $element) {
104 $actual[] = $element->textContent
;
107 $this->assertEquals(count($expected), count($elements));
108 $this->assertEquals($expected, $actual);