Chris@0: install(['breakpoint_theme_test']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test the breakpoint group created for a theme. Chris@0: */ Chris@0: public function testThemeBreakpoints() { Chris@0: // Verify the breakpoint group for breakpoint_theme_test was created. Chris@0: $expected_breakpoints = [ Chris@0: 'breakpoint_theme_test.mobile' => [ Chris@0: 'label' => 'mobile', Chris@0: 'mediaQuery' => '(min-width: 0px)', Chris@0: 'weight' => 0, Chris@0: 'multipliers' => [ Chris@0: '1x', Chris@0: ], Chris@0: 'provider' => 'breakpoint_theme_test', Chris@0: 'id' => 'breakpoint_theme_test.mobile', Chris@0: 'group' => 'breakpoint_theme_test', Chris@0: 'class' => 'Drupal\\breakpoint\\Breakpoint', Chris@0: ], Chris@0: 'breakpoint_theme_test.narrow' => [ Chris@0: 'label' => 'narrow', Chris@0: 'mediaQuery' => '(min-width: 560px)', Chris@0: 'weight' => 1, Chris@0: 'multipliers' => [ Chris@0: '1x', Chris@0: ], Chris@0: 'provider' => 'breakpoint_theme_test', Chris@0: 'id' => 'breakpoint_theme_test.narrow', Chris@0: 'group' => 'breakpoint_theme_test', Chris@0: 'class' => 'Drupal\\breakpoint\\Breakpoint', Chris@0: ], Chris@0: 'breakpoint_theme_test.wide' => [ Chris@0: 'label' => 'wide', Chris@0: 'mediaQuery' => '(min-width: 851px)', Chris@0: 'weight' => 2, Chris@0: 'multipliers' => [ Chris@0: '1x', Chris@0: ], Chris@0: 'provider' => 'breakpoint_theme_test', Chris@0: 'id' => 'breakpoint_theme_test.wide', Chris@0: 'group' => 'breakpoint_theme_test', Chris@0: 'class' => 'Drupal\\breakpoint\\Breakpoint', Chris@0: ], Chris@0: 'breakpoint_theme_test.tv' => [ Chris@0: 'label' => 'tv', Chris@0: 'mediaQuery' => 'only screen and (min-width: 1220px)', Chris@0: 'weight' => 3, Chris@0: 'multipliers' => [ Chris@0: '1x', Chris@0: ], Chris@0: 'provider' => 'breakpoint_theme_test', Chris@0: 'id' => 'breakpoint_theme_test.tv', Chris@0: 'group' => 'breakpoint_theme_test', Chris@0: 'class' => 'Drupal\\breakpoint\\Breakpoint', Chris@0: ], Chris@0: ]; Chris@0: Chris@0: $breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('breakpoint_theme_test'); Chris@0: foreach ($expected_breakpoints as $id => $expected_breakpoint) { Chris@0: $this->assertEqual($expected_breakpoint, $breakpoints[$id]->getPluginDefinition()); Chris@0: } Chris@0: Chris@0: // Test that the order is as expected. Chris@0: $this->assertIdentical(array_keys($expected_breakpoints), array_keys($breakpoints)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test the custom breakpoint group provided by a theme and a module. Chris@0: */ Chris@0: public function testCustomBreakpointGroups() { Chris@0: // Verify the breakpoint group for breakpoint_theme_test.group2 was created. Chris@0: $expected_breakpoints = [ Chris@0: 'breakpoint_theme_test.group2.narrow' => [ Chris@0: 'label' => 'narrow', Chris@0: 'mediaQuery' => '(min-width: 560px)', Chris@0: 'weight' => 0, Chris@0: 'multipliers' => [ Chris@0: '1x', Chris@0: '2x', Chris@0: ], Chris@0: 'provider' => 'breakpoint_theme_test', Chris@0: 'id' => 'breakpoint_theme_test.group2.narrow', Chris@0: 'group' => 'breakpoint_theme_test.group2', Chris@0: 'class' => 'Drupal\\breakpoint\\Breakpoint', Chris@0: ], Chris@0: 'breakpoint_theme_test.group2.wide' => [ Chris@0: 'label' => 'wide', Chris@0: 'mediaQuery' => '(min-width: 851px)', Chris@0: 'weight' => 1, Chris@0: 'multipliers' => [ Chris@0: '1x', Chris@0: '2x', Chris@0: ], Chris@0: 'provider' => 'breakpoint_theme_test', Chris@0: 'id' => 'breakpoint_theme_test.group2.wide', Chris@0: 'group' => 'breakpoint_theme_test.group2', Chris@0: 'class' => 'Drupal\\breakpoint\\Breakpoint', Chris@0: ], Chris@0: 'breakpoint_module_test.breakpoint_theme_test.group2.tv' => [ Chris@0: 'label' => 'tv', Chris@0: 'mediaQuery' => '(min-width: 6000px)', Chris@0: 'weight' => 2, Chris@0: 'multipliers' => [ Chris@0: '1x', Chris@0: ], Chris@0: 'provider' => 'breakpoint_module_test', Chris@0: 'id' => 'breakpoint_module_test.breakpoint_theme_test.group2.tv', Chris@0: 'group' => 'breakpoint_theme_test.group2', Chris@0: 'class' => 'Drupal\\breakpoint\\Breakpoint', Chris@0: ], Chris@0: ]; Chris@0: Chris@0: $breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('breakpoint_theme_test.group2'); Chris@0: foreach ($expected_breakpoints as $id => $expected_breakpoint) { Chris@0: $this->assertEqual($expected_breakpoint, $breakpoints[$id]->getPluginDefinition()); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test the breakpoint group created for a module. Chris@0: */ Chris@0: public function testModuleBreakpoints() { Chris@0: $expected_breakpoints = [ Chris@0: 'breakpoint_module_test.mobile' => [ Chris@0: 'label' => 'mobile', Chris@0: 'mediaQuery' => '(min-width: 0px)', Chris@0: 'weight' => 0, Chris@0: 'multipliers' => [ Chris@0: '1x', Chris@0: ], Chris@0: 'provider' => 'breakpoint_module_test', Chris@0: 'id' => 'breakpoint_module_test.mobile', Chris@0: 'group' => 'breakpoint_module_test', Chris@0: 'class' => 'Drupal\\breakpoint\\Breakpoint', Chris@0: ], Chris@0: 'breakpoint_module_test.standard' => [ Chris@0: 'label' => 'standard', Chris@0: 'mediaQuery' => '(min-width: 560px)', Chris@0: 'weight' => 1, Chris@0: 'multipliers' => [ Chris@0: '1x', Chris@0: '2x', Chris@0: ], Chris@0: 'provider' => 'breakpoint_module_test', Chris@0: 'id' => 'breakpoint_module_test.standard', Chris@0: 'group' => 'breakpoint_module_test', Chris@0: 'class' => 'Drupal\\breakpoint\\Breakpoint', Chris@0: ], Chris@0: ]; Chris@0: Chris@0: $breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('breakpoint_module_test'); Chris@0: $this->assertEqual(array_keys($expected_breakpoints), array_keys($breakpoints)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test the collection of breakpoint groups. Chris@0: */ Chris@0: public function testBreakpointGroups() { Chris@0: $expected = [ Chris@0: 'bartik' => 'Bartik', Chris@0: 'breakpoint_module_test' => 'Breakpoint test module', Chris@0: 'breakpoint_theme_test' => 'Breakpoint test theme', Chris@0: 'breakpoint_theme_test.group2' => 'breakpoint_theme_test.group2', Chris@0: ]; Chris@0: $breakpoint_groups = \Drupal::service('breakpoint.manager')->getGroups(); Chris@0: // Ensure the order is as expected. Should be sorted by label. Chris@0: $this->assertIdentical($expected, $this->castSafeStrings($breakpoint_groups)); Chris@0: Chris@0: $expected = [ Chris@0: 'breakpoint_theme_test' => 'theme', Chris@0: 'breakpoint_module_test' => 'module', Chris@0: ]; Chris@0: $breakpoint_group_providers = \Drupal::service('breakpoint.manager')->getGroupProviders('breakpoint_theme_test.group2'); Chris@0: $this->assertEqual($expected, $breakpoint_group_providers); Chris@0: } Chris@0: Chris@0: }