Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Schema / IndexTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Schema;
4
5 require_once __DIR__ . '/../../TestInit.php';
6
7 use Doctrine\DBAL\Schema\Schema;
8 use Doctrine\DBAL\Schema\Table;
9 use Doctrine\DBAL\Schema\Column;
10 use Doctrine\DBAL\Schema\Index;
11
12 class IndexTest extends \PHPUnit_Framework_TestCase
13 {
14     public function createIndex($unique=false, $primary=false)
15     {
16         return new Index("foo", array("bar", "baz"), $unique, $primary);
17     }
18
19     public function testCreateIndex()
20     {
21         $idx = $this->createIndex();
22         $this->assertEquals("foo", $idx->getName());
23         $columns = $idx->getColumns();
24         $this->assertEquals(2, count($columns));
25         $this->assertEquals(array("bar", "baz"), $columns);
26         $this->assertFalse($idx->isUnique());
27         $this->assertFalse($idx->isPrimary());
28     }
29
30     public function testCreatePrimary()
31     {
32         $idx = $this->createIndex(false, true);
33         $this->assertTrue($idx->isUnique());
34         $this->assertTrue($idx->isPrimary());
35     }
36
37     public function testCreateUnique()
38     {
39         $idx = $this->createIndex(true, false);
40         $this->assertTrue($idx->isUnique());
41         $this->assertFalse($idx->isPrimary());
42     }
43
44     /**
45      * @group DBAL-50
46      */
47     public function testFullfilledByUnique()
48     {
49         $idx1 = $this->createIndex(true, false);
50         $idx2 = $this->createIndex(true, false);
51         $idx3 = $this->createIndex();
52
53         $this->assertTrue($idx1->isFullfilledBy($idx2));
54         $this->assertFalse($idx1->isFullfilledBy($idx3));
55     }
56
57     /**
58      * @group DBAL-50
59      */
60     public function testFullfilledByPrimary()
61     {
62         $idx1 = $this->createIndex(true, true);
63         $idx2 = $this->createIndex(true, true);
64         $idx3 = $this->createIndex(true, false);
65
66         $this->assertTrue($idx1->isFullfilledBy($idx2));
67         $this->assertFalse($idx1->isFullfilledBy($idx3));
68     }
69
70     /**
71      * @group DBAL-50
72      */
73     public function testFullfilledByIndex()
74     {
75         $idx1 = $this->createIndex();
76         $idx2 = $this->createIndex();
77         $pri = $this->createIndex(true, true);
78         $uniq = $this->createIndex(true);
79
80         $this->assertTrue($idx1->isFullfilledBy($idx2));
81         $this->assertTrue($idx1->isFullfilledBy($pri));
82         $this->assertTrue($idx1->isFullfilledBy($uniq));
83     }
84
85     /**
86      * @group DBAL-220
87      */
88     public function testFlags()
89     {
90         $idx1 = $this->createIndex();
91         $this->assertFalse($idx1->hasFlag('clustered'));
92
93         $idx1->addFlag('clustered');
94         $this->assertTrue($idx1->hasFlag('clustered'));
95         $this->assertTrue($idx1->hasFlag('CLUSTERED'));
96
97         $idx1->removeFlag('clustered');
98         $this->assertFalse($idx1->hasFlag('clustered'));
99     }
100
101     /**
102      * @group DBAL-285
103      */
104     public function testIndexQuotes()
105     {
106         $index = new Index("foo", array("`bar`", "`baz`"));
107
108         $this->assertTrue($index->spansColumns(array("bar", "baz")));
109         $this->assertTrue($index->hasColumnAtPosition("bar", 0));
110         $this->assertTrue($index->hasColumnAtPosition("baz", 1));
111
112         $this->assertFalse($index->hasColumnAtPosition("bar", 1));
113         $this->assertFalse($index->hasColumnAtPosition("baz", 0));
114     }
115 }