You are here

function BreakpointsAdminTestCase::testBreakpointExportImport in Breakpoints 7

Test breakpoint export/import functionality.

File

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

Class

BreakpointsAdminTestCase
Tests for breakpoints admin interface.

Code

function testBreakpointExportImport() {
  $breakpoint = new stdClass();
  $breakpoint->disabled = FALSE;
  $breakpoint->api_version = 1;
  $breakpoint->machine_name = 'custom.user.test';
  $breakpoint->name = 'test';
  $breakpoint->breakpoint = '(min-width: 600px)';
  $breakpoint->source = 'user';
  $breakpoint->source_type = 'custom';
  $breakpoint->status = 1;
  $breakpoint->weight = 0;
  $breakpoint->multipliers = array(
    '1.5x' => 0,
    '2x' => 0,
  );

  // Import a breakpoint;
  $importstring = 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.test\';';
  $importstring[] = '$breakpoint->name = \'test\';';
  $importstring[] = '$breakpoint->breakpoint = \'(min-width: 600px)\';';
  $importstring[] = '$breakpoint->source = \'user\';';
  $importstring[] = '$breakpoint->source_type = \'custom\';';
  $importstring[] = '$breakpoint->status = 1;';
  $importstring[] = '$breakpoint->weight = 0;';
  $importstring[] = '$breakpoint->multipliers = array(';
  $importstring[] = '  \'1.5x\' => 0,';
  $importstring[] = '  \'2x\' => 0,';
  $importstring[] = ');';
  $this
    ->drupalGet('admin/config/media/breakpoints/groups/import-breakpoint');
  $edit = array(
    "import" => implode("\n", $importstring),
  );
  $this
    ->drupalPost(NULL, $edit, t('Import'));

  // Verify the breakpoint was imported.
  $this
    ->drupalGet('admin/config/media/breakpoints');
  $this
    ->assertField('breakpoints[' . $breakpoint->machine_name . '][name]', t('Breakpoint imported correctly.'));

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

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

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