1
0
mirror of synced 2024-12-13 22:56:04 +03:00
doctrine2/tests/CollectionTestCase.php

70 lines
2.2 KiB
PHP
Raw Normal View History

2006-04-14 00:37:28 +04:00
<?php
class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
public function testAdd() {
2006-04-17 00:38:17 +04:00
$coll = new Doctrine_Collection($this->objTable);
$coll->add(new User());
$this->assertEqual($coll->count(),1);
$coll->add(new User());
$this->assertTrue($coll->count(),2);
2006-04-19 20:01:36 +04:00
2006-04-17 00:38:17 +04:00
$this->assertEqual($coll->getKeys(), array(0,1));
2006-04-19 20:01:36 +04:00
2006-04-17 00:38:17 +04:00
$coll[2] = new User();
2006-04-19 20:01:36 +04:00
2006-04-17 00:38:17 +04:00
$this->assertTrue($coll->count(),3);
$this->assertEqual($coll->getKeys(), array(0,1,2));
}
2006-04-19 20:01:36 +04:00
2006-04-17 00:38:17 +04:00
public function testExpand() {
2006-05-29 20:15:54 +04:00
$users = $this->session->query("FROM User-b.Phonenumber-l WHERE User.Phonenumber.phonenumber LIKE '%123%'");
2006-04-19 20:01:36 +04:00
$this->assertTrue($users instanceof Doctrine_Collection_Batch);
2006-04-17 00:38:17 +04:00
$this->assertTrue($users[1] instanceof User);
2006-04-19 20:01:36 +04:00
$this->assertTrue($users[1]->Phonenumber instanceof Doctrine_Collection_Lazy);
2006-04-17 00:38:17 +04:00
$data = $users[1]->Phonenumber->getData();
$coll = $users[1]->Phonenumber;
$this->assertEqual(count($data), 1);
2006-04-19 20:01:36 +04:00
foreach($coll as $record) {
$record->phonenumber;
}
2006-04-17 00:38:17 +04:00
$coll[1];
2006-04-19 20:01:36 +04:00
2006-04-17 00:38:17 +04:00
$this->assertEqual(count($coll), 3);
2006-04-19 20:01:36 +04:00
2006-05-19 14:22:15 +04:00
$this->assertEqual($coll[2]->getState(), Doctrine_Record::STATE_PROXY);
2006-04-17 00:38:17 +04:00
2006-04-23 12:12:01 +04:00
$generator = new Doctrine_IndexGenerator($this->objTable->getIdentifier());
2006-04-17 00:38:17 +04:00
$coll->setGenerator($generator);
$generator = $coll->getGenerator();
$user = $this->session->getTable("User")->find(4);
$this->assertEqual($generator->getIndex($user), 4);
2006-04-19 20:01:36 +04:00
2006-04-17 00:38:17 +04:00
}
public function testGenerator() {
$generator = new Doctrine_IndexGenerator("name");
$coll = new Doctrine_Collection($this->objTable);
$coll->setGenerator($generator);
2006-04-19 20:01:36 +04:00
2006-04-17 00:38:17 +04:00
$user = new User();
$user->name = "name";
$coll->add($user);
2006-04-19 20:01:36 +04:00
2006-04-17 00:38:17 +04:00
$this->assertEqual($coll["name"], $user);
$this->session->getTable("email")->setAttribute(Doctrine::ATTR_COLL_KEY,"address");
$emails = $this->session->getTable("email")->findAll();
foreach($emails as $k => $v) {
$this->assertTrue(gettype($k), "string");
}
}
2006-04-14 00:37:28 +04:00
}
?>