queued transcriptions
This commit is contained in:
parent
5d1a8fa22c
commit
95e112c343
@ -6,12 +6,46 @@
|
||||
* other posts as necessary.
|
||||
*/
|
||||
class WhatDidTheySay {
|
||||
function WhatDidTheySay() {
|
||||
global $wpdb;
|
||||
|
||||
$this->table = $wpdb->prefix . "provided_transcripts";
|
||||
}
|
||||
|
||||
function save_transcript($post_id, $language, $transcript) {
|
||||
$current_transcripts = get_post_meta($post_id, "provided_transcripts", true);
|
||||
if (!is_array($current_transcripts)) { $current_transcripts = array(); }
|
||||
$current_transcripts[$language] = $transcript;
|
||||
return update_post_meta($post_id, "provided_transcripts", $current_transcripts);
|
||||
}
|
||||
|
||||
function get_transcript_languages($post_id) {
|
||||
$current_transcripts = get_post_meta($post_id, "provided_transcripts", true);
|
||||
if (is_array($current_transcripts)) {
|
||||
return array_keys($current_transcripts);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_queued_transcriptions_for_post($post_id) {
|
||||
global $wpdb;
|
||||
|
||||
$post = get_post($post_id);
|
||||
if (!empty($post)) {
|
||||
$results = $wpdb->get_results(sprintf("SELECT * FROM %s WHERE post_id = %d", $this->table, $post_id));
|
||||
if (!empty($results)) {
|
||||
$valid_results = array();
|
||||
foreach ($results as $result) {
|
||||
$user = get_userdata($result->user_id);
|
||||
if (!empty($user)) {
|
||||
$valid_results[] = $result;
|
||||
}
|
||||
}
|
||||
return $valid_results;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once('PHPUnit/Framework.php');
|
||||
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
|
||||
require_once(dirname(__FILE__) . '/../classes/WhatDidTheySay.php');
|
||||
|
||||
class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
||||
function setUp() {
|
||||
$this->what = new WhatDidTheySay();
|
||||
}
|
||||
|
||||
function testSaveTranscription() {
|
||||
$this->what->save_transcript(1, "en", "This is a transcript");
|
||||
$this->assertEquals(array("en" => "This is a transcript"), get_post_meta(1, "provided_transcripts", true));
|
||||
|
||||
$this->what->save_transcript(1, "en", "this is a new transcript");
|
||||
$this->assertEquals(array("en" => "this is a new transcript"), get_post_meta(1, "provided_transcripts", true));
|
||||
|
||||
$this->what->save_transcript(1, "fr", "il s'agit d'une nouvelle transcription");
|
||||
$this->assertEquals(array("en" => "this is a new transcript", "fr" => "il s'agit d'une nouvelle transcription"), get_post_meta(1, "provided_transcripts", true));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
71
test/WhatDidTheySayTest.php
Normal file
71
test/WhatDidTheySayTest.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
require_once('PHPUnit/Framework.php');
|
||||
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
|
||||
require_once(dirname(__FILE__) . '/../classes/WhatDidTheySay.php');
|
||||
|
||||
class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
||||
function setUp() {
|
||||
global $wpdb;
|
||||
$this->what = new WhatDidTheySay();
|
||||
_reset_wp();
|
||||
$wpdb = null;
|
||||
}
|
||||
|
||||
function testSaveTranscription() {
|
||||
$this->what->save_transcript(1, "en", "This is a transcript");
|
||||
$this->assertEquals(array("en" => "This is a transcript"), get_post_meta(1, "provided_transcripts", true));
|
||||
|
||||
$this->what->save_transcript(1, "en", "this is a new transcript");
|
||||
$this->assertEquals(array("en" => "this is a new transcript"), get_post_meta(1, "provided_transcripts", true));
|
||||
|
||||
$this->what->save_transcript(1, "fr", "il s'agit d'une nouvelle transcription");
|
||||
$this->assertEquals(array("en" => "this is a new transcript", "fr" => "il s'agit d'une nouvelle transcription"), get_post_meta(1, "provided_transcripts", true));
|
||||
}
|
||||
|
||||
function testGetListOfLanguagesForPost() {
|
||||
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'), $this->what->get_transcript_languages(1));
|
||||
|
||||
$this->assertEquals(false, $this->what->get_transcript_languages(2));
|
||||
}
|
||||
|
||||
function testGetQueuedTranscriptionsForPost() {
|
||||
global $wpdb;
|
||||
|
||||
wp_insert_user(array('ID' => 1, 'first_name' => 'Test', 'last_name' => 'User'));
|
||||
wp_insert_post(array('ID' => 1));
|
||||
|
||||
$wpdb = $this->getMock('wpdb', array('get_results'));
|
||||
$wpdb->expects($this->once())
|
||||
->method('get_results')
|
||||
->with(sprintf('SELECT * FROM %s WHERE post_id = 1', $this->what->table))
|
||||
->will(
|
||||
$this->returnValue(
|
||||
array(
|
||||
(object)array('id' => 1, 'post_id' => 1, 'user_id' => 1, 'language' => 'en', 'transcript' => "This is a transcript"),
|
||||
(object)array('id' => 2, 'post_id' => 1, 'user_id' => 2, 'language' => 'fr', 'transcript' => "il s'agit d'une nouvelle transcription"),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$result =
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
(object)array(
|
||||
'id' => 1,
|
||||
'post_id' => 1,
|
||||
'user_id' => 1,
|
||||
'language' => 'en',
|
||||
'transcript' => 'This is a transcript'
|
||||
)
|
||||
),
|
||||
$this->what->get_queued_transcriptions_for_post(1)
|
||||
);
|
||||
|
||||
$this->assertFalse($this->what->get_queued_transcriptions_for_post(2));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user