summaryrefslogtreecommitdiff
path: root/tests/simple_unit/ActiveRecord/CriteriaTestCase.php
blob: f1545e1dbf6ed1ee307d9ed5f97ac11f2dc0c843 (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
<?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');
	}
}

?>