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