1<?php 2 3namespace dokuwiki\plugin\annotations\test; 4 5use DokuWikiTest; 6 7/** 8 * General tests for the annotations plugin 9 * 10 * @group plugin_annotations 11 * @group plugins 12 */ 13class GeneralTest extends DokuWikiTest 14{ 15 /** 16 * Make sure plugin.info.txt is present and well-formed. 17 */ 18 public function testPluginInfo(): void 19 { 20 $file = __DIR__ . '/../plugin.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('date', $info); 28 $this->assertArrayHasKey('name', $info); 29 $this->assertArrayHasKey('desc', $info); 30 $this->assertArrayHasKey('url', $info); 31 32 $this->assertEquals('annotations', $info['base']); 33 $this->assertMatchesRegularExpression('/^https?:\/\//', $info['url']); 34 $this->assertMatchesRegularExpression('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); 35 $this->assertTrue(false !== strtotime($info['date'])); 36 } 37 38 /** 39 * Every $conf entry in conf/default.php must have a matching $meta entry in 40 * conf/metadata.php (and vice versa). 41 */ 42 public function testPluginConf(): void 43 { 44 $conf_file = __DIR__ . '/../conf/default.php'; 45 $meta_file = __DIR__ . '/../conf/metadata.php'; 46 47 if (!file_exists($conf_file) && !file_exists($meta_file)) { 48 self::markTestSkipped('No config files exist -> skipping test'); 49 } 50 51 if (file_exists($conf_file)) { 52 include($conf_file); 53 } 54 if (file_exists($meta_file)) { 55 include($meta_file); 56 } 57 58 $this->assertEquals( 59 gettype($conf), 60 gettype($meta), 61 'Both conf/default.php and conf/metadata.php have to exist and contain the same keys.' 62 ); 63 64 if ($conf !== null && $meta !== null) { 65 foreach ($conf as $key => $value) { 66 $this->assertArrayHasKey($key, $meta, 'Key $meta[\'' . $key . '\'] missing in conf/metadata.php'); 67 } 68 foreach ($meta as $key => $value) { 69 $this->assertArrayHasKey($key, $conf, 'Key $conf[\'' . $key . '\'] missing in conf/default.php'); 70 } 71 } 72 } 73} 74