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