Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / common / tests / Doctrine / Tests / Common / Collections / CriteriaTest.php
1 <?php
2 namespace Doctrine\Tests\Common\Collections;
3
4 use Doctrine\Common\Collections\Criteria;
5 use Doctrine\Common\Collections\Expr\Comparison;
6 use Doctrine\Common\Collections\Expr\CompositeExpression;
7
8 class CriteriaTest extends \PHPUnit_Framework_TestCase
9 {
10     public function testCreate()
11     {
12         $criteria = Criteria::create();
13
14         $this->assertInstanceOf("Doctrine\Common\Collections\Criteria", $criteria);
15     }
16
17     public function testConstructor()
18     {
19         $expr     = new Comparison("field", "=", "value");
20         $criteria = new Criteria($expr, array("foo" => "ASC"), 10, 20);
21
22         $this->assertSame($expr, $criteria->getWhereExpression());
23         $this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
24         $this->assertEquals(10, $criteria->getFirstResult());
25         $this->assertEquals(20, $criteria->getMaxResults());
26     }
27
28     public function testWhere()
29     {
30         $expr     = new Comparison("field", "=", "value");
31         $criteria = new Criteria();
32
33         $criteria->where($expr);
34
35         $this->assertSame($expr, $criteria->getWhereExpression());
36     }
37
38     public function testAndWhere()
39     {
40         $expr     = new Comparison("field", "=", "value");
41         $criteria = new Criteria();
42
43         $criteria->where($expr);
44         $expr = $criteria->getWhereExpression();
45         $criteria->andWhere($expr);
46
47         $where = $criteria->getWhereExpression();
48         $this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where);
49
50         $this->assertEquals(CompositeExpression::TYPE_AND, $where->getType());
51         $this->assertSame(array($expr, $expr), $where->getExpressionList());
52     }
53
54     public function testOrWhere()
55     {
56         $expr     = new Comparison("field", "=", "value");
57         $criteria = new Criteria();
58
59         $criteria->where($expr);
60         $expr = $criteria->getWhereExpression();
61         $criteria->orWhere($expr);
62
63         $where = $criteria->getWhereExpression();
64         $this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where);
65
66         $this->assertEquals(CompositeExpression::TYPE_OR, $where->getType());
67         $this->assertSame(array($expr, $expr), $where->getExpressionList());
68     }
69
70     public function testOrderings()
71     {
72         $criteria = Criteria::create()
73             ->orderBy(array("foo" => "ASC"));
74
75         $this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
76     }
77
78     public function testExpr()
79     {
80         $this->assertInstanceOf('Doctrine\Common\Collections\ExpressionBuilder', Criteria::expr());
81     }
82 }