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