EventListenerTestCase.php 2.5 KB
Newer Older
doctrine's avatar
doctrine committed
1
<?php
2
require_once("UnitTestCase.php");
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
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);
    }
}
doctrine's avatar
doctrine committed
18 19 20

class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
    public function testEvents() {
zYne's avatar
zYne committed
21
        $connection = $this->manager->openConnection(Doctrine_DB::getConn("sqlite::memory:"));
doctrine's avatar
doctrine committed
22 23
        $debug = $this->listener->getMessages();
        $last = end($debug);
zYne's avatar
zYne committed
24
        $this->assertTrue($last->getObject() instanceof Doctrine_Connection);
doctrine's avatar
doctrine committed
25
        $this->assertTrue($last->getCode() == Doctrine_EventListener_Debugger::EVENT_OPEN);
doctrine's avatar
doctrine committed
26
    }
27 28 29 30 31 32
    public function testAccessorInvoker() {
        $e = new EventListenerTest;
        $e->name = "something";
        $e->password = "123";


33
        $this->assertEqual($e->get('name'), 'SOMETHING');
34 35
        // test repeated calls
        $this->assertEqual($e->get('name'), 'SOMETHING');
36
        $this->assertEqual($e->id, null);
37 38 39 40 41
        $this->assertEqual($e->rawGet('name'), 'something');
        $this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');

        $e->save();

42
        $this->assertEqual($e->id, 1);
43 44 45 46 47 48 49 50
        $this->assertEqual($e->name, 'SOMETHING');
        $this->assertEqual($e->rawGet('name'), 'something');
        $this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');

        $this->connection->clear();

        $e->refresh();

51
        $this->assertEqual($e->id, 1);
52 53 54 55 56 57 58 59
        $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);

60
        $this->assertEqual($e->id, 1);
61 62 63 64
        $this->assertEqual($e->name, 'SOMETHING');
        $this->assertEqual($e->rawGet('name'), 'something');
        $this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
    }
doctrine's avatar
doctrine committed
65
    public function prepareData() { }
66 67 68 69
    public function prepareTables() {
        $this->tables = array('EventListenerTest');
        parent::prepareTables();
    }
doctrine's avatar
doctrine committed
70 71
}
?>