2009-09-05 20:05:15 +00:00
< ? php
require_once ( 'PHPUnit/Framework.php' );
2009-10-17 17:00:56 +00:00
require_once ( 'MockPress/mockpress.php' );
2009-09-25 03:26:04 +00:00
require_once ( dirname ( __FILE__ ) . '/../classes/WDTSTranscript.inc' );
2009-09-05 20:05:15 +00:00
class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
function setUp () {
_reset_wp ();
wp_insert_user ( array ( 'ID' => 1 ));
wp_set_current_user ( 1 );
wp_insert_post ( array ( 'ID' => 1 ));
$this -> w = new WDTSTranscriptManager ( 1 );
$this -> w -> key = " test " ;
2009-09-22 00:53:51 +00:00
$this -> w -> search_key = " test_search " ;
2009-09-05 20:05:15 +00:00
}
function testSaveTranscript () {
2009-09-13 16:35:20 +00:00
$this -> w -> allow_multiple = false ;
2009-09-05 20:05:15 +00:00
$this -> w -> save_transcript ( array (
'language' => 'en' ,
'transcript' => 'this is a transcript'
));
$this -> assertEquals (
array (
array (
'language' => 'en' ,
'transcript' => 'this is a transcript' ,
2009-09-13 16:35:20 +00:00
'user_id' => 1 ,
'key' => 0
2009-09-05 20:05:15 +00:00
)
),
get_post_meta ( 1 , $this -> w -> key , true )
);
2009-09-22 00:53:51 +00:00
$this -> assertEquals ( " this is a transcript " , get_post_meta ( 1 , $this -> w -> search_key , true ));
2009-09-05 20:05:15 +00:00
$this -> w -> save_transcript ( array (
'language' => 'en' ,
'transcript' => 'this is another transcript'
));
$this -> assertEquals (
array (
array (
'language' => 'en' ,
'transcript' => 'this is another transcript' ,
2009-09-13 16:35:20 +00:00
'user_id' => 1 ,
'key' => 0
2009-09-05 20:05:15 +00:00
)
),
get_post_meta ( 1 , $this -> w -> key , true )
);
2009-09-22 00:53:51 +00:00
$this -> assertEquals ( " this is another transcript " , get_post_meta ( 1 , $this -> w -> search_key , true ));
2009-09-05 20:05:15 +00:00
$this -> w -> save_transcript ( array (
'language' => 'fr' ,
2009-09-24 01:47:22 +00:00
'transcript' => " [dialog]il s'agit d'une nouvelle transcription[/dialog] "
2009-09-05 20:05:15 +00:00
));
$this -> assertEquals (
array (
array (
'language' => 'en' ,
'transcript' => 'this is another transcript' ,
2009-09-13 16:35:20 +00:00
'user_id' => 1 ,
'key' => 0
),
array (
'language' => 'fr' ,
2009-09-24 01:47:22 +00:00
'transcript' => " [dialog]il s'agit d'une nouvelle transcription[/dialog] " ,
2009-09-13 16:35:20 +00:00
'user_id' => 1 ,
'key' => 1
),
),
get_post_meta ( 1 , $this -> w -> key , true )
);
2009-09-22 00:53:51 +00:00
$this -> assertEquals ( " this is another transcript il s'agit d'une nouvelle transcription " , get_post_meta ( 1 , $this -> w -> search_key , true ));
2009-09-13 16:35:20 +00:00
$this -> w -> allow_multiple = true ;
$this -> w -> save_transcript ( array (
'language' => 'en' ,
2009-09-24 11:29:33 +00:00
'transcript' => '[dialog name="John"]this is yet another transcript[/dialog]'
2009-09-13 16:35:20 +00:00
));
$this -> assertEquals (
array (
array (
'language' => 'en' ,
'transcript' => 'this is another transcript' ,
'user_id' => 1 ,
'key' => 0
2009-09-05 20:05:15 +00:00
),
array (
'language' => 'fr' ,
2009-09-24 01:47:22 +00:00
'transcript' => " [dialog]il s'agit d'une nouvelle transcription[/dialog] " ,
2009-09-13 16:35:20 +00:00
'user_id' => 1 ,
'key' => 1
),
array (
'language' => 'en' ,
2009-09-24 11:29:33 +00:00
'transcript' => '[dialog name="John"]this is yet another transcript[/dialog]' ,
2009-09-13 16:35:20 +00:00
'user_id' => 1 ,
'key' => 2
2009-09-05 20:05:15 +00:00
),
),
get_post_meta ( 1 , $this -> w -> key , true )
);
2009-09-22 00:53:51 +00:00
2009-09-24 11:29:33 +00:00
$this -> assertEquals ( " this is another transcript il s'agit d'une nouvelle transcription John this is yet another transcript " , get_post_meta ( 1 , $this -> w -> search_key , true ));
2009-09-13 16:35:20 +00:00
}
2009-09-05 20:05:15 +00:00
function testDeleteTranscript () {
2009-09-13 16:35:20 +00:00
$this -> w -> save_transcript ( array (
'language' => 'en' ,
'transcript' => 'this is another transcript'
));
$this -> w -> save_transcript ( array (
'language' => 'fr' ,
'transcript' => " il s'agit d'une nouvelle transcription " ,
));
$this -> w -> delete_transcript ( 'en' );
$this -> assertEquals ( array (
2009-09-05 20:05:15 +00:00
array (
'language' => 'fr' ,
'transcript' => " il s'agit d'une nouvelle transcription " ,
2009-09-13 16:35:20 +00:00
'user_id' => 1 ,
'key' => 1
2009-09-05 20:05:15 +00:00
),
2009-09-13 16:35:20 +00:00
), get_post_meta ( 1 , $this -> w -> key , true ));
2009-09-22 00:53:51 +00:00
$this -> assertEquals ( " il s'agit d'une nouvelle transcription " , get_post_meta ( 1 , $this -> w -> search_key , true ));
2009-09-13 16:35:20 +00:00
}
function testDeleteTranscriptByKey () {
$this -> w -> save_transcript ( array (
'language' => 'en' ,
'transcript' => 'this is another transcript'
2009-09-05 20:05:15 +00:00
));
2009-09-13 16:35:20 +00:00
$this -> w -> save_transcript ( array (
'language' => 'fr' ,
'transcript' => " il s'agit d'une nouvelle transcription " ,
));
$this -> assertEquals (
$this -> w -> delete_transcript_by_key ( 0 ),
array (
'language' => 'en' ,
'transcript' => " this is another transcript " ,
'user_id' => 1 ,
'key' => 0
)
);
2009-09-05 20:05:15 +00:00
$this -> assertEquals ( array (
array (
'language' => 'fr' ,
'transcript' => " il s'agit d'une nouvelle transcription " ,
2009-09-13 16:35:20 +00:00
'user_id' => 1 ,
'key' => 1
2009-09-05 20:05:15 +00:00
),
), get_post_meta ( 1 , $this -> w -> key , true ));
2009-09-22 00:53:51 +00:00
$this -> assertEquals ( " il s'agit d'une nouvelle transcription " , get_post_meta ( 1 , $this -> w -> search_key , true ));
2009-09-05 20:05:15 +00:00
}
function testGetLanguages () {
update_post_meta ( 1 , $this -> w -> key , array (
array (
'language' => 'en' ,
'transcript' => 'this is another transcript' ,
'user_id' => 1
),
array (
'language' => 'fr' ,
'transcript' => " il s'agit d'une nouvelle transcription " ,
'user_id' => 1
),
));
$this -> assertEquals ( array ( 'en' , 'fr' ), $this -> w -> get_languages ());
}
2009-09-29 01:54:02 +00:00
function testUpdateTranscript () {
update_post_meta ( 1 , $this -> w -> key ,
array (
array (
'language' => 'en' ,
'transcript' => 'this is a transcript' ,
'user_id' => 1 ,
'key' => 0
)
)
);
$info = array (
'key' => 0 ,
'user_id' => 1 ,
'transcript' => 'hiss hiss hiss' ,
'language' => 'fr'
);
$this -> w -> update_transcript ( $info );
$this -> assertEquals (
array (
array (
'language' => 'en' ,
'transcript' => 'hiss hiss hiss' ,
'user_id' => 1 ,
'key' => 0
)
),
get_post_meta ( 1 , $this -> w -> key , true )
);
}
2009-09-05 20:05:15 +00:00
}
?>