delete transcript

This commit is contained in:
John Bintz 2009-08-12 19:12:52 -04:00
parent 1dab0b4522
commit 4cdd2985ac
2 changed files with 32 additions and 4 deletions

View File

@ -196,6 +196,17 @@ class WhatDidTheySay {
} }
} }
} }
function delete_transcript($post_id, $language) {
if ($this->is_user_allowed_to_update()) {
$post = get_post($post_id);
if (!empty($post)) {
$current_transcripts = get_post_meta($post_id, "provided_transcripts", true);
unset($current_transcripts[$language]);
update_post_meta($post_id, "provided_transcripts", $current_transcripts);
}
}
}
} }
?> ?>

View File

@ -7,7 +7,6 @@ require_once(dirname(__FILE__) . '/../classes/WhatDidTheySay.php');
class WhatDidTheySayTest extends PHPUnit_Framework_TestCase { class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
function setUp() { function setUp() {
global $wpdb; global $wpdb;
$this->what = new WhatDidTheySay();
_reset_wp(); _reset_wp();
$wpdb = null; $wpdb = null;
} }
@ -31,10 +30,12 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
} }
function testGetListOfLanguagesForPost() { function testGetListOfLanguagesForPost() {
update_post_meta(1, "provided_transcripts", array('en' => 'this is a new transcript', 'fr' => "il s'agit d'une nouvelle transcription")); $what = new WhatDidTheySay();
$this->assertEquals(array('en', 'fr'), $this->what->get_transcript_languages(1));
$this->assertEquals(false, $this->what->get_transcript_languages(2)); update_post_meta(1, "provided_transcripts", array('en' => 'this is a new transcript', 'fr' => "il s'agit d'une nouvelle transcription"));
$this->assertEquals(array('en', 'fr'), $what->get_transcript_languages(1));
$this->assertEquals(false, $what->get_transcript_languages(2));
} }
function testGetQueuedTranscriptionsForPost() { function testGetQueuedTranscriptionsForPost() {
@ -171,7 +172,9 @@ 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_set_current_user($current_user_id); wp_set_current_user($current_user_id);
$this->assertEquals($expected_result, $this->what->is_user_allowed_to_update());
$what = new WhatDidTheySay();
$this->assertEquals($expected_result, $what->is_user_allowed_to_update());
} }
function providerTestUpdateQueuedTranscription() { function providerTestUpdateQueuedTranscription() {
@ -295,6 +298,20 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
$what->add_transcription_to_post(1); $what->add_transcription_to_post(1);
} }
function testDeleteTranscript() {
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update'));
$what->expects($this->once())
->method('is_user_allowed_to_update')
->will($this->returnValue(true));
wp_insert_post((object)array('ID' => 1));
update_post_meta(1, "provided_transcripts", array("en" => "This is a transcript"));
$what->delete_transcript(1, "en");
$this->assertEquals(array(), get_post_meta(1, "provided_transcripts", true));
}
} }
?> ?>