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

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

Prado::using('System.Data.ActiveRecord.TActiveRecord');

class ActiveAccount extends TActiveRecord
{
	public $Account_Id;
	public $Account_FirstName;
	public $Account_LastName;
	public $Account_Email;

	public $Account_Banner_Option;
	public $Account_Cart_Option;

	const TABLE='Accounts';

	public static function finder($className=__CLASS__)
	{
		return parent::finder($className);
	}
}

/**
 * @package System.Data.SqlMap
 */
class ActiveRecordSqlMapTest extends BaseCase
{
	function __construct()
	{
		parent::__construct();
		$this->initSqlMap();
		TActiveRecordManager::getInstance()->setDbConnection($this->getConnection());

		//$this->initScript('account-init.sql');
	}

	function testLoadWithSqlMap_SaveWithActiveRecord()
	{
		$record = $this->sqlmap->queryForObject('GetActiveRecordAccounts');
		$record->Account_FirstName = "Testing 123";

		$this->assertTrue($record->save());

		$check1 = $this->sqlmap->queryForObject('GetActiveRecordAccounts');
		$finder = ActiveAccount::finder();
		$check2 = $finder->findByAccount_FirstName($record->Account_FirstName);


		$this->assertSameAccount($record,$check1);
		$this->assertSameAccount($record,$check2);

		$this->initScript('account-init.sql');
	}

	function assertSameAccount($account1,$account2)
	{
		$props = array('Account_Id', 'Account_FirstName', 'Account_LastName',
						'Account_Email', 'Account_Banner_Option', 'Account_Cart_Option');
		foreach($props as $prop)
			$this->assertEquals($account1->{$prop}, $account2->{$prop});
	}
}