2009-08-13 23:09:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('PHPUnit/Framework.php');
|
2009-10-17 17:00:56 +00:00
|
|
|
require_once('MockPress/mockpress.php');
|
2009-10-23 11:04:53 +00:00
|
|
|
|
2009-09-25 03:26:04 +00:00
|
|
|
require_once(dirname(__FILE__) . '/../classes/WhatDidTheySayAdmin.inc');
|
2009-10-23 11:04:53 +00:00
|
|
|
require_once(dirname(__FILE__) . '/../classes/WDTSTranscriptClasses.inc');
|
2009-08-13 23:09:10 +00:00
|
|
|
|
|
|
|
class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
|
|
|
function setUp() {
|
|
|
|
_reset_wp();
|
2009-08-19 02:19:11 +00:00
|
|
|
_set_user_capabilities('submit_transcriptions', 'approve_transcriptions', 'change_languages');
|
2009-08-13 23:09:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testReadLanguageData() {
|
|
|
|
$admin = new WhatDidTheySayAdmin();
|
|
|
|
|
|
|
|
$this->assertTrue(count($admin->read_language_file()) > 0);
|
|
|
|
}
|
2009-08-14 02:13:46 +00:00
|
|
|
|
2009-08-14 11:03:58 +00:00
|
|
|
function testBuildFullDefaultLanguageInfo() {
|
|
|
|
$admin = new WhatDidTheySayAdmin();
|
|
|
|
$admin->all_languages = array(
|
|
|
|
'en' => 'English',
|
|
|
|
'de' => 'German',
|
|
|
|
'fr' => 'French'
|
|
|
|
);
|
|
|
|
|
|
|
|
$admin->default_options = array(
|
|
|
|
'languages' => array(
|
|
|
|
'en',
|
|
|
|
array('code' => 'de', 'default' => true),
|
|
|
|
'it'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'en' => array('name' => 'English'),
|
|
|
|
'de' => array('name' => 'German', 'default' => true),
|
|
|
|
), $admin->build_default_languages()
|
|
|
|
);
|
2009-08-13 23:36:47 +00:00
|
|
|
}
|
2009-08-15 19:53:55 +00:00
|
|
|
|
|
|
|
function testHandleUpdateCapabilities() {
|
|
|
|
$admin = new WhatDidTheySayAdmin();
|
|
|
|
update_option('what-did-they-say-options', $admin->default_options);
|
2009-08-19 02:19:11 +00:00
|
|
|
_set_user_capabilities('edit_users');
|
2009-08-15 19:53:55 +00:00
|
|
|
|
|
|
|
$admin->handle_update_capabilities(array(
|
|
|
|
'action' => 'capabilities',
|
|
|
|
'capabilities' => array(
|
2009-08-15 20:45:08 +00:00
|
|
|
'submit_transcriptions' => 'contributor',
|
|
|
|
'approve_transcriptions' => 'subscriber',
|
2009-08-15 19:53:55 +00:00
|
|
|
'change_languages' => 'reader'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = get_option('what-did-they-say-options');
|
|
|
|
$this->assertEquals(array(
|
2009-08-15 20:45:08 +00:00
|
|
|
'submit_transcriptions' => 'contributor',
|
|
|
|
'approve_transcriptions' => 'subscriber',
|
2009-08-15 19:53:55 +00:00
|
|
|
'change_languages' => 'reader'
|
|
|
|
), $result['capabilities']);
|
|
|
|
}
|
2009-10-17 16:22:13 +00:00
|
|
|
|
|
|
|
function testUpdateUserPerms() {
|
|
|
|
$admin = new WhatDidTheySayAdmin();
|
|
|
|
$admin->_set_up_capabilities();
|
|
|
|
|
|
|
|
update_usermeta(1, 'transcript_capabilities', array(
|
|
|
|
'submit_transcriptions' => true
|
|
|
|
));
|
|
|
|
|
|
|
|
$admin->_update_user_perms(1, array(
|
|
|
|
'approve_transcriptions' => 'yes'
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEquals(array(
|
|
|
|
'approve_transcriptions' => true
|
|
|
|
), get_usermeta(1, 'transcript_capabilities'));
|
|
|
|
}
|
2009-10-23 11:04:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Integration.
|
|
|
|
*/
|
|
|
|
function testPerformImport() {
|
2009-10-25 18:11:48 +00:00
|
|
|
$admin = $this->getMock('WhatDidTheySayAdmin', array('_get_transcript_posts'));
|
2009-10-23 11:04:53 +00:00
|
|
|
$admin->_import_chunk_size = 1;
|
|
|
|
|
|
|
|
wp_insert_user(array('ID' => 1));
|
|
|
|
wp_set_current_user(1);
|
|
|
|
|
|
|
|
_set_user_capabilities('approve_transcriptions');
|
|
|
|
|
|
|
|
for ($i = 1; $i <= 2; ++$i) {
|
|
|
|
wp_insert_post(array('ID' => $i));
|
|
|
|
update_post_meta($i, "transcript", "this is my transcript");
|
|
|
|
}
|
|
|
|
|
2009-10-25 18:11:48 +00:00
|
|
|
$admin->expects($this->once())->method('_get_transcript_posts')->will($this->returnValue(array(1,2)));
|
2009-10-23 11:04:53 +00:00
|
|
|
$this->assertEquals(1, $admin->import_transcripts('en'));
|
|
|
|
|
|
|
|
$this->assertEquals('', get_post_meta(1, "transcript", true));
|
|
|
|
$this->assertEquals('this is my transcript', get_post_meta(2, "transcript", true));
|
|
|
|
|
|
|
|
$this->assertEquals(array(
|
|
|
|
array(
|
|
|
|
'language' => 'en',
|
|
|
|
'transcript' => 'this is my transcript',
|
|
|
|
'user_id' => 1,
|
|
|
|
'key' => 0
|
|
|
|
)
|
|
|
|
), get_post_meta(1, 'approved_transcripts', true));
|
|
|
|
|
|
|
|
delete_post_meta(2, 'transcript');
|
|
|
|
|
2009-10-25 18:11:48 +00:00
|
|
|
$admin = $this->getMock('WhatDidTheySayAdmin', array('_get_transcript_posts'));
|
|
|
|
$admin->_import_chunk_size = 1;
|
|
|
|
|
|
|
|
$admin->expects($this->once())->method('_get_transcript_posts')->will($this->returnValue(array()));
|
2009-10-23 11:04:53 +00:00
|
|
|
|
2009-10-25 18:11:48 +00:00
|
|
|
$this->assertEquals(0, $admin->import_transcripts('en'));
|
2009-10-23 11:04:53 +00:00
|
|
|
}
|
2009-10-23 11:13:20 +00:00
|
|
|
|
|
|
|
function providerTestCleanChild() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'script' => '<script>remove</script>test',
|
|
|
|
'style' => '<style>remove</style>test',
|
|
|
|
'link' => '<link>remove</link>test',
|
|
|
|
'keep' => '<b>remove</b>test'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'allow_html' => true
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'script' => 'test',
|
|
|
|
'style' => 'test',
|
|
|
|
'link' => 'test',
|
|
|
|
'keep' => '<b>remove</b>test'
|
|
|
|
),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'remove' => '<b>remove</b>test',
|
|
|
|
'children' => array(
|
|
|
|
'alsoremove' => '<i>remove</i>test'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'allow_html' => false
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'remove' => 'removetest',
|
|
|
|
'children' => array(
|
|
|
|
'alsoremove' => 'removetest',
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestCleanChild
|
|
|
|
*/
|
|
|
|
function testCleanChild($nodes, $options, $expected_result) {
|
|
|
|
$admin = new WhatDidTheySayAdmin();
|
|
|
|
|
|
|
|
update_option('what-did-they-say-options', $options);
|
|
|
|
|
|
|
|
$this->assertEquals($expected_result, $admin->_clean_child($nodes));
|
|
|
|
}
|
2009-08-13 23:09:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|