AriadneBaseTest::initAriadne()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
	global $store_config,$AR,$ariadne,$ax_config,$ARCurrent,$ARConfig,$ARLoader;
4
	$ariadne = getcwd().'/lib/';
5
	$ARLoader = 'cmd';
6
7
	require_once($ariadne.'/bootstrap.php');
8
	require_once(AriadneBasePath .'/configs/axstore.phtml');
9
	require_once(AriadneBasePath .'/stores/axstore.phtml');
10
11
	function importContent($base, $package) {
12
		global $AR,$ARCurrent,$store_config,$ax_config;
13
14
		/* instantiate the store */
15
		$storetype = $store_config["dbms"]."store";
16
		$store = new $storetype($root,$store_config);
0 ignored issues
show
Bug introduced by
The variable $root does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
17
18
		$ARCurrent->nolangcheck = true;
19
20
		// become admin
21
		$AR->user=new baseObject;
22
		$AR->user->data=new baseObject;
0 ignored issues
show
Bug introduced by
The property data does not seem to exist in baseObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
23
		$AR->user->data->login=$ARLogin="admin";
0 ignored issues
show
Unused Code introduced by
$ARLogin is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Bug introduced by
The property login does not seem to exist in baseObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
24
25
		$ax_config["writeable"]=false;
26
		$ax_config["database"]=$package;
27
		set_time_limit(300);
28
		$storetype = $ax_config["dbms"]."store";
29
		$axstore=new $storetype("", $ax_config);
30 View Code Duplication
		if (!$axstore->error) {
31
			$ARCurrent->importStore=&$store;
32
			$args="srcpath=/&destpath=".$base;
33
			$axstore->call("system.export.phtml", $args,
34
				$axstore->get("/"));
35
			$error=$axstore->error;
36
			$axstore->close();
37
		} else {
38
			$error=$axstore->error;
39
		}
40
41
		$store->close();
42
		print $error;
43
		return $error;
44
	}
45
46
	function initTestData() {
47
		global $AR,$ARCurrent,$store_config,$store,$ARConfig;
48
49
		$origAR        = clone $AR;
50
		$origARCurrent = clone $ARCurrent;
51
		$origARConfig  = clone $ARConfig;
52
53
		// become admin
54
		$AR->user=new baseObject;
55
		$AR->user->data=new baseObject;
0 ignored issues
show
Bug introduced by
The property data does not seem to exist in baseObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
56
		$AR->user->data->login=$ARLogin="admin";
0 ignored issues
show
Unused Code introduced by
$ARLogin is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Bug introduced by
The property login does not seem to exist in baseObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
57
58
		/* instantiate the store */
59
		$storetype = $store_config["dbms"]."store";
60
		$store = new $storetype($root,$store_config);
0 ignored issues
show
Bug introduced by
The variable $root does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
61
		$res = ar::get('/projects/')->call('system.new.phtml', array (
62
				'arNewType' => 'pproject',
63
				'arNewFilename' => '/projects/{5:id}',
64
				'en' => array (
65
					'name' => 'Unit test dir (en)'.date(DATE_W3C)
66
				),
67
				'nl' => array (
68
					'name' => 'Unit test dir (nl)'.date(DATE_W3C)
69
				),
70
				'de' => array (
71
					'name' => 'Unit test dir (de)'.date(DATE_W3C)
72
				)
73
			)
74
		);
75
		$base = current($res);
76
		// set grants for testrunner user
77
		ar::get($res)->call('system.save.grants.phtml', array(
78
			"path"      => '/system/users/testrunner/',
79
			"newgrants" => 'read add edit >delete config layout'
80
		));
81
		define('TESTBASE',$base);
82
83
		importContent($base,getcwd().'/www/install/packages/demo.ax');
84
85
		$AR        = $origAR;
86
		$ARCurrent = $origARCurrent;
87
		$ARConfig  = $origARConfig;
88
	}
89
90
	abstract class AriadneBaseTest extends PHPUnit_Framework_TestCase
91
	{
92
		protected function initAriadne() {
93
			global $ariadne,$store_config,$store,$AR;
94
			/* instantiate the store */
95
			$inst_store = $store_config["dbms"]."store";
96
			$store = new $inst_store($root,$store_config);
0 ignored issues
show
Bug introduced by
The variable $root does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
97
98
			/* now load a user (admin in this case)*/
99
			$AR->user = new baseObject();
100
			$AR->user->data = new baseObject();
0 ignored issues
show
Bug introduced by
The property data does not seem to exist in baseObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
101
			$AR->user->data->login = "admin";
0 ignored issues
show
Bug introduced by
The property login does not seem to exist in baseObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
102
		}
103
104
		private static function loadTestData() {
105
			$name = get_called_class();
106
			$reflector = new ReflectionClass($name);
107
			$file = $reflector->getFileName();
108
			$file = preg_replace('/\.php$/','.ax',$file);
109
			if ( is_file($file) ) {
110
				importContent(TESTBASE, $file);
111
			}
112
		}
113
114
		public static function setUpBeforeClass() {
115
			self::loadTestData();
116
		}
117
118
	}
119
120
121
	initTestData();
122
123
	// become testrunner
124
	$AR->user = current(ar::get('/system/users/testrunner/')->call('system.get.phtml'));
125