EventListenerChainTestCase.php 2.14 KB
Newer Older
1 2
<?php
require_once("UnitTestCase.php");
3
class EventListenerChainTest extends Doctrine_Record {
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
    public function setTableDefinition() {
        $this->hasColumn("name", "string", 100);
    }
    public function setUp() {
        $chain = new Doctrine_EventListener_Chain();
        $chain->add(new Doctrine_EventListener_TestA());
        $chain->add(new Doctrine_EventListener_TestB());
        $this->setAttribute(Doctrine::ATTR_LISTENER, $chain);
    }
}

class Doctrine_EventListener_TestA extends Doctrine_EventListener {
  public function onGetProperty(Doctrine_Record $record, $property, $value) {
    return $value . 'TestA';
  }
}
class Doctrine_EventListener_TestB extends Doctrine_EventListener {
  public function onGetProperty(Doctrine_Record $record, $property, $value) {
    return $value . 'TestB';
  }
}

26
class Doctrine_EventListener_Chain_TestCase extends Doctrine_UnitTestCase {
zYne's avatar
zYne committed
27

28
    public function testAccessorInvokerChain() {
zYne's avatar
zYne committed
29
        $e = new EventListenerChainTest;
30 31 32
        $e->name = "something";


zYne's avatar
zYne committed
33
        $this->assertEqual($e->get('name'), 'somethingTestATestB');
34
        // test repeated calls
zYne's avatar
zYne committed
35
        $this->assertEqual($e->get('name'), 'somethingTestATestB');
36 37 38 39 40 41
        $this->assertEqual($e->id, null);
        $this->assertEqual($e->rawGet('name'), 'something');

        $e->save();

        $this->assertEqual($e->id, 1);
zYne's avatar
zYne committed
42
        $this->assertEqual($e->name, 'somethingTestATestB');
43 44 45 46 47 48 49
        $this->assertEqual($e->rawGet('name'), 'something');

        $this->connection->clear();

        $e->refresh();

        $this->assertEqual($e->id, 1);
zYne's avatar
zYne committed
50
        $this->assertEqual($e->name, 'somethingTestATestB');
51 52 53 54 55 56 57
        $this->assertEqual($e->rawGet('name'), 'something');

        $this->connection->clear();

        $e = $e->getTable()->find($e->id);

        $this->assertEqual($e->id, 1);
zYne's avatar
zYne committed
58
        $this->assertEqual($e->name, 'somethingTestATestB');
59 60 61 62 63 64 65 66 67
        $this->assertEqual($e->rawGet('name'), 'something');
    }
    public function prepareData() { }
    public function prepareTables() {
        $this->tables = array('EventListenerChainTest');
        parent::prepareTables();
    }
}
?>