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 /** 162caf0be8SMichael 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'); 252f82ebfcSMichael Große $expected_difflink = 'http://wiki.example.com' . DOKU_BASE . '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'); 372f82ebfcSMichael Große $expected_apprejlink = 'http://wiki.example.com' . DOKU_BASE . '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); 55*faf1789aSMichael Große global $INFO; 56*faf1789aSMichael Große $INFO = pageinfo(); 5739e87974SMichael Große saveWikiText('start', 'start second', 'foobar'); 5839e87974SMichael Große $newrevision = pageinfo(); 5939e87974SMichael Große $newrevision = $newrevision['lastmod']; 6039e87974SMichael Große 61c447490bSMichael Große $expected_mail_body = 62c447490bSMichael Große'There is a new suggestion in your DokuWiki. Here are the details: 6339e87974SMichael Große 64c447490bSMichael GroßeDate : @DATE@ 65c447490bSMichael GroßeBrowser : @BROWSER@ 66c447490bSMichael GroßeIP-Address : @IPADDRESS@ 67c447490bSMichael GroßeHostname : @HOSTNAME@ 682f82ebfcSMichael GroßePrevious Revision: http://wiki.example.com' . DOKU_BASE . 'doku.php?id=start&rev=' . $oldrevision . ' 692f82ebfcSMichael GroßeNew Revision : http://wiki.example.com' . DOKU_BASE . 'doku.php?id=start&rev=' . $newrevision . ' 70c447490bSMichael GroßeEdit Summary : foobar 71c447490bSMichael GroßeUser : @USER@ 7239e87974SMichael Große 732f82ebfcSMichael Großehttp://wiki.example.com' . DOKU_BASE . 'doku.php?id=start&do=diff&rev2[0]=' . $oldrevision . '&rev2[1]=' . $newrevision . '&difftype=sidebyside 74c447490bSMichael Große 75c447490bSMichael Große 762f82ebfcSMichael GroßePlease 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@. 7739e87974SMichael Große 78eb718fbbSMichael Große-- '.' 7939e87974SMichael GroßeThis mail was generated by DokuWiki at 802f82ebfcSMichael Großehttp://wiki.example.com' . DOKU_BASE . ' 81c447490bSMichael Große'; 8239e87974SMichael Große 8339e87974SMichael Große 8439e87974SMichael Große $mail = new action_plugin_publish_mail; 85eb718fbbSMichael Große 86e6206222SMichael Große $actual_mail_body = $mail->create_mail_body('change'); 87bc4555caSMichael Große 88bc4555caSMichael Große $this->assertSame($expected_mail_body, $actual_mail_body); 89bc4555caSMichael Große 90bc4555caSMichael Große } 91bc4555caSMichael Große 92bc4555caSMichael Große 93bc4555caSMichael Große /** 94bc4555caSMichael Große * @covers action_plugin_publish_mail::create_mail_body 95bc4555caSMichael Große */ 96bc4555caSMichael Große function test_approve_mail_body () { 97bc4555caSMichael Große global $ID; 98bc4555caSMichael Große $ID = 'start'; 99bc4555caSMichael Große global $USERINFO; 100eb718fbbSMichael Große /** @var DokuWiki_Auth_Plugin $auth */ 101eb718fbbSMichael Große global $auth; 102eb718fbbSMichael Große $auth->createUser('john','x','John Smith','abc@def.gh'); 103bc4555caSMichael Große $_SERVER['REMOTE_USER'] = 'john'; 104bc4555caSMichael Große $USERINFO['name'] = 'John Smith'; 105*faf1789aSMichael Große 106*faf1789aSMichael Große global $INFO; 107*faf1789aSMichael Große $INFO = pageinfo(); 108bc4555caSMichael Große saveWikiText('start', 'start first', 'foobar'); 109eb718fbbSMichael Große 110eb718fbbSMichael Große $_SERVER['REMOTE_USER'] = 'mike'; 111eb718fbbSMichael Große $USERINFO['name'] = 'Mike Doe'; 112bc4555caSMichael Große $revision = pageinfo(); 113bc4555caSMichael Große $revision = $revision['lastmod']; 114bc4555caSMichael Große 115bc4555caSMichael Große $expected_mail_body = 'Hi John Smith! 1162f82ebfcSMichael GroßeYour suggestion for My Test Wiki at http://wiki.example.com' . DOKU_BASE . ' 117bc4555caSMichael Große 1182f82ebfcSMichael GroßeURL: http://wiki.example.com' . DOKU_BASE . 'doku.php?id=start&rev=' . $revision . ' 119bc4555caSMichael Große 120bc4555caSMichael Großeis approved. 121bc4555caSMichael Große 122eb718fbbSMichael Große-- '.' 123bc4555caSMichael GroßeThis mail was generated by DokuWiki at 1242f82ebfcSMichael Großehttp://wiki.example.com' . DOKU_BASE . ' 125c447490bSMichael Große'; 126bc4555caSMichael Große 127bc4555caSMichael Große 128bc4555caSMichael Große $mail = new action_plugin_publish_mail; 129eb718fbbSMichael Große 130e6206222SMichael Große $actual_mail_body = $mail->create_mail_body('approve'); 13139e87974SMichael Große 13239e87974SMichael Große $this->assertSame($expected_mail_body, $actual_mail_body); 13339e87974SMichael Große 13439e87974SMichael Große } 135abc3ac64SMichael Große} 136