You are here

function BreakpointsCRUDTestCase::testBreakpointsCRUD in Breakpoints 7

Test CRUD operations for breakpoints.

File

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

Class

BreakpointsCRUDTestCase
Tests for breakpoints CRUD operations.

Code

function testBreakpointsCRUD() {

  // Add a breakpoint with minimum data only.
  $breakpoint = new stdClass();
  $breakpoint->disabled = FALSE;
  $breakpoint->api_version = 1;
  $breakpoint->name = 'Custom';
  $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,
  );
  breakpoints_breakpoint_save($breakpoint);
  $this
    ->verifyBreakpoint($breakpoint);

  // Update the breakpoint.
  $breakpoint->weight = 1;
  $breakpoint->multipliers['2x'] = 1;
  breakpoints_breakpoint_save($breakpoint);
  $this
    ->verifyBreakpoint($breakpoint);

  // Disable the breakpoint.
  $breakpoint->status = 0;
  breakpoints_breakpoint_save($breakpoint);
  $this
    ->verifyBreakpoint($breakpoint);
  $breakpoints = breakpoints_breakpoint_load_all_active();
  $this
    ->assertFalse(isset($breakpoints[$breakpoint->machine_name]), t('breakpoints_breakpoint_load_all_active: Disabled breakpoints aren\'t loaded.'), t('Breakpoints API'));

  // Delete the breakpoint.
  breakpoints_breakpoint_delete($breakpoint);
  $db_breakpoint = db_select('breakpoints', 'b')
    ->fields('b')
    ->condition('machine_name', $breakpoint->machine_name)
    ->execute()
    ->fetchObject();
  $this
    ->assertFalse($db_breakpoint, t('Database: Deleted breakpoint no longer exists'), t('Breakpoints API'));
  $this
    ->assertFalse(breakpoints_breakpoint_load_by_fullkey($breakpoint->machine_name), t('breakpoints_breakpoint_load_by_fullkey: Loading a deleted breakpoint returns false.'), t('Breakpoints API'));
}