1
0
mirror of synced 2024-12-14 07:06:04 +03:00
doctrine2/tests/QueryWhereTestCase.php
zYne 5957622575 Fixes #157
Ticket: 157
2006-10-10 18:09:20 +00:00

94 lines
3.1 KiB
PHP

<?php
class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase {
public function prepareData() { }
public function prepareTables() {
$this->tables = array('entity');
parent::prepareTables();
}
public function testDirectParameterSetting() {
$this->connection->clear();
$user = new User();
$user->name = 'someone';
$user->save();
$q = new Doctrine_Query();
$q->from('User(id)')->addWhere('User.id = ?',1);
$users = $q->execute();
$this->assertEqual($users->count(), 1);
$this->assertEqual($users[0]->name, 'someone');
}
public function testDirectMultipleParameterSetting() {
$user = new User();
$user->name = 'someone.2';
$user->save();
$q = new Doctrine_Query();
$q->from('User(id)')->addWhere('User.id IN (?, ?)',array(1,2));
$users = $q->execute();
$this->assertEqual($users->count(), 2);
$this->assertEqual($users[0]->name, 'someone');
$this->assertEqual($users[1]->name, 'someone.2');
}
public function testComponentAliases() {
$q = new Doctrine_Query();
$q = new Doctrine_Query();
$q->from('User(id) u')->addWhere('u.id IN (?, ?)',array(1,2));
$users = $q->execute();
$this->assertEqual($users->count(), 2);
$this->assertEqual($users[0]->name, 'someone');
$this->assertEqual($users[1]->name, 'someone.2');
}
public function testOperatorWithNoTrailingSpaces() {
$q = new Doctrine_Query();
$q->from('User(id)')->where("User.name='someone'");
$users = $q->execute();
$this->assertEqual($users->count(), 1);
$this->assertEqual($q->getQuery(), "SELECT entity.id AS entity__id FROM entity WHERE entity.name = 'someone' AND (entity.type = 0)");
}
public function testOperatorWithNoTrailingSpaces2() {
$q = new Doctrine_Query();
$q->from('User(id)')->where("User.name='foo.bar'");
$users = $q->execute();
$this->assertEqual($users->count(), 0);
$this->assertEqual($q->getQuery(), "SELECT entity.id AS entity__id FROM entity WHERE entity.name = 'foo.bar' AND (entity.type = 0)");
}
public function testOperatorWithSingleTrailingSpace() {
$q = new Doctrine_Query();
$q->from('User(id)')->where("User.name= 'foo.bar'");
$users = $q->execute();
$this->assertEqual($users->count(), 0);
$this->assertEqual($q->getQuery(), "SELECT entity.id AS entity__id FROM entity WHERE entity.name = 'foo.bar' AND (entity.type = 0)");
}
public function testOperatorWithSingleTrailingSpace2() {
$q = new Doctrine_Query();
$q->from('User(id)')->where("User.name ='foo.bar'");
$users = $q->execute();
$this->assertEqual($users->count(), 0);
$this->assertEqual($q->getQuery(), "SELECT entity.id AS entity__id FROM entity WHERE entity.name = 'foo.bar' AND (entity.type = 0)");
}
}
?>