Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pquery
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
pquery
Commits
51f500d9
Commit
51f500d9
authored
Dec 08, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unit tests for Block class.
parent
49ff284b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
156 additions
and
25 deletions
+156
-25
test/utils/block.php
test/utils/block.php
+131
-0
utils/block.php
utils/block.php
+25
-25
No files found.
test/utils/block.php
0 → 100644
View file @
51f500d9
<?php
include_once
__DIR__
.
'/../config.php'
;
__p
::
load_utils
(
'block'
);
class
BlockTest
extends
PHPUnit_Framework_TestCase
{
var
$block
;
function
setUp
()
{
$this
->
block
=
new
Block
(
'foo'
);
}
function
test_constructor
()
{
$count
=
Block
::
$count
;
$block
=
new
Block
(
'foo'
);
$this
->
assertEquals
(
'foo'
,
$block
->
name
);
$this
->
assertEquals
(
$count
+
1
,
Block
::
$count
);
}
function
test_set_single
()
{
$block
=
$this
->
block
->
set
(
'bar'
,
'baz'
);
$this
->
assertEquals
(
'baz'
,
$this
->
block
->
vars
[
'bar'
]);
$this
->
assertSame
(
$this
->
block
,
$block
);
}
function
test_set_multiple
()
{
$data
=
array
(
'bar'
=>
'baz'
,
'bar2'
=>
'baz2'
);
$block
=
$this
->
block
->
set
(
$data
);
$this
->
assertEquals
(
$data
,
$this
->
block
->
vars
);
$this
->
assertSame
(
$this
->
block
,
$block
);
}
/**
* @depends test_set_single
*/
function
test_get_simple
()
{
$this
->
block
->
set
(
'bar'
,
'baz'
);
$this
->
assertEquals
(
'baz'
,
$this
->
block
->
get
(
'bar'
));
}
function
test_get_null
()
{
$this
->
assertNull
(
$this
->
block
->
get
(
'bar'
));
}
/**
* @depends test_get_simple
*/
function
test_getter
()
{
$this
->
block
->
set
(
'bar'
,
'baz'
);
$this
->
assertEquals
(
'baz'
,
$this
->
block
->
bar
);
}
/**
* @depends test_set_multiple
*/
function
test_add_empty
()
{
$block
=
$this
->
block
->
add
(
'bar'
);
$this
->
assertInstanceOf
(
'Block'
,
$block
);
$this
->
assertEquals
(
'bar'
,
$block
->
name
);
}
/**
* @depends test_get_simple
* @depends test_add_empty
*/
function
test_add_data
()
{
$block
=
$this
->
block
->
add
(
'bar'
,
array
(
'baz'
=>
'foo'
));
$this
->
assertEquals
(
'foo'
,
$block
->
get
(
'baz'
));
}
/**
* @depends test_add_empty
* @depends test_get_simple
*/
function
test_get_parent
()
{
$block
=
$this
->
block
->
set
(
'bar'
,
'baz'
)
->
add
(
'new-foo'
);
$this
->
assertEquals
(
'baz'
,
$block
->
get
(
'bar'
));
}
/**
* @depends test_add_empty
*/
function
test_find_single
()
{
$block
=
$this
->
block
->
add
(
'bar'
);
$this
->
block
->
add
(
'baz'
);
$this
->
assertSame
(
array
(
$block
),
$this
->
block
->
find
(
'bar'
));
}
/**
* @depends test_add_empty
*/
function
test_find_multiple
()
{
$block0
=
$this
->
block
->
add
(
'bar'
);
$block1
=
$this
->
block
->
add
(
'bar'
);
$this
->
block
->
add
(
'baz'
);
$this
->
assertSame
(
array
(
$block0
,
$block1
),
$this
->
block
->
find
(
'bar'
));
}
/**
* @depends test_add_empty
*/
function
test_find_none
()
{
$this
->
block
->
add
(
'bar'
);
$this
->
block
->
add
(
'baz'
);
$this
->
assertSame
(
array
(),
$this
->
block
->
find
(
'foo'
));
}
/**
* @depends test_add_empty
*/
function
test_remove_child
()
{
$block0
=
$this
->
block
->
add
(
'bar'
);
$block1
=
$this
->
block
->
add
(
'baz'
);
$ret
=
$this
->
block
->
remove_child
(
$block0
);
$this
->
assertSame
(
array
(
$block1
),
$this
->
block
->
children
);
$this
->
assertSame
(
$this
->
block
,
$ret
);
}
/**
* @depends test_remove_child
*/
function
test_remove
()
{
$block0
=
$this
->
block
->
add
(
'bar'
);
$block1
=
$this
->
block
->
add
(
'baz'
);
$ret
=
$block0
->
remove
();
$this
->
assertSame
(
array
(
$block1
),
$this
->
block
->
children
);
$this
->
assertSame
(
$block0
,
$ret
);
}
}
?>
\ No newline at end of file
utils/block.php
View file @
51f500d9
...
...
@@ -70,19 +70,6 @@ class Block {
$this
->
parent
=
$parent
;
}
/**
* Add a child block.
*
* @param string $name The name of the block to add.
* @param array $data Data to add to the created block (optional).
* @returns Block The created block.
*/
function
add
(
$name
,
$data
=
array
())
{
array_push
(
$this
->
children
,
$block
=
new
self
(
$name
,
$this
));
return
$block
->
set
(
$data
);
}
/**
* Set the value of one or more variables in the block.
*
...
...
@@ -100,18 +87,6 @@ class Block {
return
$this
;
}
/**
* Get the value of a variable.
*
* This method is an equivalent of {@link get()}.
*
* @param string $name The name of the variable to get the value of.
* @return mixed The value of the variable if it exists, NULL otherwise.
*/
function
__get
(
$name
)
{
return
$this
->
get
(
$name
);
}
/**
* Get the value of a variable.
*
...
...
@@ -131,6 +106,31 @@ class Block {
return
null
;
}
/**
* Get the value of a variable.
*
* This method is an equivalent of {@link get()}.
*
* @param string $name The name of the variable to get the value of.
* @return mixed The value of the variable if it exists, NULL otherwise.
*/
function
__get
(
$name
)
{
return
$this
->
get
(
$name
);
}
/**
* Add a child block.
*
* @param string $name The name of the block to add.
* @param array $data Data to add to the created block (optional).
* @returns Block The created block.
*/
function
add
(
$name
,
$data
=
array
())
{
array_push
(
$this
->
children
,
$block
=
new
self
(
$name
,
$this
));
return
$block
->
set
(
$data
);
}
/**
* Find all child blocks with a specified name.
*
...
...
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