1<?php 2 3namespace dokuwiki\tpl\mikio\test; 4 5use dokuwiki\template\mikio\mikio; 6use DokuWikiTest; 7 8/** 9 * General tests for the advanced plugin 10 * 11 * @group tpl_bootstrap3 12 * @group plugins 13 */ 14class general_tpl_mikio_test extends DokuWikiTest 15{ 16 17 /** 18 * Simple test to make sure the template.info.txt is in correct format 19 */ 20 public function test_templateinfo() 21 { 22 $file = __DIR__ . '/../template.info.txt'; 23 $this->assertFileExists($file); 24 25 $info = confToHash($file); 26 27 $this->assertArrayHasKey('base', $info); 28 $this->assertArrayHasKey('author', $info); 29 $this->assertArrayHasKey('email', $info); 30 $this->assertArrayHasKey('date', $info); 31 $this->assertArrayHasKey('name', $info); 32 $this->assertArrayHasKey('desc', $info); 33 $this->assertArrayHasKey('url', $info); 34 35 $this->assertEquals('mikio', $info['base']); 36 $this->assertRegExp('/^https?:\/\//', $info['url']); 37 $this->assertTrue(mail_isvalid($info['email'])); 38 $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); 39 $this->assertTrue(false !== strtotime($info['date'])); 40 } 41 42/** 43 * Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in 44 * conf/metadata.php. 45 */ 46 public function test_tpl_conf() 47 { 48 $conf_file = __DIR__ . '/../conf/default.php'; 49 50 if (file_exists($conf_file)) { 51 include $conf_file; 52 } 53 54 $meta_file = __DIR__ . '/../conf/metadata.php'; 55 56 if (file_exists($meta_file)) { 57 include $meta_file; 58 } 59 60 $this->assertEquals( 61 gettype($conf), 62 gettype($meta), 63 'Both conf/default.php and conf/metadata.php have to exist and contain the same keys.' 64 ); 65 66 if (gettype($conf) != 'NULL' && gettype($meta) != 'NULL') { 67 foreach ($conf as $key => $value) { 68 $this->assertArrayHasKey( 69 $key, 70 $meta, 71 'Key $meta[\'' . $key . '\'] missing in conf/metadata.php' 72 ); 73 } 74 75 foreach ($meta as $key => $value) { 76 $this->assertArrayHasKey( 77 $key, 78 $conf, 79 'Key $conf[\'' . $key . '\'] missing in conf/default.php' 80 ); 81 } 82 } 83 } 84 85 public function testSingletonPattern() 86 { 87 $instance1 = mikio::getInstance(); 88 $instance2 = mikio::getInstance(); 89 $this->assertSame($instance1, $instance2); 90 } 91 92 public function testGetConf() 93 { 94 $instance = mikio::getInstance(); 95 $this->assertFalse($instance->getConf('nonexistent_key')); 96 } 97 98 public function testIncludeFooter() 99 { 100 $instance = mikio::getInstance(); 101 $footer = $instance->includeFooter(false); 102 $this->assertIsString($footer); 103 } 104 105 public function testUserCanEdit() 106 { 107 global $INFO; 108 $INFO['isadmin'] = true; 109 $instance = mikio::getInstance(); 110 $this->assertTrue($instance->userCanEdit()); 111 } 112 113 public function testGetPageTitle() 114 { 115 global $conf; 116 $conf['title'] = 'Test Wiki'; 117 $instance = mikio::getInstance(); 118 $title = $instance->getPageTitle(); 119 $this->assertStringContainsString('Test Wiki', $title); 120 } 121} 122