18fe483c9SAndreas Gohr<?php 28fe483c9SAndreas Gohr 38fe483c9SAndreas Gohrnamespace dokuwiki\plugin\extension\test; 48fe483c9SAndreas Gohr 58fe483c9SAndreas Gohruse dokuwiki\plugin\extension\Extension; 68fe483c9SAndreas Gohruse dokuwiki\plugin\extension\Local; 78fe483c9SAndreas Gohruse DokuWikiTest; 88fe483c9SAndreas Gohr 98fe483c9SAndreas Gohr/** 108fe483c9SAndreas Gohr * Tests for the Local class 118fe483c9SAndreas Gohr * 128fe483c9SAndreas Gohr * @group plugin_extension 138fe483c9SAndreas Gohr * @group plugins 148fe483c9SAndreas Gohr */ 158fe483c9SAndreas Gohrclass LocalTest extends DokuWikiTest 168fe483c9SAndreas Gohr{ 178fe483c9SAndreas Gohr 188fe483c9SAndreas Gohr public function testGetTemplates() 198fe483c9SAndreas Gohr { 208fe483c9SAndreas Gohr $local = new Local(); 218fe483c9SAndreas Gohr $templates = $local->getTemplates(); 228fe483c9SAndreas Gohr 238fe483c9SAndreas Gohr $this->assertIsArray($templates); 248fe483c9SAndreas Gohr foreach ($templates as $template) { 258fe483c9SAndreas Gohr $this->assertInstanceOf(Extension::class, $template); 268fe483c9SAndreas Gohr $this->assertTrue($template->isTemplate()); 278fe483c9SAndreas Gohr } 288fe483c9SAndreas Gohr 298fe483c9SAndreas Gohr $this->assertArrayHasKey('template:dokuwiki', $templates); 308fe483c9SAndreas Gohr } 318fe483c9SAndreas Gohr 328fe483c9SAndreas Gohr public function testGetPlugins() 338fe483c9SAndreas Gohr { 348fe483c9SAndreas Gohr $local = new Local(); 358fe483c9SAndreas Gohr $plugins = $local->getPlugins(); 368fe483c9SAndreas Gohr 378fe483c9SAndreas Gohr $this->assertIsArray($plugins); 388fe483c9SAndreas Gohr foreach ($plugins as $plugin) { 398fe483c9SAndreas Gohr $this->assertInstanceOf(Extension::class, $plugin); 408fe483c9SAndreas Gohr $this->assertFalse($plugin->isTemplate()); 418fe483c9SAndreas Gohr } 428fe483c9SAndreas Gohr 438fe483c9SAndreas Gohr $this->assertArrayHasKey('extension', $plugins); 448fe483c9SAndreas Gohr } 458fe483c9SAndreas Gohr 468fe483c9SAndreas Gohr public function testGetExtensions() 478fe483c9SAndreas Gohr { 488fe483c9SAndreas Gohr $local = new Local(); 498fe483c9SAndreas Gohr $extensions = $local->getExtensions(); 508fe483c9SAndreas Gohr 518fe483c9SAndreas Gohr $this->assertIsArray($extensions); 528fe483c9SAndreas Gohr foreach ($extensions as $extension) { 538fe483c9SAndreas Gohr $this->assertInstanceOf(Extension::class, $extension); 548fe483c9SAndreas Gohr } 558fe483c9SAndreas Gohr 568fe483c9SAndreas Gohr $this->assertArrayHasKey('template:dokuwiki', $extensions); 578fe483c9SAndreas Gohr $this->assertArrayHasKey('extension', $extensions); 588fe483c9SAndreas Gohr } 59*6a8e48edSAndreas Gohr 60*6a8e48edSAndreas Gohr /** 61*6a8e48edSAndreas Gohr * A directory whose name is not a valid extension base (e.g. a leftover 62*6a8e48edSAndreas Gohr * "myplugin (copy)") must be skipped instead of aborting the whole listing. 63*6a8e48edSAndreas Gohr */ 64*6a8e48edSAndreas Gohr public function testReadExtensionsSkipsInvalidDirectory() 65*6a8e48edSAndreas Gohr { 66*6a8e48edSAndreas Gohr $dir = TMP_DIR . '/local-invalid-dir'; 67*6a8e48edSAndreas Gohr mkdir($dir . '/validplugin', 0777, true); 68*6a8e48edSAndreas Gohr mkdir($dir . '/myplugin (copy)', 0777, true); 69*6a8e48edSAndreas Gohr 70*6a8e48edSAndreas Gohr $local = new Local(); 71*6a8e48edSAndreas Gohr $extensions = self::callInaccessibleMethod($local, 'readExtensionsFromDirectory', [$dir]); 72*6a8e48edSAndreas Gohr 73*6a8e48edSAndreas Gohr $this->assertArrayHasKey('validplugin', $extensions); 74*6a8e48edSAndreas Gohr $this->assertArrayNotHasKey('myplugin (copy)', $extensions); 75*6a8e48edSAndreas Gohr } 768fe483c9SAndreas Gohr} 77