View source
<?php
class DynamicBackgroundTestCase extends DrupalWebTestCase {
protected $privileged_user;
protected $btnSave;
protected $msgSave;
public static function getInfo() {
return array(
'name' => 'Dynamic Background',
'description' => 'Ensures that the dynamic background administarion interface works.',
'group' => 'Dynamic Background',
);
}
public function setUp() {
parent::setUp('dynamic_background');
$this->privileged_user = $this
->drupalCreateUser(array(
'configure dynamic backgrounds',
'set dynamic backgrounds',
'dynamic backgrounds css',
));
$this
->drupalLogin($this->privileged_user);
$this->btnSave = t('Save configuration');
$this->msgSave = t('The configuration options have been saved.');
}
public function testDynamicBackgroundConfiguration() {
$conf = array();
$conf['dynamic_background_setting[num_of_pictures]'] = 4;
$conf['dynamic_background_setting[path]'] = 'db_images';
$conf['dynamic_background_setting[extensions]'] = 'jpg jpeg png';
$this
->drupalPost('admin/config/user-interface/backgrounds/settings', $conf, $this->btnSave);
$this
->assertText($this->msgSave);
$this
->assertFieldById('edit-dynamic-background-setting-num-of-pictures', '4', 'The number of upload fields is set corret.');
$this
->assertFieldById('edit-dynamic-background-setting-path', 'db_images', 'The upload path where corret.');
$this
->assertFieldById('edit-dynamic-background-setting-extensions', 'jpg jpeg png', 'The extensions where corret.');
$conf = array();
$conf['dynamic_background_css[custom]'] = TRUE;
$conf['dynamic_background_css[selector]'] = '#page #main-wrapper';
$conf['dynamic_background_css[css]'] = 'background-size: cover;';
$this
->drupalPost('admin/config/user-interface/backgrounds/settings', $conf, $this->btnSave);
$this
->assertText($this->msgSave);
$this
->assertFieldById('edit-dynamic-background-css-custom', TRUE, 'The custom styling have been checked.');
$this
->assertFieldById('edit-dynamic-background-css-selector', '#page #main-wrapper', 'The CSS selector was set.');
$this
->assertFieldById('edit-dynamic-background-css-css', 'background-size: cover;', 'Custom styling was saved correctly.');
$path = 'admin/config/user-interface/backgrounds';
$this
->drupalGet($path);
$this
->assertText(t('Background image 1'));
$this
->assertText(t('Background image 2'));
$this
->assertText(t('Background image 3'));
$this
->assertText(t('Background image 4'));
$file = realpath('misc/druplicon.png');
$this
->drupalPost('admin/config/user-interface/backgrounds', array(
'files[dynamic_background_picture_0]' => $file,
), $this->btnSave);
$saved = $this
->assertText($this->msgSave);
if ($saved) {
$this
->drupalPost('admin/config/user-interface/backgrounds', array(
'dynamic_background_picture_0[picture_use]' => TRUE,
), $this->btnSave);
$this
->assertText($this->msgSave);
$this
->assertFieldChecked('edit-dynamic-background-picture-0-picture-use', 'The firste image was selected.');
$this
->drupalPost('admin/config/user-interface/backgrounds', array(
'files[dynamic_background_picture_1]' => $file,
), $this->btnSave);
$this
->assertText(t('Failded to upload image, as one with that name exists.'));
$this
->drupalPost('admin/config/user-interface/backgrounds', array(
'dynamic_background_picture_0[picture_use]' => FALSE,
), $this->btnSave);
$this
->assertText($this->msgSave);
$this
->assertNoFieldChecked('edit-dynamic-background-picture-0-picture-use', 'The firste image should be de-selected.');
$this
->drupalPost('admin/config/user-interface/backgrounds', array(
'dynamic_background_picture_0[picture_delete]' => TRUE,
), $this->btnSave);
$this
->assertText($this->msgSave);
}
}
}