Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
BRIC
dokuwiki
Commits
9e777cee
Commit
9e777cee
authored
12 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
simplified using the TestRequest class
You now can call get() or post() on it and give it all the wanted input variables
parent
5d0aaf95
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_test/core/TestRequest.php
+65
-0
65 additions, 0 deletions
_test/core/TestRequest.php
_test/tests/test/basic.test.php
+83
-0
83 additions, 0 deletions
_test/tests/test/basic.test.php
with
148 additions
and
0 deletions
_test/core/TestRequest.php
+
65
−
0
View file @
9e777cee
...
...
@@ -84,4 +84,69 @@ class TestRequest {
return
$response
;
}
/**
* Set the virtual URI the request works against
*
* This parses the given URI and sets any contained GET variables
* but will not overwrite any previously set ones (eg. set via setGet()).
*
* It initializes the $_SERVER['REQUEST_URI'] and $_SERVER['QUERY_STRING']
* with all set GET variables.
*
* @param string $url end URL to simulate, needs to start with /doku.php currently
*/
public
function
setUri
(
$uri
){
if
(
substr
(
$uri
,
0
,
9
)
!=
'/doku.php'
){
throw
new
Exception
(
"only '/doku.php' is supported currently"
);
}
$params
=
array
();
list
(
$uri
,
$query
)
=
explode
(
'?'
,
$uri
,
2
);
if
(
$query
)
parse_str
(
$query
,
$params
);
$this
->
get
=
array_merge
(
$params
,
$this
->
get
);
if
(
count
(
$this
->
get
)){
$query
=
'?'
.
http_build_query
(
$this
->
get
,
''
,
'&'
);
$query
=
str_replace
(
array
(
'%3A'
,
'%5B'
,
'%5D'
),
array
(
':'
,
'['
,
']'
),
$query
);
$uri
=
$uri
.
$query
;
}
$this
->
setServer
(
'QUERY_STRING'
,
$query
);
$this
->
setServer
(
'REQUEST_URI'
,
$uri
);
}
/**
* Simulate a POST request with the given variables
*
* @param array $post all the POST parameters to use
* @param string $url end URL to simulate, needs to start with /doku.php currently
* @param return TestResponse
*/
public
function
post
(
$post
=
array
(),
$uri
=
'/doku.php'
)
{
$this
->
setUri
(
$uri
);
$this
->
post
=
array_merge
(
$this
->
post
,
$post
);
$this
->
setServer
(
'REQUEST_METHOD'
,
'POST'
);
return
$this
->
execute
();
}
/**
* Simulate a GET request with the given variables
*
* @param array $GET all the POST parameters to use
* @param string $url end URL to simulate, needs to start with /doku.php currently
* @param return TestResponse
*/
public
function
get
(
$get
=
array
(),
$uri
=
'/doku.php'
)
{
$this
->
get
=
array_merge
(
$this
->
get
,
$get
);
$this
->
setUri
(
$uri
);
$this
->
setServer
(
'REQUEST_METHOD'
,
'GET'
);
return
$this
->
execute
();
}
}
This diff is collapsed.
Click to expand it.
_test/tests/test/basic.test.php
+
83
−
0
View file @
9e777cee
...
...
@@ -19,4 +19,87 @@ class InttestsBasicTest extends DokuWikiTest {
'DokuWiki was not a word in the output'
);
}
function
testPost
()
{
$request
=
new
TestRequest
();
$input
=
array
(
'string'
=>
'A string'
,
'array'
=>
array
(
1
,
2
,
3
),
'id'
=>
'wiki:dokuwiki'
);
$response
=
$request
->
post
(
$input
);
// server var check
$this
->
assertEquals
(
'POST'
,
$request
->
getServer
(
'REQUEST_METHOD'
));
$this
->
assertEquals
(
''
,
$request
->
getServer
(
'QUERY_STRING'
));
$this
->
assertEquals
(
'/doku.php'
,
$request
->
getServer
(
'REQUEST_URI'
));
// variable setup check
$this
->
assertEquals
(
'A string'
,
$request
->
getPost
(
'string'
));
$this
->
assertEquals
(
array
(
1
,
2
,
3
),
$request
->
getPost
(
'array'
));
$this
->
assertEquals
(
'wiki:dokuwiki'
,
$request
->
getPost
(
'id'
));
// output check
$this
->
assertTrue
(
strpos
(
$response
->
getContent
(),
'Andreas Gohr'
)
>=
0
);
}
function
testPostGet
()
{
$request
=
new
TestRequest
();
$input
=
array
(
'string'
=>
'A string'
,
'array'
=>
array
(
1
,
2
,
3
),
);
$response
=
$request
->
post
(
$input
,
'/doku.php?id=wiki:dokuwiki'
);
// server var check
$this
->
assertEquals
(
'POST'
,
$request
->
getServer
(
'REQUEST_METHOD'
));
$this
->
assertEquals
(
'?id=wiki:dokuwiki'
,
$request
->
getServer
(
'QUERY_STRING'
));
$this
->
assertEquals
(
'/doku.php?id=wiki:dokuwiki'
,
$request
->
getServer
(
'REQUEST_URI'
));
// variable setup check
$this
->
assertEquals
(
'A string'
,
$request
->
getPost
(
'string'
));
$this
->
assertEquals
(
array
(
1
,
2
,
3
),
$request
->
getPost
(
'array'
));
$this
->
assertEquals
(
'wiki:dokuwiki'
,
$request
->
getGet
(
'id'
));
// output check
$this
->
assertTrue
(
strpos
(
$response
->
getContent
(),
'Andreas Gohr'
)
>=
0
);
}
function
testGet
()
{
$request
=
new
TestRequest
();
$input
=
array
(
'string'
=>
'A string'
,
'array'
=>
array
(
1
,
2
,
3
),
'test'
=>
'bar'
);
$response
=
$request
->
get
(
$input
,
'/doku.php?id=wiki:dokuwiki&test=foo'
);
// server var check
$this
->
assertEquals
(
'GET'
,
$request
->
getServer
(
'REQUEST_METHOD'
));
$this
->
assertEquals
(
'?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3'
,
$request
->
getServer
(
'QUERY_STRING'
)
);
$this
->
assertEquals
(
'/doku.php?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3'
,
$request
->
getServer
(
'REQUEST_URI'
)
);
// variable setup check
$this
->
assertEquals
(
'A string'
,
$request
->
getGet
(
'string'
));
$this
->
assertEquals
(
array
(
1
,
2
,
3
),
$request
->
getGet
(
'array'
));
$this
->
assertEquals
(
'wiki:dokuwiki'
,
$request
->
getGet
(
'id'
));
$this
->
assertEquals
(
'bar'
,
$request
->
getGet
(
'test'
));
// output check
$this
->
assertTrue
(
strpos
(
$response
->
getContent
(),
'Andreas Gohr'
)
>=
0
);
}
}
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