ControllerTestCase.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\test\lib;
12 
16 
17 /**
18  * ControllerTestCase is the base class for test cases used for Controllers.
19  *
20  * @author ingo herwig <ingo@wemove.com>
21  */
22 abstract class ControllerTestCase extends DatabaseTestCase {
23 
24  /**
25  * Make a request to the controller. This method makes sure that the
26  * requested action is routed to the controller to be tested.
27  * The calling method has to make sure that a session is started, if necessary
28  * (e.g. by calling TestUtil::startSession()). The transaction will be rolled
29  * back before the request is run in order to avoid side effects.
30  * @param $action The action
31  * @param $data An associative array with additional key/value pairs for the Request instance
32  * @return Response instance
33  */
34  protected function runRequest($action, $data) {
35  $persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
36  $persistenceFacade->getTransaction()->rollback();
37 
38  // add action key
39  TestUtil::setConfigValue('??'.$action, $this->getControllerName(), 'actionmapping');
40 
41  // make request
42  $request = ObjectFactory::getInstance('request');
43  $request->setAction($action);
44  foreach ($data as $key => $value) {
45  $request->setValue($key, $value);
46  }
47  return TestUtil::simulateRequest($request);
48  }
49 
50  /**
51  * Get the fully qualified name of the controller to test
52  * @return The name of the controller
53  */
54  abstract protected function getControllerName();
55 }
56 ?>
static getInstance($name, $dynamicConfiguration=array())
DatabaseTestCase is the base class for test cases that need database support.
static setConfigValue($key, $value, $section)
Set a configuration value.
Definition: TestUtil.php:180
getControllerName()
Get the fully qualified name of the controller to test.
ControllerTestCase is the base class for test cases used for Controllers.
Test support classes.
Definition: namespaces.php:100
runRequest($action, $data)
Make a request to the controller.
static simulateRequest($request)
Process a request as if it was sent to main.php.
Definition: TestUtil.php:134