You are here

public function BreakpointThemeTest::testThemeBreakpointGroupModule in Breakpoints 8

Test the breakpoints defined by the custom group in the module.

File

lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php, line 126
Definition of Drupal\breakpoint\Tests\BreakpointsThemeTest.

Class

BreakpointThemeTest
Test breakpoints provided by themes.

Namespace

Drupal\breakpoint\Tests

Code

public function testThemeBreakpointGroupModule() {

  // Call the import manually, since the testbot needs to enable the module
  // first, otherwise the theme isn't detected.
  _breakpoint_import_breakpoint_groups('breakpoint_theme_test', Breakpoint::SOURCE_TYPE_MODULE);

  // Verify the breakpoint group 'module_test' was created by
  // breakpoint_theme_test module.
  $breakpoint_group_obj = entity_create('breakpoint_group', array(
    'label' => 'Test Module',
    'id' => 'module_test',
    'sourceType' => Breakpoint::SOURCE_TYPE_MODULE,
    'source' => 'breakpoint_theme_test',
    'overridden' => FALSE,
  ));
  $breakpoint_group_obj->breakpoints = array(
    'theme.breakpoint_test_theme.mobile' => array(),
    'theme.breakpoint_test_theme.narrow' => array(),
    'theme.breakpoint_test_theme.wide' => array(),
  );

  // Verify we can load this breakpoint defined by the theme.
  $this
    ->verifyBreakpointGroup($breakpoint_group_obj);

  // Override the breakpoints.
  $overridden_set = clone $breakpoint_group_obj;
  $breakpoint_group = entity_load('breakpoint_group', 'module_test');
  $breakpoint_group = $breakpoint_group
    ->override();
  $overridden_set->overridden = 1;
  $this
    ->verifyBreakpointGroup($overridden_set);

  // This group uses breakpoints defined by an other theme. This means the
  // breakpoints should *not* be overridden.
  foreach (array_keys($breakpoint_group_obj->breakpoints) as $breakpoint_id) {
    $breakpoint = entity_load('breakpoint', $breakpoint_id, TRUE);
    $this
      ->assertFalse($breakpoint->overridden, t('Breakpoint @breakpoint should not be overridden.', array(
      '@breakpoint' => $breakpoint
        ->label(),
    )), t('Breakpoint API'));
  }

  // Revert the breakpoint group.
  $breakpoint_group = entity_load('breakpoint_group', 'module_test');
  $breakpoint_group = $breakpoint_group
    ->revert();
  $this
    ->verbose(highlight_string("<?php \n// Object\n" . var_export($breakpoint_group_obj, TRUE), TRUE));
  $this
    ->verbose(highlight_string("<?php \n// Group\n" . var_export($breakpoint_group, TRUE), TRUE));

  // Verify the breakpoint group has its original values again when loaded.
  $this
    ->verifyBreakpointGroup($breakpoint_group_obj);

  // Verify the breakpoints in this breakpoint group are not overridden.
  foreach (array_keys($breakpoint_group_obj->breakpoints) as $breakpoint_id) {
    $breakpoint = entity_load('breakpoint', $breakpoint_id);
    $this
      ->assertFalse($breakpoint->overridden, t('Breakpoint @breakpoint should not be overridden.', array(
      '@breakpoint' => $breakpoint
        ->label(),
    )), t('Breakpoint API'));
  }

  // Disable the test theme and verify the breakpoint group still exists.
  theme_disable(array(
    'breakpoint_test_theme',
  ));
  $this
    ->assertTrue(entity_load('breakpoint_group', 'module_test'), 'Breakpoint group still exists if theme is disabled.');

  // Disable the test module and verify the breakpoint group still exists.
  module_disable(array(
    'breakpoint_theme_test',
  ));
  $this
    ->assertTrue(entity_load('breakpoint_group', 'module_test'), 'Breakpoint group still exists if module is disabled.');

  // Uninstall the test module and verify the breakpoint group is deleted.
  module_uninstall(array(
    'breakpoint_theme_test',
  ));
  $this
    ->assertFalse(entity_load('breakpoint_group', 'module_test'), 'Breakpoint group is removed if module is uninstalled.');
}