From 28a7f50a496b2e824168cbf70807c7322f1edfb7 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 11 Aug 2009 18:16:23 -0400 Subject: [PATCH] delete queued transcription --- classes/WhatDidTheySay.php | 17 ++++++++++++++++- test/WhatDidTheySayTest.php | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/classes/WhatDidTheySay.php b/classes/WhatDidTheySay.php index c7ccced..b92a646 100644 --- a/classes/WhatDidTheySay.php +++ b/classes/WhatDidTheySay.php @@ -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; + } } ?> diff --git a/test/WhatDidTheySayTest.php b/test/WhatDidTheySayTest.php index 199f5c5..303db78 100644 --- a/test/WhatDidTheySayTest.php +++ b/test/WhatDidTheySayTest.php @@ -201,12 +201,45 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase { if ($in_array) { $wpdb->expects($this->once()) - ->method('query'); + ->method('query'); } 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); } }