1
0
mirror of synced 2024-12-13 14:56:01 +03:00
doctrine2/tests/EventListenerTestCase.php

72 lines
2.5 KiB
PHP
Raw Normal View History

2006-04-14 00:37:28 +04:00
<?php
require_once("UnitTestCase.php");
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
}
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');
// test repeated calls
$this->assertEqual($e->get('name'), 'SOMETHING');
2006-09-13 01:36:36 +04:00
$this->assertEqual($e->id, null);
$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);
$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);
$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);
$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() { }
public function prepareTables() {
$this->tables = array('EventListenerTest');
parent::prepareTables();
}
2006-04-14 00:37:28 +04:00
}
?>