1<?php
2
3use dokuwiki\plugin\sqlite\SQLiteDB;
4
5/**
6 * @group plugin_data
7 * @group plugins
8 */
9class action_handle_test extends DokuWikiTest
10{
11    protected $pluginsEnabled = array('data', 'sqlite');
12
13    protected $action;
14    /** @var helper_plugin_data */
15    protected $helper;
16    /** @var SQLiteDB */
17    protected $db;
18
19    public function tearDown(): void
20    {
21        parent::tearDown();
22
23        $this->db->exec('DELETE FROM pages WHERE page = ?', 'test');
24    }
25
26    public function setUp(): void
27    {
28        parent::setUp();
29
30        $this->action = new action_plugin_data();
31        $this->helper = plugin_load('helper', 'data');
32        $this->db = $this->helper->getDB();
33
34        $this->db->exec(
35            'INSERT INTO pages ( pid, page, title , class , lastmod) VALUES (?, ?, ?, ?, ?)',
36            [1, 'test', 'title', 'class', time()]
37        );
38    }
39
40    public function testHandleStillPresent()
41    {
42
43        $data = array(
44            0 => array(
45                1 => 'dataentry'
46            ),
47            1 => '',
48            2 => 'test'
49        );
50        $event = new Doku_Event('', $data);
51        $this->action->handle($event, null);
52
53        $pid = $this->getTestPageId();
54        $this->assertFalse(!$pid);
55    }
56
57    public function testHandleDelete()
58    {
59        $data = array(
60            0 => array(
61                1 => 'no entry'
62            ),
63            1 => '',
64            2 => 'test'
65        );
66
67        $event = new Doku_Event('', $data);
68        $this->action->handle($event, null);
69
70        $pid = $this->db->queryValue('SELECT pid FROM pages WHERE page = ?', 'test');
71        $this->assertTrue(!$pid);
72    }
73
74
75    private function getTestPageId()
76    {
77        $pid = (int) $this->db->queryValue('SELECT pid FROM pages WHERE page = ?', 'test');
78        return $pid;
79    }
80}
81