1<?php
2
3
4/**
5 * Test the api plugin
6 *
7 * @group plugin_api
8 * @group plugins
9 * @uses \PHPUnit\Framework\TestCase
10 */
11include_once (__DIR__.'/utils.php');
12class dokuwiki_plugin_api_test extends DokuWikiTest
13{
14
15    protected $pluginsEnabled = array(action_plugin_api::PLUGIN_NAME);
16
17    static function setUpBeforeClass(): void
18    {
19
20        dokuwiki_plugin_api_util::init();
21
22    }
23
24    /**
25     * Control the plugin.info.txt
26     */
27    public function test_pluginInfoTxt()
28    {
29
30        $info = dokuwiki_plugin_api_util::$PLUGIN_INFO;
31
32        $this->assertArrayHasKey('base', $info);
33        $this->assertEquals(action_plugin_api::PLUGIN_NAME, $info['base']);
34
35        $this->assertArrayHasKey('author', $info);
36        $this->assertArrayHasKey('name', $info);
37        $this->assertArrayHasKey('desc', $info);
38
39        $this->assertArrayHasKey('date', $info);
40        $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
41        $this->assertTrue(false !== strtotime($info['date']));
42
43
44        $this->assertArrayHasKey('url', $info);
45        $this->assertRegExp('/^https?:\/\//', $info['url']);
46
47        $this->assertArrayHasKey('email', $info);
48        $this->assertTrue(mail_isvalid($info['email']));
49
50
51    }
52
53    /**
54     * test if the plugin is loaded.
55     */
56    public function test_plugin_isLoaded()
57    {
58        global $plugin_controller;
59        $this->assertTrue(
60            in_array(
61                action_plugin_api::PLUGIN_NAME,
62                $plugin_controller->getList()),
63            action_plugin_api::PLUGIN_NAME . " plugin is loaded"
64        );
65    }
66
67    /**
68     * Test a call without any parameters
69     *
70     */
71    public function test_plugin_base_no_function()
72    {
73
74        $expected = array(
75            "api" => action_plugin_api::PLUGIN_NAME,
76            "version" => dokuwiki_plugin_api_util::$PLUGIN_INFO['date']
77        );
78
79        $testResponse = dokuwiki_plugin_api_util::getRequest();
80        $actualData = dokuwiki_plugin_api_util::$JSON->decode($testResponse->getContent());
81        $this->assertEquals($expected,$actualData,"Information about the API is given");
82
83    }
84
85
86}
87