2006-09-22 12:07:49 +04:00
|
|
|
<?php
|
|
|
|
class Doctrine_EnumTestCase extends Doctrine_UnitTestCase {
|
|
|
|
public function prepareData() { }
|
|
|
|
public function prepareTables() {
|
|
|
|
$this->tables = array("EnumTest");
|
|
|
|
parent::prepareTables();
|
|
|
|
}
|
|
|
|
|
2006-10-03 21:24:13 +04:00
|
|
|
public function testParameterConversion() {
|
2006-09-22 12:07:49 +04:00
|
|
|
$test = new EnumTest();
|
|
|
|
$test->status = 'open';
|
|
|
|
$this->assertEqual($test->status, 'open');
|
|
|
|
$test->save();
|
|
|
|
|
|
|
|
$query = new Doctrine_Query($this->connection);
|
2006-09-27 01:32:00 +04:00
|
|
|
$ret = $query->query('FROM EnumTest WHERE EnumTest.status = ?', array('open'));
|
2006-09-22 12:07:49 +04:00
|
|
|
$this->assertEqual(count($ret), 1);
|
|
|
|
|
|
|
|
$query = new Doctrine_Query($this->connection);
|
2006-09-27 01:32:00 +04:00
|
|
|
$ret = $query->query('FROM EnumTest WHERE EnumTest.status = open');
|
2006-09-22 12:07:49 +04:00
|
|
|
$this->assertEqual(count($ret), 1);
|
|
|
|
|
2006-09-29 01:21:33 +04:00
|
|
|
}
|
|
|
|
public function testEnumType() {
|
|
|
|
|
|
|
|
$enum = new EnumTest();
|
|
|
|
$enum->status = "open";
|
|
|
|
$this->assertEqual($enum->status, "open");
|
|
|
|
$enum->save();
|
|
|
|
$this->assertEqual($enum->status, "open");
|
|
|
|
$enum->refresh();
|
|
|
|
$this->assertEqual($enum->status, "open");
|
|
|
|
|
|
|
|
$enum->status = "closed";
|
|
|
|
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
|
|
|
|
$enum->save();
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
$this->assertTrue(is_numeric($enum->id));
|
|
|
|
$enum->refresh();
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnumTypeWithCaseConversion() {
|
|
|
|
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
|
|
|
|
|
|
|
|
$enum = new EnumTest();
|
|
|
|
|
|
|
|
$enum->status = "open";
|
|
|
|
$this->assertEqual($enum->status, "open");
|
|
|
|
|
|
|
|
$enum->save();
|
|
|
|
$this->assertEqual($enum->status, "open");
|
|
|
|
|
|
|
|
$enum->refresh();
|
|
|
|
$this->assertEqual($enum->status, "open");
|
|
|
|
|
|
|
|
$enum->status = "closed";
|
|
|
|
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
|
|
|
|
$enum->save();
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
|
|
|
|
$enum->refresh();
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
|
|
|
|
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFailingRefresh() {
|
|
|
|
$enum = $this->connection->getTable('EnumTest')->find(1);
|
|
|
|
|
|
|
|
$this->dbh->query('DELETE FROM enum_test WHERE id = 1');
|
2006-09-22 12:07:49 +04:00
|
|
|
|
2006-09-29 01:21:33 +04:00
|
|
|
$f = false;
|
|
|
|
try {
|
|
|
|
$enum->refresh();
|
|
|
|
} catch(Doctrine_Record_Exception $e) {
|
|
|
|
$f = true;
|
|
|
|
}
|
|
|
|
$this->assertTrue($f);
|
2006-09-22 12:07:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|