delete queued transcription

This commit is contained in:
John Bintz 2009-08-11 18:16:23 -04:00
parent 92c07d5a1e
commit 28a7f50a49
2 changed files with 51 additions and 3 deletions

View File

@ -123,7 +123,7 @@ class WhatDidTheySay {
* Update a queued transcript.
* @param array $update_info The info on the transcript being updated.
*/
function update_queued_transcript($update_info) {
function update_queued_transcription($update_info) {
global $wpdb;
if ($this->is_user_allowed_to_update()) {
@ -145,6 +145,21 @@ class WhatDidTheySay {
}
}
}
function delete_queued_transcription($transcription_id) {
global $wpdb;
if ($this->is_user_allowed_to_update()) {
$query = $wpdb->prepare("SELECT id FROM %s WHERE id = %d", $this->table, $transcription_id);
if (!is_null($wpdb->get_var($query))) {
$query = $wpdb->prepare("DELETE FROM %s WHERE id = %d", $this->table, $transcription_id);
$wpdb->query($query);
return true;
}
}
return false;
}
}
?>

View File

@ -206,7 +206,40 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
wp_insert_post(array('ID' => 1));
$what->update_queued_transcript($update_info);
$what->update_queued_transcription($update_info);
}
function providerTestDeleteQueuedTranscription() {
return array(
array(array(), 1, false),
array(array(2), 1, false),
array(array(1), 1, true)
);
}
/**
* @dataProvider providerTestDeleteQueuedTranscription
*/
function testDeleteQueuedTranscription($valid_transcripts, $transcript_id_to_delete, $expected_result) {
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_var', 'query'));
$wpdb->expects($this->once())
->method('get_var')
->will($this->returnValue(in_array($transcript_id_to_delete, $valid_transcripts) ? $transcript_id_to_delete : null));
if (in_array($transcript_id_to_delete, $valid_transcripts)) {
$wpdb->expects($this->once())
->method('query');
}
$what->delete_queued_transcription($transcript_id_to_delete);
}
}