add transcription to post

This commit is contained in:
John Bintz 2009-08-12 19:02:36 -04:00
parent d1b1cb4834
commit 1dab0b4522
2 changed files with 62 additions and 1 deletions

View File

@ -137,7 +137,7 @@ class WhatDidTheySay {
$query = $wpdb->prepare("SELECT * FROM %s WHERE id = %d", $this->table, $update_info['id']);
$result = $wpdb->get_results($query);
if (!empty($result)) {
if (is_array($result)) {
if (count($result) == 1) {
$result = $result[0];
foreach (array('language', 'transcript') as $field) {
@ -174,6 +174,28 @@ class WhatDidTheySay {
}
return false;
}
function add_transcription_to_post($transcription_id) {
global $wpdb;
if ($this->is_user_allowed_to_update()) {
$query = $wpdb->prepare("SELECT * from %s WHERE id = %d", $this->table, $transcription_id);
$result = $wpdb->get_results($query);
if (is_array($result)) {
if (count($result) == 1) {
$result = (object)$result[0];
$post = get_post($result->post_id);
if (!empty($post)) {
$this->save_transcript($result->post_id, $result->language, $result->transcript);
$query = $wpdb->prepare("DELETE FROM %s WHERE id = %d", $this->table, $transcription_id);
$result = $wpdb->query($query);
}
}
}
}
}
}
?>

View File

@ -256,6 +256,45 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
$what->delete_queued_transcription($transcript_id_to_delete);
}
function providerTestAddTranscriptionToPost() {
return array(
array(null, false),
array((object)array('id' => 1, 'post_id' => 2), false),
array((object)array('id' => 1, 'post_id' => 1, 'language' => 'en', 'transcript' => 'This is a transcript'), true)
);
}
/**
* @dataProvider providerTestAddTranscriptionToPost
*/
function testAddTranscriptionToPost($get_results_return, $expects_delete) {
global $wpdb;
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update', 'save_transcript'));
$what->expects($this->once())
->method('is_user_allowed_to_update')
->will($this->returnValue(true));
wp_insert_post((object)array('ID' => 1));
$wpdb = $this->getMock('wpdb', array('get_results', 'prepare', 'query'));
$wpdb->expects($this->once())
->method('get_results')
->will($this->returnValue(array($get_results_return)));
if ($expects_delete) {
$wpdb->expects($this->at(2))
->method('prepare')
->with(new PHPUnit_Framework_Constraint_PCREMatch('#DELETE FROM .* WHERE id = .*#'));
$what->expects($this->once())
->method('save_transcript');
}
$what->add_transcription_to_post(1);
}
}
?>