1<?php
2// must be run within Dokuwiki
3if (!defined('DOKU_INC')) die();
4
5/**
6 * Test cases for the meta plugin
7 */
8class plugin_meta_rendering_test extends DokuWikiTest {
9
10    public function setUp() : void {
11        $this->pluginsEnabled[] = 'meta';
12        parent::setUp();
13    }
14
15    public function test_meta_description() {
16        $text = "My page content";
17        saveWikiText('description_test', $text, 'Created');
18        self::assertEquals($text, p_get_metadata('description_test', 'description abstract', METADATA_RENDER_UNLIMITED));
19
20        $text .= DOKU_LF . '~~META:description abstract=My abstract~~';
21
22        saveWikiText('description_test', $text, 'Added meta');
23
24        self::assertEquals('My abstract', p_get_metadata('description_test', 'description abstract', METADATA_RENDER_UNLIMITED));
25
26        $text .= DOKU_LF . '~~META:description foobar=bar~~';
27        saveWikiText('description_test', $text, 'Updated meta');
28        self::assertEquals('My abstract', p_get_metadata('description_test', 'description abstract', METADATA_RENDER_UNLIMITED));
29        self::assertEquals('bar', p_get_metadata('description_test', 'description foobar', METADATA_RENDER_UNLIMITED));
30    }
31
32    public function test_meta_description_with_persistent_description() {
33        $text = "My page content";
34        $id = 'description_test';
35        saveWikiText($id, $text, 'Created');
36        self::assertEquals($text, p_get_metadata($id, 'description abstract', METADATA_RENDER_UNLIMITED));
37
38        p_set_metadata($id, array('description' => array('abstract' => 'Persistent description')), false, true);
39        self::assertEquals('Persistent description', p_get_metadata($id, 'description abstract', METADATA_RENDER_UNLIMITED));
40
41        $text .= DOKU_LF . '~~META:description abstract=My abstract~~';
42
43        saveWikiText($id, $text, 'Added meta');
44
45        self::assertEquals('My abstract', p_get_metadata($id, 'description abstract', METADATA_RENDER_UNLIMITED));
46
47        $text .= DOKU_LF . '~~META:description foobar=bar~~';
48        saveWikiText($id, $text, 'Updated meta');
49        self::assertEquals('My abstract', p_get_metadata($id, 'description abstract', METADATA_RENDER_UNLIMITED));
50        self::assertEquals('bar', p_get_metadata($id, 'description foobar', METADATA_RENDER_UNLIMITED));
51    }
52
53    public function test_relation_references_with_link() {
54        $text = "My page with a [[link_target|Link]].";
55        $id = "source";
56
57        saveWikiText($id, $text, 'Created');
58
59        self::assertEquals(array('link_target' => false), p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED));
60
61        $text .= DOKU_LF. "~~META:relation references=foo~~";
62        saveWikiText($id, $text, 'Updated');
63
64        self::assertEquals(array('foo' => false, 'link_target' => false), p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED));
65    }
66
67    public function test_relation_references_without_link() {
68        $text = "My page without a link.";
69        $id = "source";
70
71        saveWikiText($id, $text, 'Created');
72
73        self::assertEquals(null, p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED));
74
75        $text .= DOKU_LF . "~~META:relation references=foo~~";
76        saveWikiText($id, $text, 'Updated');
77
78        self::assertEquals(array('foo' => false), p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED));
79    }
80}
81