Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2bootstrap
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
yii2bootstrap
Commits
cd346119
Commit
cd346119
authored
Jul 20, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
w
parent
201b7068
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
262 additions
and
0 deletions
+262
-0
TestCase.php
framework/test/TestCase.php
+23
-0
bootstrap.php
tests/unit/bootstrap.php
+9
-0
ComponentTest.php
tests/unit/framework/base/ComponentTest.php
+223
-0
phpunit.xml
tests/unit/phpunit.xml
+7
-0
No files found.
framework/test/TestCase.php
0 → 100644
View file @
cd346119
<?php
/**
* TestCase class.
*
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\test\TestCase
;
require_once
(
'PHPUnit/Runner/Version.php'
);
require_once
(
'PHPUnit/Autoload.php'
);
/**
* TestCase is the base class for all test case classes.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
abstract
class
TestCase
extends
\PHPUnit_Framework_TestCase
{
}
tests/unit/bootstrap.php
0 → 100644
View file @
cd346119
<?php
define
(
'YII_ENABLE_EXCEPTION_HANDLER'
,
false
);
define
(
'YII_ENABLE_ERROR_HANDLER'
,
false
);
define
(
'YII_DEBUG'
,
true
);
$_SERVER
[
'SCRIPT_NAME'
]
=
'/'
.
__DIR__
;
$_SERVER
[
'SCRIPT_FILENAME'
]
=
__FILE__
;
require_once
(
__DIR__
.
'/../../framework/yii.php'
);
tests/unit/framework/base/ComponentTest.php
0 → 100644
View file @
cd346119
<?php
require_once
dirname
(
__FILE__
)
.
'/NewComponent.php'
;
require_once
dirname
(
__FILE__
)
.
'/NewBehavior.php'
;
function
globalEventHandler
(
$event
)
{
$event
->
sender
->
eventHandled
=
true
;
}
function
globalEventHandler2
(
$event
)
{
$event
->
sender
->
eventHandled
=
true
;
$event
->
handled
=
true
;
}
class
ComponentTest
extends
CTestCase
{
protected
$component
;
public
function
setUp
()
{
$this
->
component
=
new
NewComponent
();
}
public
function
tearDown
()
{
$this
->
component
=
null
;
}
public
function
testHasProperty
()
{
$this
->
assertTrue
(
$this
->
component
->
hasProperty
(
'Text'
),
"Component hasn't property Text"
);
$this
->
assertTrue
(
$this
->
component
->
hasProperty
(
'text'
),
"Component hasn't property text"
);
$this
->
assertFalse
(
$this
->
component
->
hasProperty
(
'Caption'
),
"Component as property Caption"
);
}
public
function
testCanGetProperty
()
{
$this
->
assertTrue
(
$this
->
component
->
canGetProperty
(
'Text'
));
$this
->
assertTrue
(
$this
->
component
->
canGetProperty
(
'text'
));
$this
->
assertFalse
(
$this
->
component
->
canGetProperty
(
'Caption'
));
}
public
function
testCanSetProperty
()
{
$this
->
assertTrue
(
$this
->
component
->
canSetProperty
(
'Text'
));
$this
->
assertTrue
(
$this
->
component
->
canSetProperty
(
'text'
));
$this
->
assertFalse
(
$this
->
component
->
canSetProperty
(
'Caption'
));
}
public
function
testGetProperty
()
{
$this
->
assertTrue
(
'default'
===
$this
->
component
->
Text
);
$this
->
setExpectedException
(
'CException'
);
$value2
=
$this
->
component
->
Caption
;
}
public
function
testSetProperty
()
{
$value
=
'new value'
;
$this
->
component
->
Text
=
$value
;
$text
=
$this
->
component
->
Text
;
$this
->
assertTrue
(
$value
===
$this
->
component
->
Text
);
$this
->
setExpectedException
(
'CException'
);
$this
->
component
->
NewMember
=
$value
;
}
public
function
testIsset
()
{
$this
->
assertTrue
(
isset
(
$this
->
component
->
Text
));
$this
->
assertTrue
(
!
empty
(
$this
->
component
->
Text
));
unset
(
$this
->
component
->
Text
);
$this
->
assertFalse
(
isset
(
$this
->
component
->
Text
));
$this
->
assertFalse
(
!
empty
(
$this
->
component
->
Text
));
$this
->
component
->
Text
=
''
;
$this
->
assertTrue
(
isset
(
$this
->
component
->
Text
));
$this
->
assertTrue
(
empty
(
$this
->
component
->
Text
));
}
public
function
testHasEvent
()
{
$this
->
assertTrue
(
$this
->
component
->
hasEvent
(
'OnMyEvent'
));
$this
->
assertTrue
(
$this
->
component
->
hasEvent
(
'onmyevent'
));
$this
->
assertFalse
(
$this
->
component
->
hasEvent
(
'onYourEvent'
));
}
public
function
testHasEventHandler
()
{
$this
->
assertFalse
(
$this
->
component
->
hasEventHandler
(
'OnMyEvent'
));
$this
->
component
->
attachEventHandler
(
'OnMyEvent'
,
'foo'
);
$this
->
assertTrue
(
$this
->
component
->
hasEventHandler
(
'OnMyEvent'
));
}
public
function
testGetEventHandlers
()
{
$list
=
$this
->
component
->
getEventHandlers
(
'OnMyEvent'
);
$this
->
assertEquals
(
$list
->
getCount
(),
0
);
$this
->
component
->
attachEventHandler
(
'OnMyEvent'
,
'foo'
);
$this
->
assertEquals
(
$list
->
getCount
(),
1
);
$this
->
setExpectedException
(
'CException'
);
$list
=
$this
->
component
->
getEventHandlers
(
'YourEvent'
);
}
public
function
testAttachEventHandler
()
{
$this
->
component
->
attachEventHandler
(
'OnMyEvent'
,
'foo'
);
$this
->
assertTrue
(
$this
->
component
->
getEventHandlers
(
'OnMyEvent'
)
->
getCount
()
===
1
);
$this
->
setExpectedException
(
'CException'
);
$this
->
component
->
attachEventHandler
(
'YourEvent'
,
'foo'
);
}
public
function
testDettachEventHandler
()
{
$this
->
component
->
attachEventHandler
(
'OnMyEvent'
,
'foo'
);
$this
->
component
->
attachEventHandler
(
'OnMyEvent'
,
array
(
$this
->
component
,
'myEventHandler'
));
$this
->
assertEquals
(
$this
->
component
->
getEventHandlers
(
'OnMyEvent'
)
->
getCount
(),
2
);
$this
->
assertTrue
(
$this
->
component
->
detachEventHandler
(
'OnMyEvent'
,
'foo'
));
$this
->
assertEquals
(
$this
->
component
->
getEventHandlers
(
'OnMyEvent'
)
->
getCount
(),
1
);
$this
->
assertFalse
(
$this
->
component
->
detachEventHandler
(
'OnMyEvent'
,
'foo'
));
$this
->
assertEquals
(
$this
->
component
->
getEventHandlers
(
'OnMyEvent'
)
->
getCount
(),
1
);
$this
->
assertTrue
(
$this
->
component
->
detachEventHandler
(
'OnMyEvent'
,
array
(
$this
->
component
,
'myEventHandler'
)));
$this
->
assertEquals
(
$this
->
component
->
getEventHandlers
(
'OnMyEvent'
)
->
getCount
(),
0
);
$this
->
assertFalse
(
$this
->
component
->
detachEventHandler
(
'OnMyEvent'
,
'foo'
));
}
public
function
testRaiseEvent
()
{
$this
->
component
->
attachEventHandler
(
'OnMyEvent'
,
array
(
$this
->
component
,
'myEventHandler'
));
$this
->
assertFalse
(
$this
->
component
->
eventHandled
);
$this
->
component
->
raiseEvent
(
'OnMyEvent'
,
new
CEvent
(
$this
));
$this
->
assertTrue
(
$this
->
component
->
eventHandled
);
//$this->setExpectedException('CException');
//$this->component->raiseEvent('OnUnknown',new CEvent($this));
}
public
function
testEventAccessor
()
{
$component
=
new
NewComponent
;
$this
->
assertEquals
(
$component
->
onMyEvent
->
getCount
(),
0
);
$component
->
onMyEvent
=
'globalEventHandler'
;
$component
->
onMyEvent
=
array
(
$this
->
component
,
'myEventHandler'
);
$this
->
assertEquals
(
$component
->
onMyEvent
->
getCount
(),
2
);
$this
->
assertFalse
(
$component
->
eventHandled
);
$this
->
assertFalse
(
$this
->
component
->
eventHandled
);
$component
->
onMyEvent
();
$this
->
assertTrue
(
$component
->
eventHandled
);
$this
->
assertTrue
(
$this
->
component
->
eventHandled
);
}
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
);
}
public
function
testInvalidHandler1
()
{
$this
->
component
->
onMyEvent
=
array
(
1
,
2
,
3
);
$this
->
setExpectedException
(
'CException'
);
$this
->
component
->
onMyEvent
();
}
public
function
testInvalidHandler2
()
{
$this
->
component
->
onMyEvent
=
array
(
$this
->
component
,
'nullHandler'
);
$this
->
setExpectedException
(
'CException'
);
$this
->
component
->
onMyEvent
();
}
public
function
testDetachBehavior
()
{
$component
=
new
NewComponent
;
$behavior
=
new
NewBehavior
;
$component
->
attachBehavior
(
'a'
,
$behavior
);
$this
->
assertSame
(
$behavior
,
$component
->
detachBehavior
(
'a'
));
}
public
function
testDetachingBehaviors
()
{
$component
=
new
NewComponent
;
$behavior
=
new
NewBehavior
;
$component
->
attachBehavior
(
'a'
,
$behavior
);
$component
->
detachBehaviors
();
$this
->
setExpectedException
(
'CException'
);
$component
->
test
();
}
public
function
testEnablingBehavior
()
{
$component
=
new
NewComponent
;
$behavior
=
new
NewBehavior
;
$component
->
attachBehavior
(
'a'
,
$behavior
);
$component
->
disableBehavior
(
'a'
);
$this
->
assertFalse
(
$behavior
->
getEnabled
());
$component
->
enableBehavior
(
'a'
);
$this
->
assertTrue
(
$behavior
->
getEnabled
());
}
public
function
testEnablingBehaviors
()
{
$component
=
new
NewComponent
;
$behavior
=
new
NewBehavior
;
$component
->
attachBehavior
(
'a'
,
$behavior
);
$component
->
disableBehaviors
();
$this
->
assertFalse
(
$behavior
->
getEnabled
());
$component
->
enableBehaviors
();
$this
->
assertTrue
(
$behavior
->
getEnabled
());
}
public
function
testAsa
()
{
$component
=
new
NewComponent
;
$behavior
=
new
NewBehavior
;
$component
->
attachBehavior
(
'a'
,
$behavior
);
$this
->
assertSame
(
$behavior
,
$component
->
asa
(
'a'
));
}
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'
)));
}
}
tests/unit/phpunit.xml
0 → 100644
View file @
cd346119
<phpunit
bootstrap=
"bootstrap.php"
colors=
"false"
convertErrorsToExceptions=
"true"
convertNoticesToExceptions=
"true"
convertWarningsToExceptions=
"true"
stopOnFailure=
"false"
>
</phpunit>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment