You are here

function BreakpointsAdminTestCase::testBreakpointAdmin in Breakpoints 7

Test breakpoint administration functionality

File

./breakpoints.test, line 132
Tests for breakpoints.module

Class

BreakpointsAdminTestCase
Tests for breakpoints admin interface.

Code

function testBreakpointAdmin() {

  // Add breakpoint.
  $this
    ->drupalGet('admin/config/media/breakpoints');
  $name = $this
    ->randomName();
  $mediaquery = '(min-width: 600px)';
  $edit = array(
    'breakpoints[new][name]' => $name,
    'breakpoints[new][machine_name]' => drupal_strtolower($name),
    'breakpoints[new][breakpoint]' => $mediaquery,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $machine_name = BREAKPOINTS_SOURCE_TYPE_CUSTOM . '.user.' . drupal_strtolower($name);

  // Verify the breakpoint was saved and verify default weight of the breakpoint.
  $this
    ->drupalGet('admin/config/media/breakpoints');
  $this
    ->assertFieldByName("breakpoints[{$machine_name}][weight]", 0, t('Breakpoint weight was saved.'));

  // Change the weight of the breakpoint.
  $edit = array(
    "breakpoints[{$machine_name}][weight]" => 5,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertFieldByName("breakpoints[{$machine_name}][weight]", 5, t('Breakpoint weight was saved.'));

  // Submit the form.
  $this
    ->drupalGet('admin/config/media/breakpoints');
  $this
    ->drupalPost(NULL, array(), t('Save'));

  // Verify that the custom weight of the breakpoint has been retained.
  $this
    ->drupalGet('admin/config/media/breakpoints');
  $this
    ->assertFieldByName("breakpoints[{$machine_name}][weight]", 5, t('Breakpoint weight was retained.'));

  // Change the multipliers of the breakpoint.
  $edit = array(
    "breakpoints[{$machine_name}][multipliers][1.5x]" => "1.5x",
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $id = drupal_clean_css_identifier('edit-breakpoints-' . $machine_name . '-multipliers-');
  $this
    ->assertFieldChecked($id . '15x', t('Breakpoint multipliers were saved.'));
  $this
    ->assertNoFieldChecked($id . '2x', t('Breakpoint multipliers were saved.'));

  // Submit the form.
  $this
    ->drupalGet('admin/config/media/breakpoints');
  $this
    ->drupalPost(NULL, array(), t('Save'));

  // Verify that the custom weight of the breakpoint has been retained.
  $this
    ->drupalGet('admin/config/media/breakpoints');
  $this
    ->assertFieldChecked($id . '15x', t('Breakpoint multipliers were retained.'));
  $this
    ->assertNoFieldChecked($id . '2x', t('Breakpoint multipliers were retained.'));

  // Disable breakpoint.
  $this
    ->assertLinkByHref('admin/config/media/breakpoints/disable/' . $machine_name);
  $this
    ->drupalGet('admin/config/media/breakpoints/disable/' . $machine_name);
  $this
    ->drupalPost(NULL, array(), t('Confirm'));

  // Verify that the breakpoint is disabled.
  $this
    ->assertLinkByHref('admin/config/media/breakpoints/enable/' . $machine_name, 0, t('Breakpoint was disabled.'));

  // Attempt to create a breakpoint with the same machine name as the disabled
  // breakpoint but with a different human readable name.
  $edit = array(
    'breakpoints[new][name]' => 'New Breakpoint',
    'breakpoints[new][machine_name]' => drupal_strtolower($name),
    'breakpoints[new][breakpoint]' => $mediaquery,
    'breakpoints[new][multipliers][1.5x]' => 0,
    'breakpoints[new][multipliers][2x]' => 0,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertText('The machine-readable name is already in use. It must be unique.');

  // Delete breakpoint.
  $this
    ->assertLinkByHref('admin/config/media/breakpoints/delete/' . $machine_name);
  $this
    ->drupalGet('admin/config/media/breakpoints/delete/' . $machine_name);
  $this
    ->drupalPost(NULL, array(), t('Confirm'));

  // Verify that deleted breakpoint no longer exists.
  $this
    ->drupalGet('admin/config/media/breakpoints');
  $this
    ->assertNoFieldByName('breakpoints[' . $machine_name . '][name]', '', t('Deleted breakpoint no longer exists'));
}