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