Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pquery
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
pquery
Commits
51f500d9
Commit
51f500d9
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added unit tests for Block class.
parent
49ff284b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/utils/block.php
+131
-0
131 additions, 0 deletions
test/utils/block.php
utils/block.php
+25
-25
25 additions, 25 deletions
utils/block.php
with
156 additions
and
25 deletions
test/utils/block.php
0 → 100644
+
131
−
0
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
This diff is collapsed.
Click to expand it.
utils/block.php
+
25
−
25
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.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment