add queued transcription
This commit is contained in:
parent
95e112c343
commit
b3a80ad967
@ -32,7 +32,8 @@ class WhatDidTheySay {
|
|||||||
|
|
||||||
$post = get_post($post_id);
|
$post = get_post($post_id);
|
||||||
if (!empty($post)) {
|
if (!empty($post)) {
|
||||||
$results = $wpdb->get_results(sprintf("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);
|
||||||
|
$results = $wpdb->get_results($query);
|
||||||
if (!empty($results)) {
|
if (!empty($results)) {
|
||||||
$valid_results = array();
|
$valid_results = array();
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
@ -46,6 +47,34 @@ class WhatDidTheySay {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_queued_transcription_to_post($post_id, $transcript_info) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$post = get_post($post_id);
|
||||||
|
if (!empty($post)) {
|
||||||
|
$transcript_info = (array)$transcript_info;
|
||||||
|
if (!empty($transcript_info)) {
|
||||||
|
$ok = true;
|
||||||
|
foreach (array('language', 'transcript') as $field) {
|
||||||
|
if (empty($transcript_info[$field])) { $ok = false; break; }
|
||||||
|
}
|
||||||
|
if ($ok) {
|
||||||
|
extract($transcript_info);
|
||||||
|
$user = get_userdata($user_id);
|
||||||
|
if (!empty($user)) {
|
||||||
|
$query = $wpdb->prepare(
|
||||||
|
"INSERT INTO %s (post_id, user_id, language, transcript) VALUES (%d, %d, %s, %s)",
|
||||||
|
$this->table, $post_id, $user_id, $language, $transcript
|
||||||
|
);
|
||||||
|
|
||||||
|
return $wpdb->query($query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -36,10 +36,17 @@ 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));
|
||||||
|
|
||||||
$wpdb = $this->getMock('wpdb', array('get_results'));
|
$wpdb = $this->getMock('wpdb', array('get_results', 'prepare'));
|
||||||
|
|
||||||
|
$expected_query = sprintf("SELECT * FROM '%s' WHERE post_id = '%d'", $this->what->table, 1);
|
||||||
|
|
||||||
|
$wpdb->expects($this->once())
|
||||||
|
->method('prepare')
|
||||||
|
->will($this->returnValue($expected_query));
|
||||||
|
|
||||||
$wpdb->expects($this->once())
|
$wpdb->expects($this->once())
|
||||||
->method('get_results')
|
->method('get_results')
|
||||||
->with(sprintf('SELECT * FROM %s WHERE post_id = 1', $this->what->table))
|
->with($expected_query)
|
||||||
->will(
|
->will(
|
||||||
$this->returnValue(
|
$this->returnValue(
|
||||||
array(
|
array(
|
||||||
@ -49,8 +56,6 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$result =
|
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
array(
|
||||||
(object)array(
|
(object)array(
|
||||||
@ -66,6 +71,62 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
$this->assertFalse($this->what->get_queued_transcriptions_for_post(2));
|
$this->assertFalse($this->what->get_queued_transcriptions_for_post(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function providerTestAddQueuedTranscriptionToPost() {
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
array(1, 1, "en", "This is a transcript"), true
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(2, 1, "en", "This is a transcript"), false
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(1, 2, "en", "This is a transcript"), false
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(1, 1, "", "This is a transcript"), false
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(1, 1, "en", ""), false
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestAddQueuedTranscriptionToPost
|
||||||
|
*/
|
||||||
|
function testAddQueuedTranscriptionToPost($query_settings, $expected_result) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
wp_insert_user(array('ID' => 1, 'first_name' => 'Test', 'last_name' => 'User'));
|
||||||
|
wp_insert_post(array('ID' => 1));
|
||||||
|
|
||||||
|
$expected_query = sprintf("INSERT INTO '%s' (post_id, user_id, language, transcript) VALUES ('%d', '%d', '%s', '%s')",
|
||||||
|
$this->what->table,
|
||||||
|
1, 1, "en", "This is a transcript");
|
||||||
|
|
||||||
|
$wpdb = $this->getMock('wpdb', array('query', 'prepare'));
|
||||||
|
|
||||||
|
$wpdb->expects($this->once())
|
||||||
|
->method('prepare')
|
||||||
|
->will($this->returnValue($expected_query));
|
||||||
|
|
||||||
|
if ($expected_result === true) {
|
||||||
|
$wpdb->expects($this->once())
|
||||||
|
->method('query')
|
||||||
|
->with($expected_query)
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($expected_result, $this->what->add_queued_transcription_to_post(
|
||||||
|
1,
|
||||||
|
array(
|
||||||
|
'user_id' => 1,
|
||||||
|
'language' => 'en',
|
||||||
|
'transcript' => "This is a transcript"
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user