xref: /plugin/publish/_test/mail.unit.test.php (revision bc4555ca1a2f0277568fcad103c1331bcdee9778)
1<?php
2/**
3 * Unittests for the mail functionality of the publish plugin
4 *
5 * @group plugin_publish
6 * @group plugin_publish_unittests
7 * @group plugins
8 * @group unittests
9 * @author Michael Große <grosse@cosmocode.de>
10 */
11class publish_mail_unit_test extends DokuWikiTest {
12
13    protected $pluginsEnabled = array('publish');
14
15    /**
16     * @covers action_plugin_publish_mail::difflink
17     */
18    function test_difflink () {
19        global $ID;
20        $ID = 'wiki:syntax';
21
22        /** @var helper_plugin_publish $helper*/
23        $helper = plugin_load('helper','publish');
24        $actual_difflink = $helper->getDifflink('wiki:syntax','1','2');
25        $expected_difflink = 'http://wiki.example.com/./doku.php?id=wiki:syntax&do=diff&rev2[0]=1&rev2[1]=2&difftype=sidebyside';
26        $this->assertSame($expected_difflink,$actual_difflink);
27    }
28
29    /**
30     * @covers action_plugin_publish_mail::apprejlink
31     */
32    function test_apprejlink () {
33        global $ID;
34        $ID = 'wiki:syntax';
35        $mail = new action_plugin_publish_mail;
36        $actual_apprejlink = $mail->apprejlink('wiki:syntax','1');
37        $expected_apprejlink = 'http://wiki.example.com/./doku.php?id=wiki:syntax&rev=1'; //this stray dot comes from an unclean test-setup
38        $this->assertSame($expected_apprejlink, $actual_apprejlink);
39    }
40
41    /**
42     * @covers action_plugin_publish_mail::create_mail_body
43     * @group slow
44     */
45    function test_change_mail_body () {
46        global $ID;
47        $ID = 'start';
48        global $USERINFO;
49        $_SERVER['REMOTE_USER'] = 'john';
50        $USERINFO['name'] = 'John Smith';
51        saveWikiText('start', 'start first', 'foobar');
52        $oldrevision = pageinfo();
53        $oldrevision = $oldrevision['lastmod'];
54        sleep(1);
55        saveWikiText('start', 'start second', 'foobar');
56        $newrevision = pageinfo();
57        $newrevision = $newrevision['lastmod'];
58
59        $expected_mail_body = 'Hi John Smith!
60A new suggestion for My Test Wiki at http://wiki.example.com/./
61
62View and approve: http://wiki.example.com/./doku.php?id=start&rev=' . $newrevision . '
63
64Changes from previous version: http://wiki.example.com/./doku.php?id=start&do=diff&rev2[0]=' . $oldrevision . '&rev2[1]=' . $newrevision . '&difftype=sidebyside
65
66--
67This mail was generated by DokuWiki at
68http://wiki.example.com/./';
69
70
71        $mail = new action_plugin_publish_mail;
72        $data = pageinfo();
73        $actual_mail_body = $mail->create_mail_body('start',$data, 'change');
74
75        $this->assertSame($expected_mail_body, $actual_mail_body);
76
77    }
78
79
80    /**
81     * @covers action_plugin_publish_mail::create_mail_body
82     */
83    function test_approve_mail_body () {
84        global $ID;
85        $ID = 'start';
86        global $USERINFO;
87        $_SERVER['REMOTE_USER'] = 'john';
88        $USERINFO['name'] = 'John Smith';
89        saveWikiText('start', 'start first', 'foobar');
90        $revision = pageinfo();
91        $revision = $revision['lastmod'];
92
93        $expected_mail_body = 'Hi John Smith!
94Your suggestion for My Test Wiki at http://wiki.example.com/./
95
96URL: http://wiki.example.com/./doku.php?id=start&rev=' . $revision . '
97
98is approved.
99
100--
101This mail was generated by DokuWiki at
102http://wiki.example.com/./';
103
104
105        $mail = new action_plugin_publish_mail;
106        $data = pageinfo();
107        $actual_mail_body = $mail->create_mail_body('start',$data, 'approve');
108
109        $this->assertSame($expected_mail_body, $actual_mail_body);
110
111    }
112}
113