1<?php
2/**
3 * @group plugin_datepicker
4 * @group plugins
5 */
6class plugin_datepicker_ajax_test extends DokuWikiTest {
7
8    public function setup() {
9        $this->pluginsEnabled[] = 'datepicker';
10        $this->pluginsEnabled[] = 'ajaxedit';
11        parent::setup();
12    }
13
14
15    public function test_basic_ajax() {
16        global $INFO;
17
18        $INFO['id'] = 'test:plugin_datepicker:ajax';
19        $INFO['perm'] = AUTH_EDIT;
20        saveWikiText('test:plugin_datepicker:ajax',"<datepicker>",'test');
21
22        $xhtml = p_wiki_xhtml('test:plugin_datepicker:ajax');
23        $doc = phpQuery::newDocument($xhtml);
24
25        $this->assertEquals(plugin_load('action', 'datepicker')->getConf('emptyStringDate'), pq("span.datepicker",$doc)->get(0)->textContent);
26
27        $request = new TestRequest();
28        $request->post([
29            'call'      => 'plugin_datepicker',
30            'pageid'    => 'test:plugin_datepicker:ajax',
31            'id'        => 0,
32            'datestr'   => '2018-01-01',
33            'mode'      => 'datepicker',
34
35            'lastmod'   => @filemtime(wikiFN('test:plugin_datepicker:ajax')),
36
37        ], '/lib/exe/ajax.php');
38
39        $xhtml = p_wiki_xhtml('test:plugin_datepicker:ajax');
40        $doc = phpQuery::newDocument($xhtml);
41
42        $this->assertEquals('2018-01-01', pq("span.datepicker",$doc)->get(0)->textContent);
43    }
44
45    public function test_basic_ajax_weekpicker() {
46        global $INFO;
47
48        $INFO['id'] = 'test:plugin_datepicker:ajax';
49        $INFO['perm'] = AUTH_EDIT;
50        saveWikiText('test:plugin_datepicker:ajax', "<weekpicker><weekpicker 01/18>",'test');
51
52        $request = new TestRequest();
53        $request->post([
54            'call'      => 'plugin_datepicker',
55            'pageid'    => 'test:plugin_datepicker:ajax',
56            'id'        => 1,
57            'datestr'   => '02/18',
58            'mode'      => 'weekpicker',
59
60            'lastmod'   => @filemtime(wikiFN('test:plugin_datepicker:ajax')),
61
62        ], '/lib/exe/ajax.php');
63
64        $xhtml = p_wiki_xhtml('test:plugin_datepicker:ajax');
65        $doc = phpQuery::newDocument($xhtml);
66
67        $this->assertEquals(plugin_load('action', 'datepicker')->getConf('emptyStringWeek'), pq("span.weekpicker",$doc)->get(0)->textContent);
68        $this->assertEquals('02/18', pq("span.weekpicker",$doc)->get(1)->textContent);
69    }
70}
71