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
0adf6150
Commit
0adf6150
authored
Nov 08, 2011
by
Taddes Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unit tests for 'template' plugin.
parent
b3fc6f02
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
135 additions
and
7 deletions
+135
-7
pquery.php
pquery.php
+23
-3
pquery.template.php
pquery.template.php
+6
-0
test/index.php
test/index.php
+2
-2
test/templates/expect_parse.txt
test/templates/expect_parse.txt
+39
-0
test/test_template.php
test/test_template.php
+65
-2
No files found.
pquery.php
View file @
0adf6150
...
...
@@ -115,7 +115,7 @@ class pQuery {
*/
static
function
error
(
$error
/* , $arg1, $arg2... */
)
{
$args
=
func_get_args
();
$error
=
nl2br
(
call_user_func_array
(
'sprintf'
,
$args
)
);
$error
=
call_user_func_array
(
'sprintf'
,
$args
);
throw
new
pQueryException
(
$error
);
}
...
...
@@ -251,6 +251,21 @@ class pQuery {
if
(
in_array
(
$name
,
(
array
)
$class_name
::
$variable_alias
)
)
$this
->
variable
=
$value
;
}
/**
* Handler for pQuery exceptions.
*
* If the execption is a (@link pQueryException}, exit the script with
* its message. Otherwise, throw the exception further.
*
* @param Exception $e The exception to handle.
*/
function
exception_handler
(
$e
)
{
if
(
$e
instanceof
pQueryException
)
die
(
nl2br
(
$e
->
getMessage
()));
throw
$e
;
}
}
/**
...
...
@@ -299,9 +314,14 @@ function _p($variable, $plugin=null) {
return
new
$class_name
(
$variable
);
}
/*
*
/*
* Set an alias for the bas class consistent with plugin aliases.
*/
class_alias
(
'pQuery'
,
'__p'
);
/*
* Set the exception handler
*/
set_exception_handler
(
'__p::exception_handler'
);
?>
\ No newline at end of file
pquery.template.php
View file @
0adf6150
...
...
@@ -248,8 +248,14 @@ function _tpl($path) {
return
pQuery
::
create
(
'tpl'
,
$path
);
}
/*
* Add plugin to pQuery
*/
__p
::
extend
(
'pQueryTemplate'
,
'tpl'
);
/*
* Set initial root to pQuery root folder
*/
__tpl
::
set_root
(
''
);
?>
\ No newline at end of file
test/index.php
View file @
0adf6150
...
...
@@ -28,9 +28,9 @@ while( !$a->is_empty() ) {
$results = $sql->fetch_all('object');
$results = _arr($results);
debug($results);
debug($results);
*/
__tpl::set_root('templates', false);
/*
__tpl::set_root('templates', false);
$tpl = _tpl('test.tpl');
$test1 = $tpl->data->add('test1', array('var' => 'some-variable'));
...
...
test/templates/expect_parse.txt
0 → 100644
View file @
0adf6150
lorem
block:test1
ipsum
SOME-VARIABLE
{not_a_variable}
block:test2
dolor
end:test2
sit
end:test1
block:test1
ipsum
SOME-OTHER-VARIABLE
{not_a_variable}
sit
end:test1
amet
block:test3
consectetur
end:test3
adipiscing
\ No newline at end of file
test/test_template.php
View file @
0adf6150
...
...
@@ -3,12 +3,75 @@
__p
::
load_plugin
(
'template'
);
class
pQueryTemplateTest
extends
UnitTestCase
{
const
TEMPLATES_FOLDER
=
'templates/'
;
var
$templates_folder
;
var
$file
;
var
$tpl
;
function
__construct
()
{
parent
::
__construct
(
'pQuery template plugin'
);
}
function
test_
()
{
function
setUp
()
{
$this
->
templates_folder
=
PQUERY_ROOT
.
'test/'
.
self
::
TEMPLATES_FOLDER
;
__tpl
::
set_root
(
$this
->
templates_folder
,
false
);
$this
->
file
=
'test.tpl'
;
$this
->
tpl
=
_tpl
(
$this
->
file
);
}
function
test_add_root_relative
()
{
$folder
=
PQUERY_ROOT
.
'test/'
;
$folder_relative
=
'test/'
;
__tpl
::
add_root
(
$folder_relative
);
$this
->
assertTrue
(
in_array
(
$folder
,
__tpl
::
$include_path
),
'folder was not added to include path'
);
}
function
test_add_root_absolute
()
{
$folder
=
PQUERY_ROOT
.
'test/'
;
__tpl
::
add_root
(
$folder
,
false
);
$this
->
assertTrue
(
in_array
(
$folder
,
__tpl
::
$include_path
),
'folder was not added to include path'
);
}
function
test_add_root_failure
()
{
$this
->
expectException
(
'pQueryException'
);
__tpl
::
add_root
(
'non_existing_folder'
);
}
function
test_set_root_relative
()
{
$folder
=
PQUERY_ROOT
.
'test/'
;
$folder_relative
=
'test/'
;
__tpl
::
set_root
(
$folder_relative
);
$this
->
assertEqual
(
array
(
$folder
),
__tpl
::
$include_path
,
'folder was not set as only include path'
);
}
function
test_set_root_absolute
()
{
$folder
=
PQUERY_ROOT
.
'test/'
;
__tpl
::
set_root
(
$folder
,
false
);
$this
->
assertEqual
(
array
(
$folder
),
__tpl
::
$include_path
,
'folder was not set as only include path'
);
}
function
test_constructor
()
{
$this
->
assertIsA
(
$this
->
tpl
,
'pQueryTemplate'
,
'constructor does not return pQueryTemplate object'
);
}
function
test_open_template_file
()
{
$path
=
$this
->
templates_folder
.
$this
->
file
;
$content
=
file_get_contents
(
$path
);
$this
->
assertEqual
(
$this
->
tpl
->
content
,
$content
,
'template content is not set correctly'
);
}
function
test_non_existent_file
()
{
$this
->
expectException
(
'pQueryException'
);
_tpl
(
'non_existent_file.tpl'
);
}
function
test_parse
()
{
$expected_content
=
file_get_contents
(
$this
->
templates_folder
.
'expect_parse.txt'
);
$test1
=
$this
->
tpl
->
data
->
add
(
'test1'
,
array
(
'var'
=>
'some-variable'
));
$this
->
tpl
->
data
->
add
(
'test1'
,
array
(
'var'
=>
'some-other-variable'
));
$test1
->
add
(
'test2'
);
$this
->
tpl
->
data
->
add
(
'test3'
);
$this
->
assertEqual
(
$this
->
tpl
->
parse
(),
$expected_content
,
'parsed templated does not match expected content'
);
}
}
...
...
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