2017-01-04 23:25:06 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware Api: Application test base class
|
|
|
|
*
|
|
|
|
* @link http://www.stylite.de
|
|
|
|
* @package api
|
|
|
|
* @subpackage test
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright (c) 2016 Nathan Gray
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2017-01-06 19:21:38 +01:00
|
|
|
namespace EGroupware\Api;
|
2017-01-04 23:25:06 +01:00
|
|
|
|
2017-02-06 21:04:32 +01:00
|
|
|
// test base providing Egw environment
|
|
|
|
require_once 'LoggedInTest.php';
|
2017-01-04 23:25:06 +01:00
|
|
|
|
|
|
|
use EGroupware\Api;
|
|
|
|
|
|
|
|
/**
|
2017-02-06 21:04:32 +01:00
|
|
|
* Base class for application tests, loads the egroupware environment and provides
|
|
|
|
* some handy helpers.
|
2017-01-04 23:25:06 +01:00
|
|
|
*
|
|
|
|
* Extend this class into <appname>/test/ or <appname>/src/test/ to test one
|
2017-02-06 21:04:32 +01:00
|
|
|
* small aspect of an application. For more basic (actual unit) tests that deal
|
|
|
|
* with a single function, consider extending TestCase directly instead of this
|
|
|
|
* class to avoid the overhead of creating the session.
|
2017-01-04 23:25:06 +01:00
|
|
|
*/
|
2017-02-06 21:04:32 +01:00
|
|
|
abstract class AppTest extends LoggedInTest
|
2017-01-04 23:25:06 +01:00
|
|
|
{
|
2017-02-01 17:56:04 +01:00
|
|
|
/**
|
|
|
|
* Sets the tracking object to a mock object, so we don't try to send real
|
|
|
|
* notifications while testing.
|
|
|
|
*
|
|
|
|
* After calling this to mock the tracking object, you can set expectations
|
|
|
|
* for tracking:
|
|
|
|
* <code>
|
|
|
|
* $this->mockTracking($this->bo, 'app_tracker');
|
|
|
|
*
|
|
|
|
* // we do not expect track to get called for a new entry
|
|
|
|
* $this->bo->tracking->expects($this->never())
|
|
|
|
* ->method('track');
|
|
|
|
*
|
|
|
|
* $this->bo->save($entry);
|
|
|
|
* </code>
|
|
|
|
* @param Object $bo_object Instance of the BO object
|
|
|
|
* @param String $tracker_class The name of the tracker class to mock
|
|
|
|
*/
|
|
|
|
protected function mockTracking(&$bo_object, $tracker_class)
|
|
|
|
{
|
|
|
|
if(!is_object($bo_object))
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Invalid BO object');
|
|
|
|
}
|
|
|
|
if(!property_exists($bo_object, 'tracking'))
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Invalid BO object - needs tracking property');
|
|
|
|
}
|
|
|
|
$bo_object->tracking = $this->getMockBuilder($tracker_class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->setMethods(['track'])
|
|
|
|
->getMock($bo_object);
|
|
|
|
}
|
2017-01-04 23:25:06 +01:00
|
|
|
}
|