1<?php 2 3namespace dokuwiki\@@PLUGIN_TYPE@@\@@PLUGIN_NAME@@\test; 4 5use DokuWikiTest; 6 7/** 8 * General tests for the @@PLUGIN_NAME@@ @@PLUGIN_TYPE@@ 9 * 10 * @group @@PLUGIN_TYPE@@_@@PLUGIN_NAME@@ 11 * @group @@PLUGIN_TYPE@@s 12 */ 13class GeneralTest extends DokuWikiTest 14{ 15 /** 16 * Simple test to make sure the @@PLUGIN_TYPE@@.info.txt is in correct format 17 */ 18 public function testPluginInfo(): void 19 { 20 $file = __DIR__ . '/../@@PLUGIN_TYPE@@.info.txt'; 21 $this->assertFileExists($file); 22 23 $info = confToHash($file); 24 25 $this->assertArrayHasKey('base', $info); 26 $this->assertArrayHasKey('author', $info); 27 $this->assertArrayHasKey('email', $info); 28 $this->assertArrayHasKey('date', $info); 29 $this->assertArrayHasKey('name', $info); 30 $this->assertArrayHasKey('desc', $info); 31 $this->assertArrayHasKey('url', $info); 32 33 $this->assertEquals('@@PLUGIN_NAME@@', $info['base']); 34 $this->assertRegExp('/^https?:\/\//', $info['url']); 35 $this->assertTrue(mail_isvalid($info['email'])); 36 $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); 37 $this->assertTrue(false !== strtotime($info['date'])); 38 } 39 40 /** 41 * Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in 42 * conf/metadata.php. 43 */ 44 public function testPluginConf(): void 45 { 46 $conf_file = __DIR__ . '/../conf/default.php'; 47 $meta_file = __DIR__ . '/../conf/metadata.php'; 48 49 if (!file_exists($conf_file) && !file_exists($meta_file)) { 50 self::markTestSkipped('No config files exist -> skipping test'); 51 } 52 53 if (file_exists($conf_file)) { 54 include($conf_file); 55 } 56 if (file_exists($meta_file)) { 57 include($meta_file); 58 } 59 60 $this->assertEquals( 61 gettype($conf), 62 gettype($meta), 63 'Both ' . DOKU_PLUGIN . '@@PLUGIN_NAME@@/conf/default.php and ' . DOKU_PLUGIN . '@@PLUGIN_NAME@@/conf/metadata.php have to exist and contain the same keys.' 64 ); 65 66 if ($conf !== null && $meta !== null) { 67 foreach ($conf as $key => $value) { 68 $this->assertArrayHasKey( 69 $key, 70 $meta, 71 'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . '@@PLUGIN_NAME@@/conf/metadata.php' 72 ); 73 } 74 75 foreach ($meta as $key => $value) { 76 $this->assertArrayHasKey( 77 $key, 78 $conf, 79 'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . '@@PLUGIN_NAME@@/conf/default.php' 80 ); 81 } 82 } 83 } 84} 85