You are here

function BreakpointGroupAdminTestCase::testBreakpointGroupExportImport in Breakpoints 7

Test breakpoint group export/import functionality.

File

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

Class

BreakpointGroupAdminTestCase
Tests for breakpoint groups admin interface.

Code

function testBreakpointGroupExportImport() {

  /**
   * Breakpoints.
   */
  $breakpoints = array();
  $breakpoint = new stdClass();
  $breakpoint->disabled = FALSE;
  $breakpoint->api_version = 1;
  $breakpoint->machine_name = 'custom.user.mobile';
  $breakpoint->name = 'mobile';
  $breakpoint->breakpoint = '(min-width: 0px)';
  $breakpoint->source = 'user';
  $breakpoint->source_type = 'custom';
  $breakpoint->status = 1;
  $breakpoint->weight = 4;
  $breakpoint->multipliers = array(
    '1.5x' => 0,
    '2x' => 0,
  );
  $breakpoints[$breakpoint->machine_name] = $breakpoint;
  $breakpoint = new stdClass();
  $breakpoint->disabled = FALSE;
  $breakpoint->api_version = 1;
  $breakpoint->machine_name = 'custom.user.narrow';
  $breakpoint->name = 'narrow';
  $breakpoint->breakpoint = '(min-width: 560px)';
  $breakpoint->source = 'user';
  $breakpoint->source_type = 'custom';
  $breakpoint->status = 1;
  $breakpoint->weight = 5;
  $breakpoint->multipliers = array(
    '1.5x' => 0,
    '2x' => 0,
  );
  $breakpoints[$breakpoint->machine_name] = $breakpoint;
  $breakpoint = new stdClass();
  $breakpoint->disabled = FALSE;
  $breakpoint->api_version = 1;
  $breakpoint->machine_name = 'custom.user.wide';
  $breakpoint->name = 'wide';
  $breakpoint->breakpoint = '(min-width: 851px)';
  $breakpoint->source = 'user';
  $breakpoint->source_type = 'custom';
  $breakpoint->status = 1;
  $breakpoint->weight = 6;
  $breakpoint->multipliers = array(
    '1.5x' => 0,
    '2x' => 0,
  );
  $breakpoints[$breakpoint->machine_name] = $breakpoint;
  $breakpoint = new stdClass();
  $breakpoint->disabled = FALSE;
  $breakpoint->api_version = 1;
  $breakpoint->machine_name = 'custom.user.tv';
  $breakpoint->name = 'tv';
  $breakpoint->breakpoint = 'only screen and (min-width: 3456px)';
  $breakpoint->source = 'user';
  $breakpoint->source_type = 'custom';
  $breakpoint->status = 1;
  $breakpoint->weight = 7;
  $breakpoint->multipliers = array(
    '1.5x' => 0,
    '2x' => 0,
  );
  $breakpoints[$breakpoint->machine_name] = $breakpoint;

  /**
   * Breakpoint group.
   */
  $breakpoint_group = new stdClass();
  $breakpoint_group->disabled = FALSE;

  /* Edit this to true to make a default breakpoint_group disabled initially */
  $breakpoint_group->api_version = 1;
  $breakpoint_group->machine_name = 'customgroup';
  $breakpoint_group->name = 'Customgroup';
  $breakpoint_group->breakpoints = array_keys($breakpoints);
  $breakpoint_group->type = 'custom';
  $breakpoint_group->overridden = 0;
  $importstring = array();
  $importstring[] = '/**';
  $importstring[] = ' * Breakpoints.';
  $importstring[] = ' */';
  $importstring[] = '$breakpoints = array();';
  $importstring[] = '$breakpoint = new stdClass();';
  $importstring[] = '$breakpoint->disabled = FALSE; /* Edit this to true to make a default breakpoint disabled initially */';
  $importstring[] = '$breakpoint->api_version = 1;';
  $importstring[] = '$breakpoint->machine_name = \'custom.user.mobile\';';
  $importstring[] = '$breakpoint->name = \'mobile\';';
  $importstring[] = '$breakpoint->breakpoint = \'(min-width: 0px)\';';
  $importstring[] = '$breakpoint->source = \'user\';';
  $importstring[] = '$breakpoint->source_type = \'custom\';';
  $importstring[] = '$breakpoint->status = 1;';
  $importstring[] = '$breakpoint->weight = 4;';
  $importstring[] = '$breakpoint->multipliers = array(';
  $importstring[] = '  \'1.5x\' => 0,';
  $importstring[] = '  \'2x\' => 0,';
  $importstring[] = ');';
  $importstring[] = '';
  $importstring[] = '$breakpoints[] = $breakpoint;';
  $importstring[] = '';
  $importstring[] = '$breakpoint = new stdClass();';
  $importstring[] = '$breakpoint->disabled = FALSE; /* Edit this to true to make a default breakpoint disabled initially */';
  $importstring[] = '$breakpoint->api_version = 1;';
  $importstring[] = '$breakpoint->machine_name = \'custom.user.narrow\';';
  $importstring[] = '$breakpoint->name = \'narrow\';';
  $importstring[] = '$breakpoint->breakpoint = \'(min-width: 560px)\';';
  $importstring[] = '$breakpoint->source = \'user\';';
  $importstring[] = '$breakpoint->source_type = \'custom\';';
  $importstring[] = '$breakpoint->status = 1;';
  $importstring[] = '$breakpoint->weight = 5;';
  $importstring[] = '$breakpoint->multipliers = array(';
  $importstring[] = '  \'1.5x\' => 0,';
  $importstring[] = '  \'2x\' => 0,';
  $importstring[] = ');';
  $importstring[] = '';
  $importstring[] = '$breakpoints[] = $breakpoint;';
  $importstring[] = '';
  $importstring[] = '$breakpoint = new stdClass();';
  $importstring[] = '$breakpoint->disabled = FALSE; /* Edit this to true to make a default breakpoint disabled initially */';
  $importstring[] = '$breakpoint->api_version = 1;';
  $importstring[] = '$breakpoint->machine_name = \'custom.user.wide\';';
  $importstring[] = '$breakpoint->name = \'wide\';';
  $importstring[] = '$breakpoint->breakpoint = \'(min-width: 851px)\';';
  $importstring[] = '$breakpoint->source = \'user\';';
  $importstring[] = '$breakpoint->source_type = \'custom\';';
  $importstring[] = '$breakpoint->status = 1;';
  $importstring[] = '$breakpoint->weight = 6;';
  $importstring[] = '$breakpoint->multipliers = array(';
  $importstring[] = '  \'1.5x\' => 0,';
  $importstring[] = '  \'2x\' => 0,';
  $importstring[] = ');';
  $importstring[] = '';
  $importstring[] = '$breakpoints[] = $breakpoint;';
  $importstring[] = '';
  $importstring[] = '$breakpoint = new stdClass();';
  $importstring[] = '$breakpoint->disabled = FALSE; /* Edit this to true to make a default breakpoint disabled initially */';
  $importstring[] = '$breakpoint->api_version = 1;';
  $importstring[] = '$breakpoint->machine_name = \'custom.user.tv\';';
  $importstring[] = '$breakpoint->name = \'tv\';';
  $importstring[] = '$breakpoint->breakpoint = \'only screen and (min-width: 3456px)\';';
  $importstring[] = '$breakpoint->source = \'user\';';
  $importstring[] = '$breakpoint->source_type = \'custom\';';
  $importstring[] = '$breakpoint->status = 1;';
  $importstring[] = '$breakpoint->weight = 7;';
  $importstring[] = '$breakpoint->multipliers = array(';
  $importstring[] = '  \'1.5x\' => 0,';
  $importstring[] = '  \'2x\' => 0,';
  $importstring[] = ');';
  $importstring[] = '';
  $importstring[] = '$breakpoints[] = $breakpoint;';
  $importstring[] = '';
  $importstring[] = '/**';
  $importstring[] = ' * Breakpoint group.';
  $importstring[] = ' */';
  $importstring[] = '$breakpoint_group = new stdClass();';
  $importstring[] = '$breakpoint_group->disabled = FALSE; /* Edit this to true to make a default breakpoint_group disabled initially */';
  $importstring[] = '$breakpoint_group->api_version = 1;';
  $importstring[] = '$breakpoint_group->machine_name = \'customgroup\';';
  $importstring[] = '$breakpoint_group->name = \'Customgroup\';';
  $importstring[] = '$breakpoint_group->breakpoints = $breakpoints;';
  $importstring[] = '$breakpoint_group->type = \'custom\';';
  $importstring[] = '$breakpoint_group->overridden = 0;';
  $this
    ->drupalGet('admin/config/media/breakpoints/groups/import');
  $edit = array(
    "import" => implode("\n", $importstring),
  );
  $this
    ->drupalPost(NULL, $edit, t('Import'));

  // Verify the breakpoint group was imported.
  $this
    ->drupalGet('admin/config/media/breakpoints/groups/' . $breakpoint_group->machine_name);
  $this
    ->assertResponse(200, t('Breakpoint group imported correctly'));

  // Verify the breakpoint group is in the database, is loadable and has the correct data.
  $this
    ->verifyBreakpointGroup($breakpoint_group, FALSE);

  // Verify the breakpoint group exports correctly.
  $this
    ->drupalGet('admin/config/media/breakpoints/groups/' . $breakpoint_group->machine_name . '/export');
  foreach ($importstring as $importline) {
    $importline = trim($importline);
    if (!empty($importline)) {

      // Text in a textarea is htmlencoded.
      $this
        ->assertRaw(check_plain($importline));
    }
  }
}