summaryrefslogtreecommitdiff
path: root/tests/UnitTests/framework/utPradoBase.php
blob: a53c17ddc2d6a58dbd7c47a32dbbbd763dc5fc7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php

require_once(dirname(__FILE__).'/common.php');

class testNode
{
	public $data='';
	public $parent=null;
	public $child=null;
	public function __construct($data)
	{
		$this->data=$data;
	}
}

class utPradoBase extends UnitTestCase
{
	public function testFrameworkPath()
	{
		$this->assertTrue(FRAMEWORK_DIR===Prado::getFrameworkPath());
	}

	public function testSerialization()
	{
		$object=new TComponent;
		$number=12345.123;
		$string='12345\'"';
		$array=array('123'=>123,'abc'=>'def');
		$this->assertFalse($object===Prado::unserialize(Prado::serialize($object)));
		$this->assertTrue(Prado::unserialize(Prado::serialize($object)) instanceof TComponent);
		$this->assertTrue($number===Prado::unserialize(Prado::serialize($number)));
		$this->assertTrue($string===Prado::unserialize(Prado::serialize($string)));
		$this->assertTrue($array===Prado::unserialize(Prado::serialize($array)));

		// test complex object reference structure  grandparent <-> parent <-> child
		$grandp=new testNode('grandp');
		$parent=new testNode('parent');
		$child=new testNode('child');
		$grandp->child=$parent;
		$parent->child=$child;
		$child->parent=$parent;
		$parent->parent=$grandp;

		$newGrandp=Prado::unserialize(Prado::serialize($grandp));
		$this->assertTrue($newGrandp!==$grandp);
		$this->assertTrue($newGrandp instanceof testNode);
		$this->assertTrue($newGrandp->parent===null);
		$this->assertTrue($newGrandp->data==='grandp');

		$newParent=$newGrandp->child;
		$this->assertTrue($newParent!==$parent);
		$this->assertTrue($newParent instanceof testNode);
		$this->assertTrue($newParent->parent===$newGrandp);
		$this->assertTrue($newParent->data==='parent');

		$newChild=$newParent->child;
		$this->assertTrue($newChild!==$child);
		$this->assertTrue($newChild instanceof testNode);
		$this->assertTrue($newChild->parent===$newParent);
		$this->assertTrue($newChild->child===null);
		$this->assertTrue($newChild->data==='child');
	}

	public function testCreateComponent()
	{
		$this->assertTrue(Prado::createComponent('TComponent') instanceof TComponent);
		$this->assertTrue(Prado::createComponent('System.TComponent') instanceof TComponent);
		try
		{
			Prado::createComponent('System.TComponent2');
			$this->fail('exception not raised when creating a nonexistent component');
		}
		catch(TInvalidDataValueException $e)
		{
			$this->pass();
		}
	}

	public function testNamespace()
	{
		$this->assertTrue(FRAMEWORK_DIR===Prado::getPathOfAlias('System'));
		$this->assertTrue(Prado::getPathOfAlias('System2')===null);
		$testSystem=dirname(__FILE__).'/TestSystem';

		Prado::setPathOfAlias('TestSystem',$testSystem);
		$this->assertTrue(realpath($testSystem)===Prado::getPathOfAlias('TestSystem'));

		$this->assertTrue(Prado::getPathOfNamespace('TestSystem.*')===realpath($testSystem));
		$this->assertTrue(Prado::getPathOfNamespace('TestSystem.protected.*')===realpath($testSystem).'/protected');

		// test repeatedly using the same namespaces
		Prado::using('System.*');
		Prado::using('System.*');
		Prado::using('System.TComponent');
		Prado::using('System.TComponent');

		try
		{
			Prado::using('System');
			$this->fail('no exception raised when using an invalid namespace for a directory');
		}
		catch(TInvalidDataValueException $e)
		{
			$this->pass();
		}
		// TODO: using new namespaces to see if classes can be automatically loaded or found
	}
}

?>