summaryrefslogtreecommitdiff
path: root/tests/simple_unit/ActiveRecord/CriteriaTestCase.php
blob: 17f691d7595088ec590b61b47aed1608bcbc0cce (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
<?php

Prado::using('System.Data.ActiveRecord.TActiveRecord');
require_once(dirname(__FILE__).'/records/DepartmentRecord.php');
require_once(dirname(__FILE__).'/records/DepSections.php');

class CriteriaTestCase extends UnitTestCase
{
	function setup()
	{
		$conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
		TActiveRecordManager::getInstance()->setDbConnection($conn);
	}

	function test_orderby_only()
	{
		$criteria = new TActiveRecordCriteria;
		$criteria->OrdersBy['name'] = 'asc';
		$records = DepartmentRecord::finder()->findAll($criteria);
		$this->assertEqual(count($records), 8);
		$this->assertEqual($records[0]->name, '+GX Service');
		$this->assertEqual($records[7]->name, 'Marketing');
	}

	function test_orderby_only_desc()
	{
		$criteria = new TActiveRecordCriteria;
		$criteria->OrdersBy['name'] = 'desc';
		$records = DepartmentRecord::finder()->findAll($criteria);
		$this->assertEqual(count($records), 8);
		$this->assertEqual($records[7]->name, '+GX Service');
		$this->assertEqual($records[0]->name, 'Marketing');
	}

	function test_criteria_parameters()
	{
		$criteria = new TActiveRecordCriteria('sql', "One", "two", 3);
		$expect = array("One", "two", 3);
		$this->assertEqual($criteria->getParameters()->toArray(), $expect);
	}

	function test_criteria_parameters_array()
	{
		$expect = array("One", "two", 3);
		$criteria = new TActiveRecordCriteria('sql', $expect);
		$this->assertEqual($criteria->getParameters()->toArray(), $expect);
	}
}

?>