1<?php 2 3// must be run within Dokuwiki 4if (!defined('DOKU_INC')) die(); 5 6/** 7 * Test cases for the move plugin 8 * 9 * @group plugin_move 10 * @group plugins 11 */ 12class plugin_move_mediamove_test extends DokuWikiTest { 13 14 public function setUp(): void { 15 $this->pluginsEnabled[] = 'move'; 16 parent::setUp(); 17 } 18 19 /** 20 * @group slow 21 */ 22 public function test_movePageWithRelativeMedia() { 23 $src = 'mediareltest:foo'; 24 saveWikiText($src, 25 '{{ myimage.png}} [[:start|{{ testimage.png?200x800 }}]] [[bar|{{testimage.gif?400x200}}]] 26[[doku>wiki:dokuwiki|{{wiki:logo.png}}]] [[http://www.example.com|{{testimage.jpg}}]] 27[[doku>wiki:foo|{{foo.gif?200x3000}}]]', 'Test setup'); 28 idx_addPage($src); 29 30 $dst = 'foo'; 31 32 /** @var helper_plugin_move_op $move */ 33 $move = plugin_load('helper', 'move_op'); 34 $this->assertTrue($move->movePage($src, $dst)); 35 36 $this->assertEquals('{{ mediareltest:myimage.png}} [[:start|{{ mediareltest:testimage.png?200x800 }}]] [[mediareltest:bar|{{mediareltest:testimage.gif?400x200}}]] 37[[doku>wiki:dokuwiki|{{wiki:logo.png}}]] [[http://www.example.com|{{mediareltest:testimage.jpg}}]] 38[[doku>wiki:foo|{{mediareltest:foo.gif?200x3000}}]]', rawWiki('foo')); 39 } 40 41 /** 42 * @group slow 43 */ 44 public function test_moveSingleMedia() { 45 global $AUTH_ACL; 46 $AUTH_ACL[] = "wiki:*\t@ALL\t16"; 47 $AUTH_ACL[] = "foobar:*\t@ALL\t8"; 48 49 saveWikiText('wiki:movetest', '{{wiki:dokuwiki-128.png?200}}', 'Test initialized'); 50 idx_addPage('wiki:movetest'); 51 52 $src = 'wiki:dokuwiki-128.png'; 53 $dst = 'foobar:logo.png'; 54 55 /** @var helper_plugin_move_op $move */ 56 $move = plugin_load('helper', 'move_op'); 57 $this->assertTrue($move->moveMedia($src, $dst)); 58 59 $this->assertTrue(@file_exists(mediaFn('foobar:logo.png'))); 60 61 $this->assertEquals('{{foobar:logo.png?200}}', rawWiki('wiki:movetest')); 62 } 63 64 /** 65 * @group slow 66 */ 67 public function test_moveSingleMedia_colonstart() { 68 global $AUTH_ACL; 69 $AUTH_ACL[] = "wiki:*\t@ALL\t16"; 70 $AUTH_ACL[] = "foobar:*\t@ALL\t16"; 71 $AUTH_ACL[] = "*\t@ALL\t8"; 72 73 $filepath = DOKU_TMP_DATA.'media/wiki/testimage.png'; 74 io_makeFileDir($filepath); 75 io_saveFile($filepath,''); 76 77 saveWikiText('wiki:movetest', '{{:wiki:testimage.png?200}}', 'Test initialized'); 78 idx_addPage('wiki:movetest'); 79 80 $src = 'wiki:testimage.png'; 81 $dst = 'foobar:logo_2.png'; 82 83 /** @var helper_plugin_move_op $move */ 84 $move = plugin_load('helper', 'move_op'); 85 $this->assertTrue($move->moveMedia($src, $dst)); 86 87 $this->assertTrue(@file_exists(mediaFn('foobar:logo_2.png'))); 88 89 $this->assertEquals('{{foobar:logo_2.png?200}}', rawWiki('wiki:movetest')); 90 91 $this->assertTrue($move->moveMedia($dst, 'logo_2.png')); 92 93 $this->assertTrue(@file_exists(mediaFn('logo_2.png'))); 94 95 $this->assertEquals('{{:logo_2.png?200}}', rawWiki('wiki:movetest')); 96 } 97 98 /** 99 * @group slow 100 */ 101 public function test_moveSingleMedia_space() { 102 global $AUTH_ACL; 103 $AUTH_ACL[] = "wiki:*\t@ALL\t16"; 104 $AUTH_ACL[] = "foobar:*\t@ALL\t8"; 105 106 $filepath = DOKU_TMP_DATA.'media/wiki/foo/test_image.png'; 107 io_makeFileDir($filepath); 108 io_saveFile($filepath,''); 109 110 saveWikiText('wiki:movetest', '{{:wiki:foo:test image.png?200|test image}}', 'Test initialized'); 111 idx_addPage('wiki:movetest'); 112 113 $src = 'wiki:foo:test_image.png'; 114 $dst = 'wiki:foobar:test_image.png'; 115 116 /** @var helper_plugin_move_op $move */ 117 $move = plugin_load('helper', 'move_op'); 118 $this->assertTrue($move->moveMedia($src, $dst)); 119 120 $this->assertTrue(@file_exists(mediaFn('wiki:foobar:test_image.png'))); 121 122 $this->assertEquals('{{wiki:foobar:test_image.png?200|test image}}', rawWiki('wiki:movetest')); 123 } 124} 125