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