예제 #1
0
 public function testUnsetFunction()
 {
     $this->assertEquals('default', $this->component->getText());
     unset($this->component->Text);
     $this->assertNull($this->component->getText());
     unset($this->component->UndefinedProperty);
     // object events
     $this->assertEquals(0, $this->component->onMyEvent->Count);
     $this->component->attachEventHandler('onMyEvent', 'foo');
     $this->assertEquals(1, $this->component->onMyEvent->Count);
     unset($this->component->onMyEvent);
     $this->assertEquals(0, $this->component->onMyEvent->Count);
     //global events
     $this->assertEquals(1, $this->component->fxAttachClassBehavior->Count);
     $component = new NewComponent();
     $this->assertEquals(2, $this->component->fxAttachClassBehavior->Count);
     unset($this->component->fxAttachClassBehavior);
     // retain the other object event
     $this->assertEquals(1, $this->component->fxAttachClassBehavior->Count);
     $component->unlisten();
     try {
         unset($this->component->Object);
         $this->fail('TInvalidOperationException not raised when unsetting get only property');
     } catch (TInvalidOperationException $e) {
     }
     $this->component->attachBehavior('BehaviorTestBehavior', new BehaviorTestBehavior());
     $this->assertTrue($this->component->asa('BehaviorTestBehavior') instanceof BehaviorTestBehavior);
     $this->assertFalse($this->component->asa('BehaviorTestBehavior2') instanceof BehaviorTestBehavior);
     $this->assertEquals('faa', $this->component->Excitement);
     unset($this->component->Excitement);
     $this->assertNull($this->component->Excitement);
     $this->component->Excitement = 'sol';
     $this->assertEquals('sol', $this->component->Excitement);
     // Test the disabling of unset within behaviors
     $this->component->disableBehaviors();
     unset($this->component->Excitement);
     $this->component->enableBehaviors();
     // This should still be 'sol'  because the unset happened inside behaviors being disabled
     $this->assertEquals('sol', $this->component->Excitement);
     $this->component->disableBehavior('BehaviorTestBehavior');
     unset($this->component->Excitement);
     $this->component->enableBehavior('BehaviorTestBehavior');
     $this->assertEquals('sol', $this->component->Excitement);
     unset($this->component->Excitement);
     $this->assertNull($this->component->Excitement);
     try {
         unset($this->component->ReadOnly);
         $this->fail('TInvalidOperationException not raised when unsetting get only property');
     } catch (TInvalidOperationException $e) {
     }
     $this->component->onBehaviorEvent = 'foo';
     $this->assertEquals(1, count($this->component->onBehaviorEvent));
     $this->assertEquals(1, count($this->component->BehaviorTestBehavior->onBehaviorEvent));
     unset($this->component->onBehaviorEvent);
     $this->assertEquals(0, count($this->component->onBehaviorEvent));
     $this->assertEquals(0, count($this->component->BehaviorTestBehavior->onBehaviorEvent));
     // Remove behavior via unset
     unset($this->component->BehaviorTestBehavior);
     $this->assertFalse($this->component->asa('BehaviorTestBehavior') instanceof BehaviorTestBehavior);
 }