xref: /plugin/publish/_test/mail.unit.test.php (revision eb718fbbb17a6bf8d6cbd1344b92819a1480b25a)
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::revlink
31     */
32    function test_apprejlink () {
33        global $ID;
34        $ID = 'wiki:syntax';
35        $mail = new action_plugin_publish_mail;
36        $actual_apprejlink = $mail->revlink('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 =
60'There is a new suggestion in your DokuWiki. Here are the details:
61
62Date             : @DATE@
63Browser          : @BROWSER@
64IP-Address       : @IPADDRESS@
65Hostname         : @HOSTNAME@
66Previous Revision: http://wiki.example.com/./doku.php?id=start&rev=' . $oldrevision . '
67New Revision     : http://wiki.example.com/./doku.php?id=start&rev=' . $newrevision . '
68Edit Summary     : foobar
69User             : @USER@
70
71http://wiki.example.com/./doku.php?id=start&do=diff&rev2[0]=' . $oldrevision . '&rev2[1]=' . $newrevision . '&difftype=sidebyside
72
73
74Please review the changes and approve the revision at http://wiki.example.com/./doku.php?id=start&rev=' . $newrevision . ' or give feedback to @USER@.
75
76-- '.'
77This mail was generated by DokuWiki at
78http://wiki.example.com/./
79';
80
81
82        $mail = new action_plugin_publish_mail;
83
84        $actual_mail_body = $mail->create_mail_body('change');
85
86        $this->assertSame($expected_mail_body, $actual_mail_body);
87
88    }
89
90
91    /**
92     * @covers action_plugin_publish_mail::create_mail_body
93     */
94    function test_approve_mail_body () {
95        global $ID;
96        $ID = 'start';
97        global $USERINFO;
98        /** @var DokuWiki_Auth_Plugin $auth */
99        global $auth;
100        $auth->createUser('john','x','John Smith','abc@def.gh');
101        $_SERVER['REMOTE_USER'] = 'john';
102        $USERINFO['name'] = 'John Smith';
103        saveWikiText('start', 'start first', 'foobar');
104
105        $_SERVER['REMOTE_USER'] = 'mike';
106        $USERINFO['name'] = 'Mike Doe';
107        $revision = pageinfo();
108        $revision = $revision['lastmod'];
109
110        $expected_mail_body = 'Hi John Smith!
111Your suggestion for My Test Wiki at http://wiki.example.com/./
112
113URL: http://wiki.example.com/./doku.php?id=start&rev=' . $revision . '
114
115is approved.
116
117-- '.'
118This mail was generated by DokuWiki at
119http://wiki.example.com/./
120';
121
122
123        $mail = new action_plugin_publish_mail;
124
125        $actual_mail_body = $mail->create_mail_body('approve');
126
127        $this->assertSame($expected_mail_body, $actual_mail_body);
128
129    }
130}
131