1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5use dokuwiki\plugin\struct\meta;
6
7/**
8 * Tests for the move plugin support of the struct plugin
9 *
10 * @group plugin_struct
11 * @group plugins
12 *
13 * @covers action_plugin_struct_move
14 *
15 *
16 */
17class move_struct_test extends StructTest
18{
19
20    protected $data1 = array(
21        'page' => 'wiki:syntax',
22        'pages' => array('wiki:syntax', 'wiki:welcome'),
23        'lookup' => '["page1",0]',
24        'lookups' => ['["page1",0]', '["page2",0]'],
25        'media' => 'wiki:logo.png',
26        'medias' => array('wiki:logo.png'),
27        'title' => 'wiki:syntax',
28        'titles' => array('wiki:syntax', 'wiki:welcome')
29    );
30
31    protected $data2 = array(
32        'page' => 'wiki:syntax#something',
33        'pages' => array('wiki:syntax#something', 'wiki:welcome#something'),
34        'lookup' => '["page1",0]',
35        'lookups' => ['["page1",0]', '["page2",0]'],
36        'media' => 'wiki:logo.png',
37        'medias' => array('wiki:logo.png'),
38        'title' => 'wiki:syntax#something',
39        'titles' => array('wiki:syntax#something', 'wiki:welcome#something')
40    );
41
42    protected $empty = array(
43        'page' => '',
44        'pages' => array(),
45        'lookup' => '',
46        'lookups' => array(),
47        'media' => '',
48        'medias' => array(),
49        'title' => '',
50        'titles' => array()
51    );
52
53    public function setUp(): void
54    {
55        parent::setUp();
56        $this->loadSchemaJSON('moves');
57
58        $schemaData = meta\AccessTable::getPageAccess('moves', 'page1');
59        $schemaData->saveData($this->data1);
60
61        $schemaData = meta\AccessTable::getPageAccess('moves', 'page2');
62        $schemaData->saveData($this->data2);
63    }
64
65    public function test_selfmove()
66    {
67        // fake move event
68        $evdata = array('src_id' => 'page1', 'dst_id' => 'page3');
69        $event = new \Doku_Event('PLUGIN_MOVE_PAGE_RENAME', $evdata);
70        $event->trigger();
71
72        // old page should be gone
73        $schemaData = meta\AccessTable::getPageAccess('moves', 'page1');
74        $this->assertEquals($this->empty, $schemaData->getDataArray());
75
76        // new page should have adjusted data
77        $data = $this->data1;
78        $data['lookup'] = '["page3",0]';
79        $data['lookups'] = ['["page3",0]', '["page2",0]'];
80        $schemaData = meta\AccessTable::getPageAccess('moves', 'page3');
81        $this->assertEquals($data, $schemaData->getDataArray());
82
83        // other page should have adjusted lookups
84        $data = $this->data2;
85        $data['lookup'] = '["page3",0]';
86        $data['lookups'] = ['["page3",0]', '["page2",0]'];
87        $schemaData = meta\AccessTable::getPageAccess('moves', 'page2');
88        $this->assertEquals($data, $schemaData->getDataArray());
89    }
90
91    public function test_pagemove()
92    {
93        // fake move event
94        $evdata = array('src_id' => 'wiki:syntax', 'dst_id' => 'foobar');
95        $event = new \Doku_Event('PLUGIN_MOVE_PAGE_RENAME', $evdata);
96        $event->trigger();
97
98        $data = $this->data1;
99        $data['page'] = 'foobar';
100        $data['pages'] = array('foobar', 'wiki:welcome');
101        $data['title'] = 'foobar';
102        $data['titles'] = array('foobar', 'wiki:welcome');
103        $schemaData = meta\AccessTable::getPageAccess('moves', 'page1');
104        $this->assertEquals($data, $schemaData->getDataArray());
105
106        $data = $this->data2;
107        $data['page'] = 'foobar#something';
108        $data['pages'] = array('foobar#something', 'wiki:welcome#something');
109        $data['title'] = 'foobar#something';
110        $data['titles'] = array('foobar#something', 'wiki:welcome#something');
111        $schemaData = meta\AccessTable::getPageAccess('moves', 'page2');
112        $this->assertEquals($data, $schemaData->getDataArray());
113    }
114
115    public function test_mediamove()
116    {
117        // fake move event
118        $evdata = array('src_id' => 'wiki:logo.png', 'dst_id' => 'foobar.png');
119        $event = new \Doku_Event('PLUGIN_MOVE_MEDIA_RENAME', $evdata);
120        $event->trigger();
121
122        $data = $this->data1;
123        $data['media'] = 'foobar.png';
124        $data['medias'] = array('foobar.png');
125        $schemaData = meta\AccessTable::getPageAccess('moves', 'page1');
126        $this->assertEquals($data, $schemaData->getDataArray());
127
128        $data = $this->data2;
129        $data['media'] = 'foobar.png';
130        $data['medias'] = array('foobar.png');
131        $schemaData = meta\AccessTable::getPageAccess('moves', 'page2');
132        $this->assertEquals($data, $schemaData->getDataArray());
133    }
134}
135