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