xref: /plugin/publish/_test/mail.unit.test.php (revision f31c65950a6efa9da48782c687bcdf57f7339988)
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    /**
16abc3ac64SMichael Große     * @covers action_plugin_publish_mail::difflink
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    /**
30*f31c6595SMichael 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;
36*f31c6595SMichael 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
5939e87974SMichael Große        $expected_mail_body = 'Hi John Smith!
6039e87974SMichael GroßeA new suggestion for My Test Wiki at http://wiki.example.com/./
6139e87974SMichael Große
6239e87974SMichael GroßeView and approve: http://wiki.example.com/./doku.php?id=start&rev=' . $newrevision . '
6339e87974SMichael Große
6439e87974SMichael GroßeChanges from previous version: http://wiki.example.com/./doku.php?id=start&do=diff&rev2[0]=' . $oldrevision . '&rev2[1]=' . $newrevision . '&difftype=sidebyside
6539e87974SMichael Große
6639e87974SMichael Große--
6739e87974SMichael GroßeThis mail was generated by DokuWiki at
6839e87974SMichael Großehttp://wiki.example.com/./';
6939e87974SMichael Große
7039e87974SMichael Große
7139e87974SMichael Große        $mail = new action_plugin_publish_mail;
7239e87974SMichael Große        $data = pageinfo();
73e6206222SMichael Große        $actual_mail_body = $mail->create_mail_body('change');
74bc4555caSMichael Große
75bc4555caSMichael Große        $this->assertSame($expected_mail_body, $actual_mail_body);
76bc4555caSMichael Große
77bc4555caSMichael Große    }
78bc4555caSMichael Große
79bc4555caSMichael Große
80bc4555caSMichael Große    /**
81bc4555caSMichael Große     * @covers action_plugin_publish_mail::create_mail_body
82bc4555caSMichael Große     */
83bc4555caSMichael Große    function test_approve_mail_body () {
84bc4555caSMichael Große        global $ID;
85bc4555caSMichael Große        $ID = 'start';
86bc4555caSMichael Große        global $USERINFO;
87bc4555caSMichael Große        $_SERVER['REMOTE_USER'] = 'john';
88bc4555caSMichael Große        $USERINFO['name'] = 'John Smith';
89bc4555caSMichael Große        saveWikiText('start', 'start first', 'foobar');
90bc4555caSMichael Große        $revision = pageinfo();
91bc4555caSMichael Große        $revision = $revision['lastmod'];
92bc4555caSMichael Große
93bc4555caSMichael Große        $expected_mail_body = 'Hi John Smith!
94bc4555caSMichael GroßeYour suggestion for My Test Wiki at http://wiki.example.com/./
95bc4555caSMichael Große
96bc4555caSMichael GroßeURL: http://wiki.example.com/./doku.php?id=start&rev=' . $revision . '
97bc4555caSMichael Große
98bc4555caSMichael Großeis approved.
99bc4555caSMichael Große
100bc4555caSMichael Große--
101bc4555caSMichael GroßeThis mail was generated by DokuWiki at
102bc4555caSMichael Großehttp://wiki.example.com/./';
103bc4555caSMichael Große
104bc4555caSMichael Große
105bc4555caSMichael Große        $mail = new action_plugin_publish_mail;
106bc4555caSMichael Große        $data = pageinfo();
107e6206222SMichael Große        $actual_mail_body = $mail->create_mail_body('approve');
10839e87974SMichael Große
10939e87974SMichael Große        $this->assertSame($expected_mail_body, $actual_mail_body);
11039e87974SMichael Große
11139e87974SMichael Große    }
112abc3ac64SMichael Große}
113