You are here

function ResponsivePreviewDeviceCRUD::testDeviceConfiguration in Responsive Theme Preview 7

File

./responsive_preview.test, line 34
Tests for responsive_preview.module.

Class

ResponsivePreviewDeviceCRUD
@file Tests for responsive_preview.module.

Code

function testDeviceConfiguration() {

  // Create and login administrative user.
  $admin_user = $this->admin_user;
  $this
    ->drupalLogin($admin_user);

  // Set the controls block to a region to confirm block is available.
  $edit = array();
  $edit['blocks[responsive_preview_controls][region]'] = 'sidebar_first';
  $this
    ->drupalPost('admin/structure/block', $edit, t('Save blocks'));
  $this
    ->assertText(t('The block settings have been updated.'), 'Block successfully move to sidebar_first region.');

  // Assert
  $this
    ->drupalGet('admin/config/content/responsive-preview');

  // Some default devices exist.
  $this
    ->assertLinkByHref('admin/config/content/responsive-preview/large/delete');
  $this
    ->assertLinkByHref('admin/config/content/responsive-preview/iphone6/delete');

  // Some devices are shown by default.
  $this
    ->drupalGet('');
  $this
    ->checkDevices(array(
    'iphone6',
    'iphone6p',
    'nexus5',
    'nexus6',
    'nexus9',
  ));

  // Delete one of the predefined devices.
  $this
    ->drupalPost('admin/config/content/responsive-preview/iphone6/delete', array(), t('Delete'));
  $this
    ->assertRaw(t('Device %name has been deleted.', array(
    '%name' => 'iPhone 6',
  )));

  // Make generic tablet appear in the list.
  $this
    ->drupalPost('admin/config/content/responsive-preview', array(
    'devices[medium][status]' => 1,
  ), t('Save'));
  $this
    ->assertRaw(t('The device settings have been updated.'));

  // Add a new device as well.
  $edit = array(
    'device[label]' => 'Tarsier',
    'device[name]' => 'tarsier',
    'device[dimensions][width]' => '200',
    'device[dimensions][height]' => '350',
    'device[dimensions][dppx]' => '3',
  );
  $this
    ->drupalPost('admin/config/content/responsive-preview/add', $edit, t('Add device'));
  $this
    ->assertRaw(t('Device %name has been added.', array(
    '%name' => 'Tarsier',
  )));

  // Check updated device list. New devices are shown in the list by default.
  $this
    ->drupalGet('');
  $this
    ->checkDevices(array(
    'tarsier',
    'iphone6',
    'iphone6p',
    'nexus5',
    'nexus6',
    'nexus9',
  ));

  // Update an existing device.
  $edit = array(
    'device[dimensions][width]' => '1600',
    'device[dimensions][height]' => '2850',
    'device[dimensions][dppx]' => '2',
  );

  // Delete one of the predefined devices.
  $this
    ->drupalPost('admin/config/content/responsive-preview/iphone6/edit', $edit, t('Save'));
  $this
    ->assertRaw(t('Device %name has been updated.', array(
    '%name' => 'iPhone 6',
  )));
}