/** Catch strict standards */
error_reporting(E_ALL | E_STRICT);
-
-/** Load stubs */
-require_once 'Stub/Browser.php';
-require_once 'Stub/Identity.php';
-require_once 'Stub/Injector.php';
-require_once 'Stub/Prefs.php';
-require_once 'Stub/Registry.php';
\ No newline at end of file
+++ /dev/null
-<?php
-/**
- * Dummy Horde_Browser stub.
- *
- * PHP version 5
- *
- * @category Horde
- * @package IMP
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Imp
- */
-
-/**
- * Dummy Horde_Browser stub.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @category Horde
- * @package IMP
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/gpl.html GPL
- * @link http://pear.horde.org/index.php?package=Imp
- */
-class IMP_Stub_Browser
-{
- public function hasQuirk($quirk)
- {
- return false;
- }
-
- public function hasFeature($feature)
- {
- return false;
- }
-}
\ No newline at end of file
+++ /dev/null
-<?php
-/**
- * Dummy IMP_Prefs_Identity stub.
- *
- * PHP version 5
- *
- * @category Horde
- * @package IMP
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Imp
- */
-
-/**
- * Dummy IMP_Prefs_Identity stub.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @category Horde
- * @package IMP
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/gpl.html GPL
- * @link http://pear.horde.org/index.php?package=Imp
- */
-class IMP_Stub_Identity
-{
- private $_id = 'default';
-
- public function getMatchingIdentity($mail)
- {
- if ($mail == 'test@example.org') {
- return 'test';
- }
- }
-
- public function setDefault($id)
- {
- if ($id != 'test' && $id != 'other' && $id != 'default') {
- throw new Exception("Unexpected default $id!");
- }
- $this->_id = $id;
- }
-
- public function getDefault()
- {
- return $this->_id;
- }
-
- public function getFromAddress()
- {
- return 'test@example.org';
- }
-
- public function getValue($value)
- {
- switch ($value) {
- case 'fullname':
- return 'Mr. Test';
- case 'replyto_addr':
- switch ($this->_id) {
- case 'test':
- return 'test@example.org';
- case 'other':
- return 'reply@example.org';
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-<?php
-/**
- * Dummy Horde_Injector stub.
- *
- * PHP version 5
- *
- * @category Horde
- * @package IMP
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Imp
- */
-
-/**
- * Dummy Horde_Injector stub.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @category Horde
- * @package IMP
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/gpl.html GPL
- * @link http://pear.horde.org/index.php?package=Imp
- */
-class IMP_Stub_Injector
-{
- private $_mail;
-
- public function getInstance($interface)
- {
- switch($interface) {
- case 'IMP_Identity':
- return new IMP_Stub_Identity();
- case 'IMP_Mail':
- if (!isset($this->_mail)) {
- $this->_mail = new Horde_Mail_Transport_Mock();
- }
- return $this->_mail;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-<?php
-/**
- * Dummy Horde_Prefs stub.
- *
- * PHP version 5
- *
- * @category Horde
- * @package IMP
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Imp
- */
-
-/**
- * Dummy Horde_Prefs stub.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @category Horde
- * @package IMP
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/gpl.html GPL
- * @link http://pear.horde.org/index.php?package=Imp
- */
-class IMP_Stub_Prefs
-{
- public function getValue($pref)
- {
- switch($pref) {
- case 'date_format':
- return '%x';
- case 'twentyFour':
- return true;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-<?php
-/**
- * Dummy Horde_Registry stub.
- *
- * PHP version 5
- *
- * @category Horde
- * @package IMP
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Imp
- */
-
-/**
- * Dummy Horde_Registry stub.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @category Horde
- * @package IMP
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/gpl.html GPL
- * @link http://pear.horde.org/index.php?package=Imp
- */
-class IMP_Stub_Registry
-{
- private $_charset = 'UTF-8';
-
- public function getCharset()
- {
- return $this->_charset;
- }
-
- public function setCharset($charset)
- {
- $this->_charset = $charset;
- }
-
- public function get($parameter, $app = null)
- {
- return null;
- }
-}
class Imp_Unit_Mime_Viewer_ItipTest
extends PHPUnit_Framework_TestCase
{
+ private $_identity;
+ private $_identityId = 'default';
+ private $_mail;
+ private $_registryCharset = 'UTF-8';
+
public function setUp()
{
- $GLOBALS['registry'] = new IMP_Stub_Registry();
- $GLOBALS['browser'] = new IMP_Stub_Browser();
- $GLOBALS['prefs'] = new IMP_Stub_Prefs();
- $GLOBALS['injector'] = new IMP_Stub_Injector();
+ $browser = $this->getMock('Horde_Browser');
+ $browser->expects($this->any())
+ ->method('hasQuirk')
+ ->will($this->returnValue(false));
+ $browser->expects($this->any())
+ ->method('hasFeature')
+ ->will($this->returnValue(false));
+ $GLOBALS['browser'] = $browser;
+
+ $injector = $this->getMock('Horde_Injector', array(), array(), '', false);
+ $injector->expects($this->any())
+ ->method('getInstance')
+ ->will($this->returnCallback(array($this, '_injectorGetInstance')));
+ $GLOBALS['injector'] = $injector;
+
+ $prefs = $this->getMock('Horde_Prefs', array(), array(), '' , false);
+ $prefs->expects($this->any())
+ ->method('getValue')
+ ->will($this->returnCallback(array($this, '_prefsGetValue')));
+ $GLOBALS['prefs'] = $prefs;
+
+ $registry = $this->getMock('Horde_Registry', array(), array(), '', false);
+ $registry->expects($this->any())
+ ->method('getCharset')
+ ->will($this->returnCallback(array($this, '_registryGetCharset')));
+ $registry->expects($this->any())
+ ->method('setCharset')
+ ->will($this->returnCallback(array($this, '_registrySetCharset')));
+ $GLOBALS['registry'] = $registry;
+
$GLOBALS['conf']['server']['name'] = 'localhost';
$_GET['identity'] = 'test';
$_SERVER['REMOTE_ADDR'] = 'localhost';
$_SESSION = array('imp' => array('view' => 'imp'));
}
+ public function _injectorGetInstance($interface)
+ {
+ switch ($interface) {
+ case 'IMP_Identity':
+ if (!isset($this->_identity)) {
+ $identity = $this->getMock('Horde_Core_Prefs_Identity', array(), array(), '', false);
+ $identity->expects($this->any())
+ ->method('setDefault')
+ ->will($this->returnCallback(array($this, '_identitySetDefault')));
+ $identity->expects($this->any())
+ ->method('getDefault')
+ ->will($this->returnCallback(array($this, '_identityGetDefault')));
+ $identity->expects($this->any())
+ ->method('getFromAddress')
+ ->will($this->returnValue('test@example.org'));
+ $identity->expects($this->any())
+ ->method('getValue')
+ ->will($this->returnCallback(array($this, '_identityGetValue')));
+ $identity->expects($this->any())
+ ->method('getMatchingIdentity')
+ ->will($this->returnCallback(array($this, '_identityGetMatchingIdentity')));
+ $this->_identity = $identity;
+ }
+ return $this->_identity;
+
+ case 'IMP_Mail':
+ if (!isset($this->_mail)) {
+ $this->_mail = Horde_Mail::factory('Mock');
+ }
+ return $this->_mail;
+ }
+ }
+
+ public function _identityGetMatchingIdentity($mail)
+ {
+ if ($mail == 'test@example.org') {
+ return 'test';
+ }
+ }
+
+ public function _identitySetDefault($id)
+ {
+ if (($id != 'test') &&
+ ($id != 'other') &&
+ ($id != 'default')) {
+ throw new Exception("Unexpected default $id!");
+ }
+
+ $this->_identityId = $id;
+ }
+
+ public function _identityGetDefault()
+ {
+ return $this->_identityId;
+ }
+
+ public function _identityGetValue($value)
+ {
+ switch ($value) {
+ case 'fullname':
+ return 'Mr. Test';
+
+ case 'replyto_addr':
+ switch ($this->_identityId) {
+ case 'test':
+ return 'test@example.org';
+
+ case 'other':
+ return 'reply@example.org';
+ }
+ }
+ }
+
+ public function _prefsGetValue($pref)
+ {
+ switch ($pref) {
+ case 'date_format':
+ return '%x';
+
+ case 'twentyFour':
+ return true;
+ }
+ }
+
+ public function _registryGetCharset()
+ {
+ return $this->_registryCharset;
+ }
+
+ public function _registrySetCharset($charset)
+ {
+ $this->_registryCharset = $charset;
+ }
+
+ /* Begin tests */
+
public function testAcceptingAnInvitationResultsInReplySent()
{
$_GET['itip_action'] = array(0 => 'accept');
$this->assertEquals('Tentative: Test Invitation', $this->_getMailHeaders()->getValue('Subject'));
}
public function testResultMimeMessageHeadersContainsReplyToForAlternateIdentity()
- {
+ {
$_GET['identity'] = 'other';
$_GET['itip_action'] = array(0 => 'accept');
$viewer = $this->_getViewer($this->_getInvitation()->exportvCalendar());
{
$mail = '';
if (isset($GLOBALS['injector']->getInstance('IMP_Mail')->sentMessages[0])) {
- $mail .= $GLOBALS['injector']->getInstance('IMP_Mail')->sentMessages[0]['header_text'] . "\n\n";
- $body = $GLOBALS['injector']->getInstance('IMP_Mail')->sentMessages[0]['body'];
- while (!feof($body)) {
- $mail .= fread($body, 8192);
- }
+ $mail .= $GLOBALS['injector']->getInstance('IMP_Mail')->sentMessages[0]['header_text'] .
+ "\n\n" .
+ $GLOBALS['injector']->getInstance('IMP_Mail')->sentMessages[0]['body'];
}
return $mail;
}