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