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