You are here

function BreakpointGroupCRUDTestCase::testBreakpointGroupCRUD in Breakpoints 7

Test CRUD operations for breakpoint groups.

File

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

Class

BreakpointGroupCRUDTestCase
Tests for breakpoint group CRUD operations.

Code

function testBreakpointGroupCRUD() {

  // Add breakpoints.
  $breakpoints = array();
  for ($i = 0; $i <= 3; $i++) {
    $breakpoint = new stdClass();
    $breakpoint->disabled = FALSE;
    $breakpoint->api_version = 1;
    $breakpoint->name = $this
      ->randomName();
    $width = ($i + 1) * 200;
    $breakpoint->breakpoint = "(min-width: {$width}px)";
    $breakpoint->source = 'user';
    $breakpoint->source_type = 'custom';
    $breakpoint->status = 1;
    $breakpoint->weight = $i;
    $breakpoint->multipliers = array(
      '1.5x' => 0,
      '2x' => 0,
    );
    breakpoints_breakpoint_save($breakpoint);
    $breakpoints[$breakpoint->machine_name] = $breakpoint;
  }

  // Add a breakpoint group with minimum data only.
  $group = new stdClass();
  $group->name = $this
    ->randomName();
  $group->machine_name = drupal_strtolower($group->name);
  $group->breakpoints = array();
  breakpoints_breakpoint_group_save($group);
  $this
    ->verifyBreakpointGroup($group);

  // Update the breakpoint group.
  $group->breakpoints = array_keys($breakpoints);
  breakpoints_breakpoint_group_save($group);
  $this
    ->verifyBreakpointGroup($group);

  // Delete the breakpoint group.
  breakpoints_breakpoint_group_delete($group);
  $db_group = db_select('breakpoint_group', 'bg')
    ->fields('bg')
    ->condition('machine_name', $group->machine_name)
    ->execute()
    ->fetchObject();
  $this
    ->assertFalse($db_group, t('Database: Deleted breakpoint group no longer exists'), t('Breakpoints API'));
  $this
    ->assertFalse(breakpoints_breakpoint_group_load($group->machine_name), t('breakpoints_breakpoint_group_load: Loading a deleted breakpoint group returns false.'), t('Breakpoints API'));
}