function MediaElementTestCase::testMedia in D7 Media 7.4
Same name and namespace in other branches
- 7.2 tests/media.test \MediaElementTestCase::testMedia()
- 7.3 tests/media.test \MediaElementTestCase::testMedia()
Tests the media element type.
File
- tests/
media.test, line 266 - Tests for media.module.
Class
- MediaElementTestCase
- Tests the 'media' element type.
Code
function testMedia() {
// Check that $element['#size'] is passed to the child upload element.
$this
->drupalGet('media/test');
$this
->assertFieldByXpath('//input[@name="media[nested_media]" and @size="13"]', NULL, 'The custom #size attribute is passed to the child upload element.');
// Perform the tests with all permutations of $form['#tree'] and
// $element['#extended'].
foreach (array(
0,
1,
) as $tree) {
foreach (array(
0,
1,
) as $extended) {
$test_file = $this
->getTestFile('text');
$test_file->uid = $this->admin_user->uid;
$test_file = file_save($test_file);
$path = 'media/test/' . $tree . '/' . $extended;
$input_base_name = $tree ? 'nested_media' : 'media';
// Submit without a file.
$this
->drupalPost($path, array(), t('Save'));
$this
->assertRaw(t('The file id is %fid.', array(
'%fid' => 0,
)), 'Submitted without a file.');
// Submit a new file, without using the Attach button.
$edit = array(
'media[' . $input_base_name . ']' => $test_file->fid,
);
$this
->drupalPost($path, $edit, t('Save'));
$this
->assertRaw(t('The file id is %fid.', array(
'%fid' => $test_file->fid,
)), 'Submit handler has correct file info.');
// Now, test the Attach and Remove buttons, with and without Ajax.
foreach (array(
FALSE,
) as $ajax) {
// Attach, then Submit.
$this
->drupalGet($path);
$edit = array(
'media[' . $input_base_name . ']' => $test_file->fid,
);
if ($ajax) {
$this
->drupalPostAJAX(NULL, $edit, $input_base_name . '_attach_button');
}
else {
$this
->drupalPost(NULL, $edit, t('Attach'));
}
$this
->drupalPost(NULL, array(), t('Save'));
$this
->assertRaw(t('The file id is %fid.', array(
'%fid' => $test_file->fid,
)), 'Submit handler has correct file info.');
// Attach, then Remove, then Submit.
$this
->drupalGet($path);
$edit = array(
'media[' . $input_base_name . ']' => $test_file->fid,
);
if ($ajax) {
$this
->drupalPostAJAX(NULL, $edit, $input_base_name . '_attach_button');
$this
->drupalPostAJAX(NULL, array(), $input_base_name . '_remove_button');
}
else {
$this
->drupalPost(NULL, $edit, t('Attach'));
$this
->drupalPost(NULL, array(), t('Remove'));
}
$this
->drupalPost(NULL, array(), t('Save'));
$this
->assertRaw(t('The file id is %fid.', array(
'%fid' => 0,
)), 'Submission after file attachment and removal was successful.');
}
}
}
}