PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/framework/base/CBehaviorTest.php

https://bitbucket.org/intel352/yii-framework
PHP | 51 lines | 36 code | 6 blank | 9 comment | 0 complexity | 55194df8ad9e7d9b3b9bf80a0fab1b7d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. require_once dirname(__FILE__) . '/NewComponent.php';
  3. require_once dirname(__FILE__) . '/NewBehavior.php';
  4. require_once dirname(__FILE__) . '/NewBeforeValidateBehavior.php';
  5. require_once dirname(__FILE__) . '/NewFormModel.php';
  6. class CBehaviorTest extends CTestCase {
  7. public function testAttachBehavior() {
  8. $component=new NewComponent;
  9. $component->attachBehavior('a',new NewBehavior);
  10. $this->assertFalse($component->behaviorCalled);
  11. $this->assertFalse(method_exists($component,'test'));
  12. $this->assertEquals(2,$component->test());
  13. $this->assertTrue($component->behaviorCalled);
  14. $this->setExpectedException('CException');
  15. $component->test2();
  16. }
  17. public function testDisableBehaviors(){
  18. $component=new NewComponent;
  19. $component->attachBehavior('a',new NewBehavior);
  20. $component->disableBehaviors();
  21. $this->setExpectedException('CException');
  22. // test should not be called since behavior is disabled
  23. echo $component->test();
  24. }
  25. /**
  26. * Since disableBehaviors() was called, validate() should not call beforeValidate() from behavior.
  27. * @return void
  28. */
  29. public function testDisableBehaviorsAndModels(){
  30. $model = new NewFormModel();
  31. $model->disableBehaviors();
  32. $model->validate();
  33. }
  34. /**
  35. * enableBehaviors() should work after disableBehaviors().
  36. * @return void
  37. */
  38. public function testDisableAndEnableBehaviorsAndModels(){
  39. $this->setExpectedException('NewBeforeValidateBehaviorException');
  40. $model = new NewFormModel();
  41. $model->disableBehaviors();
  42. $model->enableBehaviors();
  43. $model->validate();
  44. }
  45. }