Commit 71063374 by Qiang Xue

test

parent cd346119
...@@ -135,7 +135,7 @@ class Component ...@@ -135,7 +135,7 @@ class Component
elseif (method_exists($this, $name) && strncasecmp($name, 'on', 2) === 0) { // event, e.g. onClick() elseif (method_exists($this, $name) && strncasecmp($name, 'on', 2) === 0) { // event, e.g. onClick()
$name = strtolower($name); $name = strtolower($name);
if (!isset($this->_e[$name])) { if (!isset($this->_e[$name])) {
$this->_e[$name] = new \yii\collections\Vector; $this->_e[$name] = new Vector;
} }
return $this->_e[$name]; return $this->_e[$name];
} }
...@@ -149,7 +149,7 @@ class Component ...@@ -149,7 +149,7 @@ class Component
} }
} }
} }
throw new Exception('Getting unknown property: ' . get_class($this) . '.' $name); throw new Exception('Getting unknown property: ' . get_class($this) . '.' . $name);
} }
/** /**
...@@ -176,7 +176,7 @@ class Component ...@@ -176,7 +176,7 @@ class Component
elseif (method_exists($this, $name) && strncasecmp($name, 'on', 2) === 0) { elseif (method_exists($this, $name) && strncasecmp($name, 'on', 2) === 0) {
$name = strtolower($name); $name = strtolower($name);
if (!isset($this->_e[$name])) { if (!isset($this->_e[$name])) {
$this->_e[$name] = new \yii\collections\Vector; $this->_e[$name] = new Vector;
} }
return $this->_e[$name]->add($value); return $this->_e[$name]->add($value);
} }
...@@ -188,10 +188,10 @@ class Component ...@@ -188,10 +188,10 @@ class Component
} }
} }
if (method_exists($this, 'get' . $name)) { if (method_exists($this, 'get' . $name)) {
throw new Exception('Setting read-only property: ' . get_class($this) . '.' $name); throw new Exception('Setting read-only property: ' . get_class($this) . '.' . $name);
} }
else { else {
throw new Exception('Setting unknown property: ' . get_class($this) . '.' $name); throw new Exception('Setting unknown property: ' . get_class($this) . '.' . $name);
} }
} }
...@@ -269,7 +269,7 @@ class Component ...@@ -269,7 +269,7 @@ class Component
} }
} }
elseif (method_exists($this, 'get' . $name)) { elseif (method_exists($this, 'get' . $name)) {
throw new Exception('Unsetting read-only property: ' . get_class($this) . '.' $name); throw new Exception('Unsetting read-only property: ' . get_class($this) . '.' . $name);
} }
} }
...@@ -304,7 +304,7 @@ class Component ...@@ -304,7 +304,7 @@ class Component
} }
} }
} }
throw new Exception('Unknown method: ' . get_class($this) . '::' $name . '()'); throw new Exception('Unknown method: ' . get_class($this) . "::$name()");
} }
/** /**
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\test\TestCase; namespace yii\test;
require_once('PHPUnit/Runner/Version.php'); require_once('PHPUnit/Runner/Version.php');
require_once('PHPUnit/Autoload.php'); require_once('PHPUnit/Autoload.php');
......
<?php <?php
require_once dirname(__FILE__) . '/NewComponent.php';
require_once dirname(__FILE__) . '/NewBehavior.php';
function globalEventHandler($event) function globalEventHandler($event)
{ {
...@@ -13,7 +11,7 @@ function globalEventHandler2($event) ...@@ -13,7 +11,7 @@ function globalEventHandler2($event)
$event->handled=true; $event->handled=true;
} }
class ComponentTest extends CTestCase class ComponentTest extends \yii\test\TestCase
{ {
protected $component; protected $component;
...@@ -133,7 +131,7 @@ class ComponentTest extends CTestCase ...@@ -133,7 +131,7 @@ class ComponentTest extends CTestCase
{ {
$this->component->attachEventHandler('OnMyEvent',array($this->component,'myEventHandler')); $this->component->attachEventHandler('OnMyEvent',array($this->component,'myEventHandler'));
$this->assertFalse($this->component->eventHandled); $this->assertFalse($this->component->eventHandled);
$this->component->raiseEvent('OnMyEvent',new CEvent($this)); $this->component->raiseEvent('OnMyEvent',new \yii\base\Event($this));
$this->assertTrue($this->component->eventHandled); $this->assertTrue($this->component->eventHandled);
//$this->setExpectedException('CException'); //$this->setExpectedException('CException');
...@@ -221,3 +219,53 @@ class ComponentTest extends CTestCase ...@@ -221,3 +219,53 @@ class ComponentTest extends CTestCase
$this->assertEquals('Hello world',$component->evaluateExpression(array($component,'exprEvaluator'),array('who' => 'world'))); $this->assertEquals('Hello world',$component->evaluateExpression(array($component,'exprEvaluator'),array('who' => 'world')));
} }
} }
class NewComponent extends \yii\base\Component
{
private $_object = null;
private $_text = 'default';
public $eventHandled = false;
public $behaviorCalled = false;
public function getText()
{
return $this->_text;
}
public function setText($value)
{
$this->_text=$value;
}
public function getObject()
{
if(!$this->_object)
{
$this->_object=new NewComponent;
$this->_object->_text='object text';
}
return $this->_object;
}
public function onMyEvent()
{
$this->raiseEvent('OnMyEvent',new \yii\base\Event($this));
}
public function myEventHandler($event)
{
$this->eventHandled=true;
}
public function exprEvaluator($p1,$comp) {
return "Hello $p1";
}
}
class NewBehavior extends \yii\base\Behavior
{
public function test()
{
$this->owner->behaviorCalled=true;
return 2;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment