1696a1b1bSAndreas Gohr<?php 2696a1b1bSAndreas Gohr 3696a1b1bSAndreas Gohrnamespace dokuwiki\plugin\statistics\test; 4696a1b1bSAndreas Gohr 5696a1b1bSAndreas Gohruse DokuWikiTest; 6696a1b1bSAndreas Gohr 7696a1b1bSAndreas Gohr/** 8696a1b1bSAndreas Gohr * General tests for the statistics plugin 9696a1b1bSAndreas Gohr * 10696a1b1bSAndreas Gohr * @group plugin_statistics 11696a1b1bSAndreas Gohr * @group plugins 12696a1b1bSAndreas Gohr */ 13696a1b1bSAndreas Gohrclass GeneralTest extends DokuWikiTest 14696a1b1bSAndreas Gohr{ 15696a1b1bSAndreas Gohr /** 16696a1b1bSAndreas Gohr * Simple test to make sure the plugin.info.txt is in correct format 17696a1b1bSAndreas Gohr */ 18696a1b1bSAndreas Gohr public function testPluginInfo(): void 19696a1b1bSAndreas Gohr { 20696a1b1bSAndreas Gohr $file = __DIR__ . '/../plugin.info.txt'; 21696a1b1bSAndreas Gohr $this->assertFileExists($file); 22696a1b1bSAndreas Gohr 23696a1b1bSAndreas Gohr $info = confToHash($file); 24696a1b1bSAndreas Gohr 25696a1b1bSAndreas Gohr $this->assertArrayHasKey('base', $info); 26696a1b1bSAndreas Gohr $this->assertArrayHasKey('author', $info); 27696a1b1bSAndreas Gohr $this->assertArrayHasKey('email', $info); 28696a1b1bSAndreas Gohr $this->assertArrayHasKey('date', $info); 29696a1b1bSAndreas Gohr $this->assertArrayHasKey('name', $info); 30696a1b1bSAndreas Gohr $this->assertArrayHasKey('desc', $info); 31696a1b1bSAndreas Gohr $this->assertArrayHasKey('url', $info); 32696a1b1bSAndreas Gohr 33696a1b1bSAndreas Gohr $this->assertEquals('statistics', $info['base']); 34*b188870fSAndreas Gohr $this->assertMatchesRegularExpression('/^https?:\/\//', $info['url']); 35696a1b1bSAndreas Gohr $this->assertTrue(mail_isvalid($info['email'])); 36*b188870fSAndreas Gohr $this->assertMatchesRegularExpression('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); 37696a1b1bSAndreas Gohr $this->assertTrue(false !== strtotime($info['date'])); 38696a1b1bSAndreas Gohr } 39696a1b1bSAndreas Gohr 40696a1b1bSAndreas Gohr /** 41696a1b1bSAndreas Gohr * Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in 42696a1b1bSAndreas Gohr * conf/metadata.php. 43696a1b1bSAndreas Gohr */ 44696a1b1bSAndreas Gohr public function testPluginConf(): void 45696a1b1bSAndreas Gohr { 46696a1b1bSAndreas Gohr $conf_file = __DIR__ . '/../conf/default.php'; 47696a1b1bSAndreas Gohr $meta_file = __DIR__ . '/../conf/metadata.php'; 48696a1b1bSAndreas Gohr 49696a1b1bSAndreas Gohr if (!file_exists($conf_file) && !file_exists($meta_file)) { 50696a1b1bSAndreas Gohr self::markTestSkipped('No config files exist -> skipping test'); 51696a1b1bSAndreas Gohr } 52696a1b1bSAndreas Gohr 53696a1b1bSAndreas Gohr if (file_exists($conf_file)) { 54696a1b1bSAndreas Gohr include($conf_file); 55696a1b1bSAndreas Gohr } 56696a1b1bSAndreas Gohr if (file_exists($meta_file)) { 57696a1b1bSAndreas Gohr include($meta_file); 58696a1b1bSAndreas Gohr } 59696a1b1bSAndreas Gohr 60696a1b1bSAndreas Gohr $this->assertEquals( 61696a1b1bSAndreas Gohr gettype($conf), 62696a1b1bSAndreas Gohr gettype($meta), 63696a1b1bSAndreas Gohr 'Both ' . DOKU_PLUGIN . 'statistics/conf/default.php and ' . DOKU_PLUGIN . 'statistics/conf/metadata.php have to exist and contain the same keys.' 64696a1b1bSAndreas Gohr ); 65696a1b1bSAndreas Gohr 66696a1b1bSAndreas Gohr if ($conf !== null && $meta !== null) { 67696a1b1bSAndreas Gohr foreach ($conf as $key => $value) { 68696a1b1bSAndreas Gohr $this->assertArrayHasKey( 69696a1b1bSAndreas Gohr $key, 70696a1b1bSAndreas Gohr $meta, 71696a1b1bSAndreas Gohr 'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'statistics/conf/metadata.php' 72696a1b1bSAndreas Gohr ); 73696a1b1bSAndreas Gohr } 74696a1b1bSAndreas Gohr 75696a1b1bSAndreas Gohr foreach ($meta as $key => $value) { 76696a1b1bSAndreas Gohr $this->assertArrayHasKey( 77696a1b1bSAndreas Gohr $key, 78696a1b1bSAndreas Gohr $conf, 79696a1b1bSAndreas Gohr 'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'statistics/conf/default.php' 80696a1b1bSAndreas Gohr ); 81696a1b1bSAndreas Gohr } 82696a1b1bSAndreas Gohr } 83696a1b1bSAndreas Gohr } 84696a1b1bSAndreas Gohr} 85