Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
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
outils
question2answer
Commits
f91a1bda
Commit
f91a1bda
authored
Jul 26, 2017
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for qa_get_vote_view
parent
dd3eca21
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
7 deletions
+112
-7
options.php
qa-include/app/options.php
+7
-7
AppOptionsTest.php
qa-tests/AppOptionsTest.php
+105
-0
No files found.
qa-include/app/options.php
View file @
f91a1bda
...
...
@@ -642,13 +642,13 @@ function qa_message_html_defaults()
/**
* Return $voteview parameter to pass to qa_post_html_fields() in qa-app-format.php
for the post in $postorbasetype
*
with buttons enabled if appropriate (based on whether $full post shown) unless $enabledif is false.
*
For compatibility $postorbasetype can also just be a basetype, i.e. 'Q', 'A' or 'C'
* @param
$postorbasetype
* @
param bool $full
*
@param bool $enabledif
*
@return bool|string
* Return $voteview parameter to pass to qa_post_html_fields() in qa-app-format.php
.
*
@param $postorbasetype The post, or for compatibility just a basetype, i.e. 'Q', 'A' or 'C'
*
@param bool $full Whether full post is shown
* @param
bool $enabledif Whether to do checks for voting buttons (i.e. will always disable voting if false)
* @
return bool|string Possible values:
*
updown, updown-disabled-page, updown-disabled-level, updown-uponly-level, updown-disabled-approve, updown-uponly-approve
*
net, net-disabled-page, net-disabled-level, net-uponly-level, net-disabled-approve, net-uponly-approve
*/
function
qa_get_vote_view
(
$postorbasetype
,
$full
=
false
,
$enabledif
=
true
)
{
...
...
qa-tests/AppOptionsTest.php
0 → 100644
View file @
f91a1bda
<?php
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
require_once
QA_INCLUDE_DIR
.
'app/options.php'
;
class
AppOptionsTest
extends
PHPUnit_Framework_TestCase
{
private
$voteviewOpts
=
array
(
'voting_on_qs'
=>
1
,
'voting_on_as'
=>
1
,
'voting_on_cs'
=>
1
,
'voting_on_q_page_only'
=>
1
,
'votes_separated'
=>
0
,
'permit_vote_a'
=>
QA_PERMIT_USERS
,
'permit_vote_q'
=>
QA_PERMIT_USERS
,
'permit_vote_down'
=>
QA_PERMIT_USERS
,
);
private
$mockUser
=
array
(
'userid'
=>
'1'
,
'passsalt'
=>
null
,
'passcheck'
=>
null
,
'passhash'
=>
'passhash'
,
'email'
=>
'email'
,
'level'
=>
'120'
,
'emailcode'
=>
''
,
'handle'
=>
'admin'
,
'created'
=>
''
,
'sessioncode'
=>
''
,
'sessionsource'
=>
null
,
'flags'
=>
'265'
,
'loggedin'
=>
''
,
'loginip'
=>
''
,
'written'
=>
''
,
'writeip'
=>
''
,
'avatarblobid'
=>
''
,
'avatarwidth'
=>
''
,
'avatarheight'
=>
''
,
'points'
=>
'100'
,
'wallposts'
=>
'6'
,
);
/**
* Test voteview where upvotes/downvotes are combined
*/
public
function
test__qa_get_vote_view__net
()
{
// set options/user cache to bypass database
global
$qa_options_cache
,
$qa_curr_ip_blocked
,
$qa_cached_logged_in_user
;
$qa_options_cache
=
array_merge
(
$qa_options_cache
,
$this
->
voteviewOpts
);
$qa_curr_ip_blocked
=
false
;
$qa_cached_logged_in_user
=
$this
->
mockUser
;
$this
->
assertSame
(
'net'
,
qa_get_vote_view
(
'Q'
,
true
));
$this
->
assertSame
(
'net-disabled-page'
,
qa_get_vote_view
(
'Q'
,
false
));
$this
->
assertSame
(
'net-disabled-page'
,
qa_get_vote_view
(
'Q'
,
true
,
false
));
$this
->
assertSame
(
'net-disabled-page'
,
qa_get_vote_view
(
'Q'
,
false
,
false
));
$this
->
assertSame
(
'net'
,
qa_get_vote_view
(
'A'
,
true
));
$this
->
assertSame
(
'net'
,
qa_get_vote_view
(
'A'
,
false
));
$this
->
assertSame
(
'net-disabled-page'
,
qa_get_vote_view
(
'A'
,
true
,
false
));
$this
->
assertSame
(
'net-disabled-page'
,
qa_get_vote_view
(
'A'
,
false
,
false
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'C'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'C'
,
false
));
$qa_options_cache
[
'voting_on_qs'
]
=
0
;
$qa_options_cache
[
'voting_on_as'
]
=
0
;
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'Q'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'A'
,
true
));
}
/**
* Test voteview where upvotes/downvotes are separated
*/
public
function
test__qa_get_vote_view__updown
()
{
// set options/user cache to bypass database
global
$qa_options_cache
,
$qa_curr_ip_blocked
,
$qa_cached_logged_in_user
;
$qa_options_cache
=
array_merge
(
$qa_options_cache
,
$this
->
voteviewOpts
,
array
(
'votes_separated'
=>
1
));
$qa_curr_ip_blocked
=
false
;
$qa_cached_logged_in_user
=
$this
->
mockUser
;
$this
->
assertSame
(
'updown'
,
qa_get_vote_view
(
'Q'
,
true
));
$this
->
assertSame
(
'updown-disabled-page'
,
qa_get_vote_view
(
'Q'
,
false
));
$this
->
assertSame
(
'updown-disabled-page'
,
qa_get_vote_view
(
'Q'
,
true
,
false
));
$this
->
assertSame
(
'updown-disabled-page'
,
qa_get_vote_view
(
'Q'
,
false
,
false
));
$this
->
assertSame
(
'updown'
,
qa_get_vote_view
(
'A'
,
true
));
$this
->
assertSame
(
'updown'
,
qa_get_vote_view
(
'A'
,
false
));
$this
->
assertSame
(
'updown-disabled-page'
,
qa_get_vote_view
(
'A'
,
true
,
false
));
$this
->
assertSame
(
'updown-disabled-page'
,
qa_get_vote_view
(
'A'
,
false
,
false
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'C'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'C'
,
false
));
$qa_options_cache
[
'voting_on_qs'
]
=
0
;
$qa_options_cache
[
'voting_on_as'
]
=
0
;
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'Q'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'A'
,
true
));
}
}
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