Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_testcase_dcp_application.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package Dcp\Pu
5 */
6 
7 namespace Dcp\Pu;
8 
9 require_once 'PU_testcase_dcp.php';
10 
11 abstract class TestCaseDcpApplication extends TestCaseDcp
12 {
13  protected static $app;
14 
15  protected function tearDown()
16  {
17  if (!self::$odb) {
18  self::$odb = new \DbObj(self::$dbaccess);
19  }
20  self::$odb->rollbackPoint('testunit');
21  }
22 
23  protected function setUp()
24  {
25  self::$odb->savePoint('testunit');
26  }
27 
28  public static function setUpBeforeClass()
29  {
30  parent::setUpBeforeClass();
31 
32  self::connectUser();
33  self::beginTransaction();
34  /* configList can be a single app or a list of apps */
35  $configList = static::appConfig();
36  if (!is_array($configList) && !empty($configList)) {
37  throw new \Exception(sprintf("::appConfig() did not returned an array (returned type is %s).", gettype($configList)));
38  }
39  /* If configList is a single app, then wrap it in an array of a single app */
40  if (isset($configList['appRoot']) || isset($configList['appName'])) {
41  $configList = array(
42  $configList
43  );
44  }
45  foreach ($configList as $i => $config) {
46  if (!is_array($config) && !empty($config)) {
47  throw new \Exception(sprintf("::appConfig() at index %d is not an array (returned type is %s).", $i, gettype($config)));
48  }
49  if (!isset($config['appRoot']) || !isset($config['appName'])) {
50  throw new \Exception(sprintf("Missing 'appRoot' or 'appName'."));
51  }
52 
53  self::setIncludePath(ini_get('include_path') . ':' . $config['appRoot']);
54 
55  self::setUpTestApplication($config['appRoot'], $config['appName']);
56 
57  if (isset($config['import'])) {
58  if (is_scalar($config['import'])) {
59  $config['import'] = array(
60  $config['import']
61  );
62  }
63  if (is_array($config['import'])) {
64  foreach ($config['import'] as $import) {
65  self::importDocument($import);
66  }
67  }
68  }
69  }
70  }
71 
72  public static function tearDownAfterClass()
73  {
74  self::rollbackTransaction();
75  self::resetIncludePath();
76  }
77  /**
78  * Set up a false Action object can be used to execute action
79  *
80  * @param string $appRoot root path to application folder
81  * @param string $appName application name
82  *
83  * @throws \Exception
84  * @return void
85  */
86  protected static function setUpTestApplication($appRoot, $appName)
87  {
88  if (!is_dir($appRoot)) {
89  throw new \Exception(sprintf("appRoot '%s' is not a valid directory.", $appRoot));
90  }
91 
92  $fileDotApp = join(DIRECTORY_SEPARATOR, array(
93  $appRoot,
94  $appName,
95  sprintf("%s.app", $appName)
96  ));
97  if (!is_file($fileDotApp)) {
98  throw new \Exception(sprintf(".app file '%s' not found.", $fileDotApp));
99  }
100 
101  $myAction = self::getAction();
102 
103  self::$app = new \Application();
104  self::$app->rootdir = $appRoot;
105  self::$app->param = new \Param(self::$dbaccess);
106  self::$app->parent = $myAction->parent;
107  self::$app->set($appName, $myAction->parent, $myAction->parent->session, true);
108 
109  if (self::$app->id <= 0) {
110  throw new \Exception(sprintf("Error initializing application from '%s'.", $fileDotApp));
111  }
112  }
113  /**
114  * Config of the application
115  *
116  * Need to have appRoot, and appName keys
117  *
118  * @return array
119  */
120  protected static function appConfig()
121  {
122  return array();
123  }
124 }
$app
static setUpTestApplication($appRoot, $appName)
$dbaccess
Definition: checkVault.php:17
$import
← centre documentaire © anakeen