Наследование: extends CComponent
Пример #1
0
 public function testDisableBehaviors()
 {
     $component = new NewComponent();
     $component->attachBehavior('a', new NewBehavior());
     $component->disableBehaviors();
     $this->setExpectedException('CException');
     // test should not be called since behavior is disabled
     echo $component->test();
 }
Пример #2
0
 public function testStopEvent()
 {
     $component = new NewComponent();
     $component->onMyEvent = 'globalEventHandler2';
     $component->onMyEvent = array($this->component, 'myEventHandler');
     $component->onMyEvent();
     $this->assertTrue($component->eventHandled);
     $this->assertFalse($this->component->eventHandled);
 }
Пример #3
0
 public function testEvaluateExpression()
 {
     $component = new NewComponent();
     $this->assertEquals('Hello world', $component->evaluateExpression('"Hello $who"', array('who' => 'world')));
     $this->assertEquals('Hello world', $component->evaluateExpression(array($component, 'exprEvaluator'), array('who' => 'world')));
 }
Пример #4
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);
 }
Пример #5
0
 protected function setUp()
 {
     //parent::setUp();
     $this->sample = Yii::createObject(['class' => NewComponent::className(), 'items' => $this->items]);
 }
Пример #6
0
 public function testEvaluateExpression()
 {
     $this->assertSame('Hello world', $this->component->evaluateExpression('"Hello $who"', array('who' => 'world')));
     $this->assertSame('Hello world', $this->component->evaluateExpression(array($this->component, 'exprEvaluator'), array('who' => 'world')));
 }
 public function testBehavior()
 {
     $component = new NewComponent();
     $component->attachBehavior('a', new NewBehavior());
     $this->assertFalse($component->behaviorCalled);
     $this->assertFalse(method_exists($component, 'test'));
     $this->assertEquals(2, $component->test());
     $this->assertTrue($component->behaviorCalled);
     $this->setExpectedException('CException');
     $component->test2();
 }