summaryrefslogtreecommitdiff
path: root/tests/unit/Data/SqlMap/PropertyAccessTest.php
blob: ba9e24c7d941a129e86cd3ad43b509c699d4de44 (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
<?php

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

/**
 * @package System.Data.SqlMap
 */
class PropertyAccessTest extends BaseCase
{
	function testGetPublicProperty()
	{
		$account = new AccountBis();

		$account->Id = 10;
		$account->FirstName = "Luky";
		$account->LastName = "Luke";
		$account->EmailAddress = "luly.luke@somewhere.com";

		$two = new AccountBis();
		$two->Id = 12;
		$two->FirstName = "Mini Me!";
		$account->More = $two;

		$account6 = $this->NewAccount6();
		$two->More = $account6;

		$this->assertSame(10, TPropertyAccess::get($account, 'Id'));
		$this->assertSame(12, TPropertyAccess::get($account, 'More.Id'));
		$this->assertSame(6, TPropertyAccess::get($account, 'More.More.Id'));
	}

	function testSetPublicProperty()
	{
		$account = new AccountBis();

		$account->Id = 10;
		$account->FirstName = "Luky";
		$account->LastName = "Luke";
		$account->EmailAddress = "luly.luke@somewhere.com";

		$two = new AccountBis();
		$two->Id = 12;
		$two->FirstName = "Mini Me!";
		TPropertyAccess::set($account, 'More', $two);

		$account6 = $this->NewAccount6();
		TPropertyAccess::set($account, 'More.More', $account6);

		TPropertyAccess::set($account, 'More.More.EmailAddress', 'hahaha');

		$this->assertSame(10, TPropertyAccess::get($account, 'Id'));
		$this->assertSame(12, TPropertyAccess::get($account, 'More.Id'));
		$this->assertSame(6, TPropertyAccess::get($account, 'More.More.Id'));

		$this->assertSame('hahaha',
				TPropertyAccess::get($account, 'More.More.EmailAddress'));
	}

	function testArrayAccessProperty()
	{
		$account = new AccountBis();
		$things['more'] = 1;
		$things['accounts']  = $this->NewAccount6();
		$account->More = $things;

		$this->assertSame(6, TPropertyAccess::get($account, 'More.accounts.ID'));

		TPropertyAccess::set($account, 'More.accounts.EmailAddress', 'adssd');
		$this->assertSame('adssd', TPropertyAccess::get($account, 'More.accounts.EmailAddress'));

		$this->assertSame(1, TPropertyAccess::get($things, 'more'));
	}

}