xref: /plugin/publish/_test/mail.unit.test.php (revision 2caf0be8bfdd85e7e0465558e45cd9514f489af4)
1abc3ac64SMichael Große<?php
2abc3ac64SMichael Große/**
3abc3ac64SMichael Große * Unittests for the mail functionality of the publish plugin
4abc3ac64SMichael Große *
5abc3ac64SMichael Große * @group plugin_publish
6abc3ac64SMichael Große * @group plugin_publish_unittests
7abc3ac64SMichael Große * @group plugins
8abc3ac64SMichael Große * @group unittests
9abc3ac64SMichael Große * @author Michael Große <grosse@cosmocode.de>
10abc3ac64SMichael Große */
11abc3ac64SMichael Großeclass publish_mail_unit_test extends DokuWikiTest {
12abc3ac64SMichael Große
13abc3ac64SMichael Große    protected $pluginsEnabled = array('publish');
14abc3ac64SMichael Große
15abc3ac64SMichael Große    /**
16*2caf0be8SMichael Große     * @covers helper_plugin_publish::getDifflink
17abc3ac64SMichael Große     */
18abc3ac64SMichael Große    function test_difflink () {
19abc3ac64SMichael Große        global $ID;
20abc3ac64SMichael Große        $ID = 'wiki:syntax';
211d7b4c34SMichael Große
221d7b4c34SMichael Große        /** @var helper_plugin_publish $helper*/
231d7b4c34SMichael Große        $helper = plugin_load('helper','publish');
241d7b4c34SMichael Große        $actual_difflink = $helper->getDifflink('wiki:syntax','1','2');
25efec8cf1SMichael Große        $expected_difflink = 'http://wiki.example.com/./doku.php?id=wiki:syntax&do=diff&rev2[0]=1&rev2[1]=2&difftype=sidebyside';
26efec8cf1SMichael Große        $this->assertSame($expected_difflink,$actual_difflink);
27abc3ac64SMichael Große    }
28abc3ac64SMichael Große
29abc3ac64SMichael Große    /**
30f31c6595SMichael Große     * @covers action_plugin_publish_mail::revlink
31abc3ac64SMichael Große     */
32abc3ac64SMichael Große    function test_apprejlink () {
33abc3ac64SMichael Große        global $ID;
34abc3ac64SMichael Große        $ID = 'wiki:syntax';
35abc3ac64SMichael Große        $mail = new action_plugin_publish_mail;
36f31c6595SMichael Große        $actual_apprejlink = $mail->revlink('wiki:syntax','1');
371d7b4c34SMichael Große        $expected_apprejlink = 'http://wiki.example.com/./doku.php?id=wiki:syntax&rev=1'; //this stray dot comes from an unclean test-setup
38abc3ac64SMichael Große        $this->assertSame($expected_apprejlink, $actual_apprejlink);
39abc3ac64SMichael Große    }
4039e87974SMichael Große
4139e87974SMichael Große    /**
42bc4555caSMichael Große     * @covers action_plugin_publish_mail::create_mail_body
4339e87974SMichael Große     * @group slow
4439e87974SMichael Große     */
4539e87974SMichael Große    function test_change_mail_body () {
4639e87974SMichael Große        global $ID;
4739e87974SMichael Große        $ID = 'start';
4839e87974SMichael Große        global $USERINFO;
4939e87974SMichael Große        $_SERVER['REMOTE_USER'] = 'john';
5039e87974SMichael Große        $USERINFO['name'] = 'John Smith';
5139e87974SMichael Große        saveWikiText('start', 'start first', 'foobar');
5239e87974SMichael Große        $oldrevision = pageinfo();
5339e87974SMichael Große        $oldrevision = $oldrevision['lastmod'];
5439e87974SMichael Große        sleep(1);
5539e87974SMichael Große        saveWikiText('start', 'start second', 'foobar');
5639e87974SMichael Große        $newrevision = pageinfo();
5739e87974SMichael Große        $newrevision = $newrevision['lastmod'];
5839e87974SMichael Große
59c447490bSMichael Große        $expected_mail_body =
60c447490bSMichael Große'There is a new suggestion in your DokuWiki. Here are the details:
6139e87974SMichael Große
62c447490bSMichael GroßeDate             : @DATE@
63c447490bSMichael GroßeBrowser          : @BROWSER@
64c447490bSMichael GroßeIP-Address       : @IPADDRESS@
65c447490bSMichael GroßeHostname         : @HOSTNAME@
66c447490bSMichael GroßePrevious Revision: http://wiki.example.com/./doku.php?id=start&rev=' . $oldrevision . '
67c447490bSMichael GroßeNew Revision     : http://wiki.example.com/./doku.php?id=start&rev=' . $newrevision . '
68c447490bSMichael GroßeEdit Summary     : foobar
69c447490bSMichael GroßeUser             : @USER@
7039e87974SMichael Große
71c447490bSMichael Großehttp://wiki.example.com/./doku.php?id=start&do=diff&rev2[0]=' . $oldrevision . '&rev2[1]=' . $newrevision . '&difftype=sidebyside
72c447490bSMichael Große
73c447490bSMichael Große
74c447490bSMichael GroßePlease review the changes and approve the revision at http://wiki.example.com/./doku.php?id=start&rev=' . $newrevision . ' or give feedback to @USER@.
7539e87974SMichael Große
76eb718fbbSMichael Große-- '.'
7739e87974SMichael GroßeThis mail was generated by DokuWiki at
78c447490bSMichael Großehttp://wiki.example.com/./
79c447490bSMichael Große';
8039e87974SMichael Große
8139e87974SMichael Große
8239e87974SMichael Große        $mail = new action_plugin_publish_mail;
83eb718fbbSMichael Große
84e6206222SMichael Große        $actual_mail_body = $mail->create_mail_body('change');
85bc4555caSMichael Große
86bc4555caSMichael Große        $this->assertSame($expected_mail_body, $actual_mail_body);
87bc4555caSMichael Große
88bc4555caSMichael Große    }
89bc4555caSMichael Große
90bc4555caSMichael Große
91bc4555caSMichael Große    /**
92bc4555caSMichael Große     * @covers action_plugin_publish_mail::create_mail_body
93bc4555caSMichael Große     */
94bc4555caSMichael Große    function test_approve_mail_body () {
95bc4555caSMichael Große        global $ID;
96bc4555caSMichael Große        $ID = 'start';
97bc4555caSMichael Große        global $USERINFO;
98eb718fbbSMichael Große        /** @var DokuWiki_Auth_Plugin $auth */
99eb718fbbSMichael Große        global $auth;
100eb718fbbSMichael Große        $auth->createUser('john','x','John Smith','abc@def.gh');
101bc4555caSMichael Große        $_SERVER['REMOTE_USER'] = 'john';
102bc4555caSMichael Große        $USERINFO['name'] = 'John Smith';
103bc4555caSMichael Große        saveWikiText('start', 'start first', 'foobar');
104eb718fbbSMichael Große
105eb718fbbSMichael Große        $_SERVER['REMOTE_USER'] = 'mike';
106eb718fbbSMichael Große        $USERINFO['name'] = 'Mike Doe';
107bc4555caSMichael Große        $revision = pageinfo();
108bc4555caSMichael Große        $revision = $revision['lastmod'];
109bc4555caSMichael Große
110bc4555caSMichael Große        $expected_mail_body = 'Hi John Smith!
111bc4555caSMichael GroßeYour suggestion for My Test Wiki at http://wiki.example.com/./
112bc4555caSMichael Große
113bc4555caSMichael GroßeURL: http://wiki.example.com/./doku.php?id=start&rev=' . $revision . '
114bc4555caSMichael Große
115bc4555caSMichael Großeis approved.
116bc4555caSMichael Große
117eb718fbbSMichael Große-- '.'
118bc4555caSMichael GroßeThis mail was generated by DokuWiki at
119c447490bSMichael Großehttp://wiki.example.com/./
120c447490bSMichael Große';
121bc4555caSMichael Große
122bc4555caSMichael Große
123bc4555caSMichael Große        $mail = new action_plugin_publish_mail;
124eb718fbbSMichael Große
125e6206222SMichael Große        $actual_mail_body = $mail->create_mail_body('approve');
12639e87974SMichael Große
12739e87974SMichael Große        $this->assertSame($expected_mail_body, $actual_mail_body);
12839e87974SMichael Große
12939e87974SMichael Große    }
130abc3ac64SMichael Große}
131