2009-08-13 23:09:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('PHPUnit/Framework.php');
|
|
|
|
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
|
|
|
|
require_once(dirname(__FILE__) . '/../classes/WhatDidTheySayAdmin.php');
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
function providerTestHandleUpdateLanguages() {
|
|
|
|
return array(
|
|
|
|
array(
|
2009-08-14 10:54:25 +00:00
|
|
|
array('en' => array('name' => 'English'), 'de' => array('name' => 'German')),
|
|
|
|
array('code' => 'en', 'action' => 'delete'),
|
|
|
|
array('de' => array('name' => 'German'))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array('de' => array('name' => 'German')),
|
|
|
|
array('code' => 'en', 'action' => 'add'),
|
|
|
|
array('en' => array('name' => 'English'), 'de' => array('name' => 'German')),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array('en' => array('name' => 'English', 'default' => true), 'de' => array('name' => 'German')),
|
|
|
|
array('code' => 'de', 'action' => 'default'),
|
|
|
|
array('en' => array('name' => 'English'), 'de' => array('name' => 'German', 'default' => true)),
|
|
|
|
),
|
2009-08-14 11:09:37 +00:00
|
|
|
array(
|
|
|
|
array('en' => array('name' => 'English'), 'de' => array('name' => 'German')),
|
|
|
|
array('code' => 'de', 'action' => 'rename', 'name' => 'Deutsch'),
|
|
|
|
array('en' => array('name' => 'English'), 'de' => array('name' => 'Deutsch')),
|
|
|
|
),
|
2009-08-14 02:13:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestHandleUpdateLanguages
|
|
|
|
*/
|
|
|
|
function testHandleUpdateLanguages($original_options, $form_submission, $expected_results) {
|
2009-08-13 23:09:10 +00:00
|
|
|
$admin = new WhatDidTheySayAdmin();
|
|
|
|
$admin->all_languages = array(
|
|
|
|
'en' => 'English',
|
2009-08-14 02:13:46 +00:00
|
|
|
'de' => 'German',
|
|
|
|
'fr' => 'French'
|
2009-08-13 23:09:10 +00:00
|
|
|
);
|
2009-08-14 02:13:46 +00:00
|
|
|
|
2009-08-14 10:54:25 +00:00
|
|
|
update_option('what-did-they-say-options', array('languages' => $original_options));
|
2009-08-13 23:09:10 +00:00
|
|
|
|
2009-08-14 02:13:46 +00:00
|
|
|
$admin->handle_update_languages($form_submission);
|
2009-08-13 23:32:42 +00:00
|
|
|
|
|
|
|
$options = get_option('what-did-they-say-options');
|
2009-08-14 02:13:46 +00:00
|
|
|
$this->assertEquals($expected_results, $options['languages']);
|
2009-08-13 23:32:42 +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-08-13 23:09:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|