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