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 $data = pageinfo(); 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 $_SERVER['REMOTE_USER'] = 'john'; 99 $USERINFO['name'] = 'John Smith'; 100 saveWikiText('start', 'start first', 'foobar'); 101 $revision = pageinfo(); 102 $revision = $revision['lastmod']; 103 104 $expected_mail_body = 'Hi John Smith! 105Your suggestion for My Test Wiki at http://wiki.example.com/./ 106 107URL: http://wiki.example.com/./doku.php?id=start&rev=' . $revision . ' 108 109is approved. 110 111-- 112This mail was generated by DokuWiki at 113http://wiki.example.com/./ 114'; 115 116 117 $mail = new action_plugin_publish_mail; 118 $data = pageinfo(); 119 $actual_mail_body = $mail->create_mail_body('approve'); 120 121 $this->assertSame($expected_mail_body, $actual_mail_body); 122 123 } 124} 125