1<?php
2
3/**
4 * Syntax 'keyword_source' tests for the description plugin.
5 *
6 * @group plugin_description
7 * @group plugins
8 *
9 * @author Mark C. Prins <mprins@users.sf.net>
10 *
11 * @noinspection AutoloadingIssuesInspection
12 * @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
13 */
14class syntax_plugin_description_test extends DokuWikiTest
15{
16    protected $pluginsEnabled = array('description');
17
18    /**
19     * copy data and pages.
20     */
21    public static function setUpBeforeClass(): void
22    {
23        parent::setUpBeforeClass();
24        TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/');
25    }
26
27    final public function setUp(): void
28    {
29        global $conf;
30        parent::setUp();
31        $conf['plugin']['description']['keyword_source'] = 'syntax';
32    }
33
34    /**
35     * @throws Exception if anything goes wrong
36     */
37    final public function testHeaderFromSyntax(): void
38    {
39        $request = new TestRequest();
40        $response = $request->get(array('id' => 'description_syntax'));
41
42        // check description meta headers, set from file
43        $this->assertStringContainsString(
44            'Place the page description here',
45            $response->queryHTML('meta[name="description"]')->attr('content')
46        );
47    }
48
49    /**
50     * Test that pages without description syntax don't cause PHP errors
51     * This tests the fix for issue #6
52     *
53     * @throws Exception if anything goes wrong
54     */
55    final public function testNoDescriptionSyntaxNoError(): void
56    {
57        $request = new TestRequest();
58        $response = $request->get(array('id' => 'no_description'));
59
60        // Page should load successfully without PHP errors
61        $this->assertNotNull($response);
62
63        // No description meta tag should be present
64        $metaTags = $response->queryHTML('meta[name="description"]');
65        $this->assertEquals(0, $metaTags->count());
66    }
67}
68