2006-04-19 20:01:36 +04:00
|
|
|
<?php
|
2006-10-19 00:17:49 +04:00
|
|
|
class Doctrine_Collection_Offset_TestCase extends Doctrine_UnitTestCase {
|
2006-04-19 20:01:36 +04:00
|
|
|
public function testExpand() {
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$users = $this->connection->query("FROM User-o");
|
2006-04-19 20:01:36 +04:00
|
|
|
$this->assertTrue($users instanceof Doctrine_Collection_Offset);
|
|
|
|
|
|
|
|
$this->assertEqual(count($users), 5);
|
|
|
|
$users[5];
|
|
|
|
|
|
|
|
$this->assertEqual($users[5]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$users[5];
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->connection->setAttribute(Doctrine::ATTR_COLL_LIMIT, 3);
|
2006-04-19 20:01:36 +04:00
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$users = $this->connection->query("FROM User-o");
|
2006-04-19 20:01:36 +04:00
|
|
|
$this->assertEqual(count($users), 3);
|
|
|
|
$this->assertEqual($users[0]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($users[1]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($users[2]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
// indexes 0,1,2 in use
|
|
|
|
|
|
|
|
$users[7];
|
|
|
|
$this->assertEqual(count($users), 5);
|
|
|
|
$this->assertFalse($users->contains(3));
|
|
|
|
$this->assertFalse($users->contains(4));
|
|
|
|
$this->assertFalse($users->contains(5));
|
|
|
|
$this->assertTrue($users->contains(6));
|
|
|
|
$this->assertTrue($users->contains(7));
|
|
|
|
|
|
|
|
$this->assertEqual($users[6]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($users[7]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
|
|
|
|
|
|
|
|
$users[5];
|
|
|
|
$this->assertEqual(count($users), 8);
|
|
|
|
$this->assertEqual($users[3]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($users[4]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($users[5]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->connection->setAttribute(Doctrine::ATTR_COLL_LIMIT, 1);
|
|
|
|
$users = $this->connection->query("FROM User-b, User.Phonenumber-o WHERE User.".$this->objTable->getIdentifier()." = 5");
|
2006-04-19 20:01:36 +04:00
|
|
|
|
|
|
|
$this->assertEqual(count($users), 1);
|
|
|
|
|
|
|
|
$coll = $users[0]->Phonenumber;
|
2006-08-16 03:25:53 +04:00
|
|
|
$this->assertEqual(count($coll), 3);
|
2006-04-19 20:01:36 +04:00
|
|
|
$coll[1];
|
|
|
|
|
2006-08-16 03:25:53 +04:00
|
|
|
$this->assertEqual(count($coll), 3);
|
2006-04-19 20:01:36 +04:00
|
|
|
$this->assertEqual($coll[1]->phonenumber, "456 456");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetIterator() {
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->connection->setAttribute(Doctrine::ATTR_COLL_LIMIT, 4);
|
|
|
|
$coll = $this->connection->query("FROM User-o");
|
2006-04-19 20:01:36 +04:00
|
|
|
|
|
|
|
foreach($coll as $user) {
|
|
|
|
}
|
|
|
|
$this->assertEqual($coll->count(), 8);
|
|
|
|
$this->assertEqual($coll[3]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($coll[6]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->connection->setAttribute(Doctrine::ATTR_COLL_LIMIT, 3);
|
2006-04-19 20:01:36 +04:00
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$coll = $this->connection->query("FROM User-o");
|
2006-04-19 20:01:36 +04:00
|
|
|
|
|
|
|
foreach($coll as $user) {
|
|
|
|
}
|
|
|
|
$this->assertEqual($coll->count(), 8);
|
|
|
|
$this->assertEqual($coll[3]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($coll[6]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
}
|
|
|
|
}
|