You are here

public function BreakpointGroupCrudTest::testBreakpointGroupCrud in Breakpoints 8

Test CRUD operations for breakpoint groups.

File

lib/Drupal/breakpoint/Tests/BreakpointGroupCrudTest.php, line 32
Definition of Drupal\breakpoint\Tests\BreakpointGroupCrudTest.

Class

BreakpointGroupCrudTest
Tests for breakpoint group CRUD operations.

Namespace

Drupal\breakpoint\Tests

Code

public function testBreakpointGroupCrud() {

  // Add breakpoints.
  $breakpoints = array();
  for ($i = 0; $i <= 3; $i++) {
    $width = ($i + 1) * 200;
    $breakpoint = entity_create('breakpoint', array(
      'name' => drupal_strtolower($this
        ->randomName()),
      'weight' => $i,
      'mediaQuery' => "(min-width: {$width}px)",
    ));
    $breakpoint
      ->save();
    $breakpoints[$breakpoint
      ->id()] = $breakpoint;
  }

  // Add a breakpoint group with minimum data only.
  $label = $this
    ->randomName();
  $group = entity_create('breakpoint_group', array(
    'label' => $label,
    'id' => drupal_strtolower($label),
  ));
  $group
    ->save();
  $this
    ->verifyBreakpointGroup($group);

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

  // Duplicate the breakpoint group.
  $new_set = entity_create('breakpoint_group', array(
    'breakpoints' => $group->breakpoints,
  ));
  $duplicated_set = $group
    ->duplicate();
  $this
    ->verifyBreakpointGroup($duplicated_set, $new_set);

  // Delete the breakpoint group.
  $group
    ->delete();
  $this
    ->assertFalse(entity_load('breakpoint_group', $group->id), t('breakpoint_group_load: Loading a deleted breakpoint group returns false.'), t('Breakpoints API'));
}