update authentication stuff
This commit is contained in:
parent
7bed32fbff
commit
d1b1cb4834
|
@ -20,6 +20,7 @@ class WhatDidTheySay {
|
||||||
* @return bool True if the transcript was saved, false otherwise.
|
* @return bool True if the transcript was saved, false otherwise.
|
||||||
*/
|
*/
|
||||||
function save_transcript($post_id, $language, $transcript) {
|
function save_transcript($post_id, $language, $transcript) {
|
||||||
|
if ($this->is_user_allowed_to_update()) {
|
||||||
$post = get_post($post_id);
|
$post = get_post($post_id);
|
||||||
if (!empty($post)) {
|
if (!empty($post)) {
|
||||||
$current_transcripts = get_post_meta($post_id, "provided_transcripts", true);
|
$current_transcripts = get_post_meta($post_id, "provided_transcripts", true);
|
||||||
|
@ -29,6 +30,7 @@ class WhatDidTheySay {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the languages that the approved transcripts for the post are written in.
|
* Get the languages that the approved transcripts for the post are written in.
|
||||||
|
@ -51,6 +53,7 @@ class WhatDidTheySay {
|
||||||
function get_queued_transcriptions_for_post($post_id) {
|
function get_queued_transcriptions_for_post($post_id) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
if ($this->is_user_allowed_to_update()) {
|
||||||
$post = get_post($post_id);
|
$post = get_post($post_id);
|
||||||
if (!empty($post)) {
|
if (!empty($post)) {
|
||||||
$query = $wpdb->prepare('SELECT * FROM %s WHERE post_id = %d', $this->table, $post_id);
|
$query = $wpdb->prepare('SELECT * FROM %s WHERE post_id = %d', $this->table, $post_id);
|
||||||
|
@ -66,6 +69,7 @@ class WhatDidTheySay {
|
||||||
return $valid_results;
|
return $valid_results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +81,7 @@ class WhatDidTheySay {
|
||||||
function add_queued_transcription_to_post($post_id, $transcript_info) {
|
function add_queued_transcription_to_post($post_id, $transcript_info) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
if ($this->is_user_allowed_to_update()) {
|
||||||
$post = get_post($post_id);
|
$post = get_post($post_id);
|
||||||
if (!empty($post)) {
|
if (!empty($post)) {
|
||||||
$transcript_info = (array)$transcript_info;
|
$transcript_info = (array)$transcript_info;
|
||||||
|
@ -99,6 +104,7 @@ class WhatDidTheySay {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,18 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
||||||
function testSaveTranscription() {
|
function testSaveTranscription() {
|
||||||
wp_insert_post(array('ID' => 1));
|
wp_insert_post(array('ID' => 1));
|
||||||
|
|
||||||
$this->what->save_transcript(1, "en", "This is a transcript");
|
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update'));
|
||||||
|
$what->expects($this->any())
|
||||||
|
->method('is_user_allowed_to_update')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
|
$what->save_transcript(1, "en", "This is a transcript");
|
||||||
$this->assertEquals(array("en" => "This is a transcript"), get_post_meta(1, "provided_transcripts", true));
|
$this->assertEquals(array("en" => "This is a transcript"), get_post_meta(1, "provided_transcripts", true));
|
||||||
|
|
||||||
$this->what->save_transcript(1, "en", "this is a new transcript");
|
$what->save_transcript(1, "en", "this is a new transcript");
|
||||||
$this->assertEquals(array("en" => "this is a new transcript"), get_post_meta(1, "provided_transcripts", true));
|
$this->assertEquals(array("en" => "this is a new transcript"), get_post_meta(1, "provided_transcripts", true));
|
||||||
|
|
||||||
$this->what->save_transcript(1, "fr", "il s'agit d'une nouvelle transcription");
|
$what->save_transcript(1, "fr", "il s'agit d'une nouvelle transcription");
|
||||||
$this->assertEquals(array("en" => "this is a new transcript", "fr" => "il s'agit d'une nouvelle transcription"), get_post_meta(1, "provided_transcripts", true));
|
$this->assertEquals(array("en" => "this is a new transcript", "fr" => "il s'agit d'une nouvelle transcription"), get_post_meta(1, "provided_transcripts", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,9 +43,14 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
||||||
wp_insert_user(array('ID' => 1, 'first_name' => 'Test', 'last_name' => 'User'));
|
wp_insert_user(array('ID' => 1, 'first_name' => 'Test', 'last_name' => 'User'));
|
||||||
wp_insert_post(array('ID' => 1));
|
wp_insert_post(array('ID' => 1));
|
||||||
|
|
||||||
|
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update'));
|
||||||
|
$what->expects($this->any())
|
||||||
|
->method('is_user_allowed_to_update')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
$wpdb = $this->getMock('wpdb', array('get_results', 'prepare'));
|
$wpdb = $this->getMock('wpdb', array('get_results', 'prepare'));
|
||||||
|
|
||||||
$expected_query = sprintf("SELECT * FROM '%s' WHERE post_id = '%d'", $this->what->table, 1);
|
$expected_query = sprintf("SELECT * FROM '%s' WHERE post_id = '%d'", $what->table, 1);
|
||||||
|
|
||||||
$wpdb->expects($this->once())
|
$wpdb->expects($this->once())
|
||||||
->method('prepare')
|
->method('prepare')
|
||||||
|
@ -68,10 +78,10 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
||||||
'transcript' => 'This is a transcript'
|
'transcript' => 'This is a transcript'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
$this->what->get_queued_transcriptions_for_post(1)
|
$what->get_queued_transcriptions_for_post(1)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertFalse($this->what->get_queued_transcriptions_for_post(2));
|
$this->assertFalse($what->get_queued_transcriptions_for_post(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
function providerTestAddQueuedTranscriptionToPost() {
|
function providerTestAddQueuedTranscriptionToPost() {
|
||||||
|
@ -113,6 +123,11 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
||||||
->method('prepare')
|
->method('prepare')
|
||||||
->will($this->returnValue($expected_query));
|
->will($this->returnValue($expected_query));
|
||||||
|
|
||||||
|
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update'));
|
||||||
|
$what->expects($this->any())
|
||||||
|
->method('is_user_allowed_to_update')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
if ($expected_result === true) {
|
if ($expected_result === true) {
|
||||||
$wpdb->expects($this->once())
|
$wpdb->expects($this->once())
|
||||||
->method('query')
|
->method('query')
|
||||||
|
@ -120,7 +135,7 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals($expected_result, $this->what->add_queued_transcription_to_post(
|
$this->assertEquals($expected_result, $what->add_queued_transcription_to_post(
|
||||||
1,
|
1,
|
||||||
array(
|
array(
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
|
|
Loading…
Reference in New Issue