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