[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 class media_searchlist_test extends DokuWikiTest 4 { 5 6 /** 7 * @var string namespace used for testing 8 */ 9 protected $upload_ns = 'media_searchlist_test'; 10 11 /** 12 * Save the file 13 * 14 * @param string $name name of saving file 15 * @param string $copy file used as a content of uploaded file 16 */ 17 protected function save($name, $copy) 18 { 19 $media_id = $this->upload_ns . ':' . $name; 20 media_save(array('name' => $copy), $media_id, true, AUTH_UPLOAD, 'copy'); 21 } 22 23 /** 24 * Called for each test 25 * 26 * @throws Exception 27 */ 28 function setUp() : void 29 { 30 parent::setUp(); 31 32 //create some files to search 33 $png = mediaFN('wiki:kind_zu_katze.png'); 34 $ogv = mediaFN('wiki:kind_zu_katze.ogv'); 35 $webm = mediaFN('wiki:kind_zu_katze.webm'); 36 37 $this->save('a.png', $png); 38 $this->save('aa.png', $png); 39 $this->save('ab.png', $png); 40 41 $this->save('a.ogv', $ogv); 42 $this->save('aa.ogv', $ogv); 43 $this->save('ab.ogv', $ogv); 44 45 $this->save('a:a.png', $png); 46 $this->save('b:a.png', $png); 47 48 $this->save('0.webm', $webm); 49 50 } 51 52 /** 53 * Wrap around media_searchlist: return the result 54 * Reset media_printfile static variables afterwards 55 * 56 * @param $query 57 * @param $ns 58 * @return string 59 */ 60 protected function media_searchlist($query, $ns) 61 { 62 ob_start(); 63 media_searchlist($query, $ns); 64 $out = ob_get_contents(); 65 ob_end_clean(); 66 return $out; 67 } 68 69 /** 70 * @return array[] 71 * @see testSearch 72 */ 73 public function provideSearch() 74 { 75 return [ 76 ['a.png', ['a:a.png', 'b:a.png', 'a.png', 'aa.png']], // no globbing 77 ['a*.png', ['a:a.png', 'b:a.png', 'a.png', 'aa.png', 'ab.png']], // globbing asterisk 78 ['*.ogv', ['a.ogv', 'aa.ogv', 'ab.ogv']], // globbing find by ext 79 ['a?.png', ['aa.png', 'ab.png']], // globbing question mark 80 ['a?.*', ['aa.ogv', 'aa.png', 'ab.ogv', 'ab.png']], // globbing question mark and asterisk 81 ['?.png', ['a:a.png', 'b:a.png', 'a.png']], // globbing question mark on the beginning 82 ['??.png', ['aa.png', 'ab.png']], // globbing two question marks on the beginning 83 ['??.*', ['aa.ogv', 'aa.png', 'ab.ogv', 'ab.png']], // globbing two letter file names 84 ['0', ['0.webm']], // zero search 85 ]; 86 } 87 88 /** 89 * @dataProvider provideSearch 90 * @param string $query The query to use 91 * @param string[] $expected The expected media IDs in the result HTML 92 * @throws Exception 93 */ 94 public function testSearch($query, $expected) 95 { 96 $result = $this->media_searchlist($query, $this->upload_ns); 97 $pq = phpQuery::newDocument($result); 98 99 $elements = $pq->find('a.mediafile'); 100 $actual = []; 101 foreach ($elements as $element) { 102 $actual[] = $element->textContent; 103 } 104 105 $this->assertEquals(count($expected), count($elements)); 106 $this->assertEquals($expected, $actual); 107 } 108 109 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body