break out authentication
This commit is contained in:
parent
1e6b3b64fb
commit
92c07d5a1e
|
@ -102,13 +102,7 @@ class WhatDidTheySay {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a queued transcript.
|
||||
* @param array $update_info The info on the transcript being updated.
|
||||
*/
|
||||
function update_queued_transcript($update_info) {
|
||||
global $wpdb;
|
||||
|
||||
function is_user_allowed_to_update() {
|
||||
$options = get_option('what-did-they-say-options');
|
||||
$user_info = wp_get_current_user();
|
||||
|
||||
|
@ -122,7 +116,17 @@ class WhatDidTheySay {
|
|||
}
|
||||
}
|
||||
|
||||
if ($ok) {
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a queued transcript.
|
||||
* @param array $update_info The info on the transcript being updated.
|
||||
*/
|
||||
function update_queued_transcript($update_info) {
|
||||
global $wpdb;
|
||||
|
||||
if ($this->is_user_allowed_to_update()) {
|
||||
$query = $wpdb->prepare("SELECT * FROM %s WHERE id = %d", $this->table, $update_info['id']);
|
||||
$result = $wpdb->get_results($query);
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
function testSaveTranscription() {
|
||||
wp_insert_post(array('ID' => 1));
|
||||
|
||||
$this->what->save_transcript(1, "en", "This is a transcript");
|
||||
$this->assertEquals(array("en" => "This is a transcript"), get_post_meta(1, "provided_transcripts", true));
|
||||
|
||||
|
@ -128,33 +130,49 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
|||
));
|
||||
}
|
||||
|
||||
function providerTestIsUserAllowedToUpdate() {
|
||||
return array(
|
||||
array(
|
||||
false, array(), array(), 1, false
|
||||
),
|
||||
array(
|
||||
false, array('edit_posts'), array(), 1, true
|
||||
),
|
||||
array(
|
||||
true, array(), array(2), 1, false
|
||||
),
|
||||
array(
|
||||
true, array(), array(1), 1, true
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestIsUserAllowedToUpdate
|
||||
*/
|
||||
function testIsUserAllowedToUpdate($only_allowed_users, $current_user_can, $allowed_users, $current_user_id, $expected_result) {
|
||||
update_option('what-did-they-say-options', array('allowed_users' => $allowed_users, 'only_allowed_users' => $only_allowed_users));
|
||||
_set_user_capabilities($current_user_can);
|
||||
wp_insert_user(array('ID' => 1, 'first_name' => 'Test', 'last_name' => 'User'));
|
||||
wp_set_current_user($current_user_id);
|
||||
|
||||
$this->assertEquals($expected_result, $this->what->is_user_allowed_to_update());
|
||||
}
|
||||
|
||||
function providerTestUpdateQueuedTranscription() {
|
||||
return array(
|
||||
array(
|
||||
false, array(), array(), array(), 1, array("language" => "en", "transcript" => "This")
|
||||
array(), array("language" => "en", "transcript" => "This")
|
||||
),
|
||||
array(
|
||||
false, array('edit_posts'), array(), array(), 1, array("language" => "en", "transcript" => "This")
|
||||
),
|
||||
array(
|
||||
false, array('edit_posts'), array(
|
||||
(object)array('ID' => 1)
|
||||
), array(), 1, array("language" => "en", "transcript" => "This")
|
||||
), array("language" => "en", "transcript" => "This")
|
||||
),
|
||||
array(
|
||||
false, array('edit_posts'), array(
|
||||
(object)array('ID' => 1)
|
||||
), array(), 1, array("language" => "en", "transcript" => "This", 'id' => 1)
|
||||
),
|
||||
array(
|
||||
true, array(), array(
|
||||
(object)array('ID' => 1)
|
||||
), array(2), 1, array("language" => "en", "transcript" => "This", 'id' => 1)
|
||||
),
|
||||
array(
|
||||
true, array(), array(
|
||||
(object)array('ID' => 1)
|
||||
), array(1), 1, array("language" => "en", "transcript" => "This", 'id' => 1)
|
||||
), array("language" => "en", "transcript" => "This", 'id' => 1)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -162,24 +180,16 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
|||
/**
|
||||
* @dataProvider providerTestUpdateQueuedTranscription
|
||||
*/
|
||||
function testUpdateQueuedTranscription($only_allowed_users, $current_user_can, $valid_transcripts, $allowed_users, $current_user_id, $update_info) {
|
||||
function testUpdateQueuedTranscription($valid_transcripts, $update_info) {
|
||||
global $wpdb;
|
||||
|
||||
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update'));
|
||||
$what->expects($this->once())
|
||||
->method('is_user_allowed_to_update')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$wpdb = $this->getMock('wpdb', array('prepare', 'get_results', 'query'));
|
||||
update_option('what-did-they-say-options', array('allowed_users' => $allowed_users, 'only_allowed_users' => $only_allowed_users));
|
||||
|
||||
_set_user_capabilities($current_user_can);
|
||||
|
||||
if ($only_allowed_users) {
|
||||
$will_search_transcripts = (in_array($current_user_id, $allowed_users));
|
||||
} else {
|
||||
$will_search_transcripts = true;
|
||||
if (!in_array('edit_posts', $current_user_can)) {
|
||||
$will_search_transcripts = (in_array($current_user_id, $allowed_users));
|
||||
}
|
||||
}
|
||||
|
||||
if ($will_search_transcripts) {
|
||||
$wpdb->expects($this->once())
|
||||
->method('get_results')
|
||||
->will($this->returnValue($valid_transcripts));
|
||||
|
@ -193,13 +203,10 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
|||
$wpdb->expects($this->once())
|
||||
->method('query');
|
||||
}
|
||||
}
|
||||
|
||||
wp_insert_post(array('ID' => 1));
|
||||
wp_insert_user(array('ID' => 1, 'first_name' => 'Test', 'last_name' => 'User'));
|
||||
wp_set_current_user($current_user_id);
|
||||
|
||||
$this->what->update_queued_transcript($update_info);
|
||||
$what->update_queued_transcript($update_info);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue