2006-04-14 00:37:28 +04:00
|
|
|
<?php
|
2006-06-07 00:37:56 +04:00
|
|
|
require_once("UnitTestCase.php");
|
2006-09-12 14:15:58 +04:00
|
|
|
class EventListenerTest extends Doctrine_Record {
|
|
|
|
public function setTableDefinition() {
|
|
|
|
$this->hasColumn("name", "string", 100);
|
|
|
|
$this->hasColumn("password", "string", 8);
|
|
|
|
}
|
|
|
|
public function setUp() {
|
|
|
|
$this->setAttribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_AccessorInvoker());
|
|
|
|
}
|
|
|
|
public function getName($name) {
|
|
|
|
return strtoupper($name);
|
|
|
|
}
|
|
|
|
public function setPassword($password) {
|
|
|
|
return md5($password);
|
|
|
|
}
|
|
|
|
}
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
|
|
|
|
public function testEvents() {
|
2006-08-23 00:14:29 +04:00
|
|
|
$connection = $this->manager->openConnection(Doctrine_DB::getConn("sqlite::memory:"));
|
2006-04-14 00:37:28 +04:00
|
|
|
$debug = $this->listener->getMessages();
|
|
|
|
$last = end($debug);
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->assertTrue($last->getObject() instanceof Doctrine_Connection);
|
2006-06-03 13:10:43 +04:00
|
|
|
$this->assertTrue($last->getCode() == Doctrine_EventListener_Debugger::EVENT_OPEN);
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
2006-09-12 14:15:58 +04:00
|
|
|
public function testAccessorInvoker() {
|
|
|
|
$e = new EventListenerTest;
|
|
|
|
$e->name = "something";
|
|
|
|
$e->password = "123";
|
|
|
|
|
|
|
|
|
2006-09-13 01:36:36 +04:00
|
|
|
$this->assertEqual($e->get('name'), 'SOMETHING');
|
2006-09-12 14:15:58 +04:00
|
|
|
// test repeated calls
|
|
|
|
$this->assertEqual($e->get('name'), 'SOMETHING');
|
2006-09-13 01:36:36 +04:00
|
|
|
$this->assertEqual($e->id, null);
|
2006-09-12 14:15:58 +04:00
|
|
|
$this->assertEqual($e->rawGet('name'), 'something');
|
|
|
|
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
|
|
|
|
|
|
|
$e->save();
|
|
|
|
|
2006-09-13 01:36:36 +04:00
|
|
|
$this->assertEqual($e->id, 1);
|
2006-09-12 14:15:58 +04:00
|
|
|
$this->assertEqual($e->name, 'SOMETHING');
|
|
|
|
$this->assertEqual($e->rawGet('name'), 'something');
|
|
|
|
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
|
|
|
|
|
|
|
$this->connection->clear();
|
|
|
|
|
|
|
|
$e->refresh();
|
|
|
|
|
2006-09-13 01:36:36 +04:00
|
|
|
$this->assertEqual($e->id, 1);
|
2006-09-12 14:15:58 +04:00
|
|
|
$this->assertEqual($e->name, 'SOMETHING');
|
|
|
|
$this->assertEqual($e->rawGet('name'), 'something');
|
|
|
|
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
|
|
|
|
|
|
|
$this->connection->clear();
|
|
|
|
|
|
|
|
$e = $e->getTable()->find($e->id);
|
|
|
|
|
2006-09-13 01:36:36 +04:00
|
|
|
$this->assertEqual($e->id, 1);
|
2006-09-12 14:15:58 +04:00
|
|
|
$this->assertEqual($e->name, 'SOMETHING');
|
|
|
|
$this->assertEqual($e->rawGet('name'), 'something');
|
|
|
|
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
|
|
|
}
|
2006-06-03 13:10:43 +04:00
|
|
|
public function prepareData() { }
|
2006-09-12 14:15:58 +04:00
|
|
|
public function prepareTables() {
|
|
|
|
$this->tables = array('EventListenerTest');
|
|
|
|
parent::prepareTables();
|
|
|
|
}
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
|
|
|
?>
|