annotate core/modules/breakpoint/tests/src/Kernel/BreakpointDiscoveryTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\breakpoint\Kernel;
Chris@0 4
Chris@0 5 use Drupal\KernelTests\KernelTestBase;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Tests discovery of breakpoints provided by themes and modules.
Chris@0 9 *
Chris@0 10 * @group breakpoint
Chris@0 11 */
Chris@0 12 class BreakpointDiscoveryTest extends KernelTestBase {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Modules to install.
Chris@0 16 *
Chris@0 17 * @var array
Chris@0 18 */
Chris@0 19 public static $modules = ['system', 'breakpoint', 'breakpoint_module_test'];
Chris@0 20
Chris@0 21 protected function setUp() {
Chris@0 22 parent::setUp();
Chris@0 23 \Drupal::service('theme_handler')->install(['breakpoint_theme_test']);
Chris@0 24 }
Chris@0 25
Chris@0 26 /**
Chris@0 27 * Test the breakpoint group created for a theme.
Chris@0 28 */
Chris@0 29 public function testThemeBreakpoints() {
Chris@0 30 // Verify the breakpoint group for breakpoint_theme_test was created.
Chris@0 31 $expected_breakpoints = [
Chris@0 32 'breakpoint_theme_test.mobile' => [
Chris@0 33 'label' => 'mobile',
Chris@0 34 'mediaQuery' => '(min-width: 0px)',
Chris@0 35 'weight' => 0,
Chris@0 36 'multipliers' => [
Chris@0 37 '1x',
Chris@0 38 ],
Chris@0 39 'provider' => 'breakpoint_theme_test',
Chris@0 40 'id' => 'breakpoint_theme_test.mobile',
Chris@0 41 'group' => 'breakpoint_theme_test',
Chris@0 42 'class' => 'Drupal\\breakpoint\\Breakpoint',
Chris@0 43 ],
Chris@0 44 'breakpoint_theme_test.narrow' => [
Chris@0 45 'label' => 'narrow',
Chris@0 46 'mediaQuery' => '(min-width: 560px)',
Chris@0 47 'weight' => 1,
Chris@0 48 'multipliers' => [
Chris@0 49 '1x',
Chris@0 50 ],
Chris@0 51 'provider' => 'breakpoint_theme_test',
Chris@0 52 'id' => 'breakpoint_theme_test.narrow',
Chris@0 53 'group' => 'breakpoint_theme_test',
Chris@0 54 'class' => 'Drupal\\breakpoint\\Breakpoint',
Chris@0 55 ],
Chris@0 56 'breakpoint_theme_test.wide' => [
Chris@0 57 'label' => 'wide',
Chris@0 58 'mediaQuery' => '(min-width: 851px)',
Chris@0 59 'weight' => 2,
Chris@0 60 'multipliers' => [
Chris@0 61 '1x',
Chris@0 62 ],
Chris@0 63 'provider' => 'breakpoint_theme_test',
Chris@0 64 'id' => 'breakpoint_theme_test.wide',
Chris@0 65 'group' => 'breakpoint_theme_test',
Chris@0 66 'class' => 'Drupal\\breakpoint\\Breakpoint',
Chris@0 67 ],
Chris@0 68 'breakpoint_theme_test.tv' => [
Chris@0 69 'label' => 'tv',
Chris@0 70 'mediaQuery' => 'only screen and (min-width: 1220px)',
Chris@0 71 'weight' => 3,
Chris@0 72 'multipliers' => [
Chris@0 73 '1x',
Chris@0 74 ],
Chris@0 75 'provider' => 'breakpoint_theme_test',
Chris@0 76 'id' => 'breakpoint_theme_test.tv',
Chris@0 77 'group' => 'breakpoint_theme_test',
Chris@0 78 'class' => 'Drupal\\breakpoint\\Breakpoint',
Chris@0 79 ],
Chris@0 80 ];
Chris@0 81
Chris@0 82 $breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('breakpoint_theme_test');
Chris@0 83 foreach ($expected_breakpoints as $id => $expected_breakpoint) {
Chris@0 84 $this->assertEqual($expected_breakpoint, $breakpoints[$id]->getPluginDefinition());
Chris@0 85 }
Chris@0 86
Chris@0 87 // Test that the order is as expected.
Chris@0 88 $this->assertIdentical(array_keys($expected_breakpoints), array_keys($breakpoints));
Chris@0 89 }
Chris@0 90
Chris@0 91 /**
Chris@0 92 * Test the custom breakpoint group provided by a theme and a module.
Chris@0 93 */
Chris@0 94 public function testCustomBreakpointGroups() {
Chris@0 95 // Verify the breakpoint group for breakpoint_theme_test.group2 was created.
Chris@0 96 $expected_breakpoints = [
Chris@0 97 'breakpoint_theme_test.group2.narrow' => [
Chris@0 98 'label' => 'narrow',
Chris@0 99 'mediaQuery' => '(min-width: 560px)',
Chris@0 100 'weight' => 0,
Chris@0 101 'multipliers' => [
Chris@0 102 '1x',
Chris@0 103 '2x',
Chris@0 104 ],
Chris@0 105 'provider' => 'breakpoint_theme_test',
Chris@0 106 'id' => 'breakpoint_theme_test.group2.narrow',
Chris@0 107 'group' => 'breakpoint_theme_test.group2',
Chris@0 108 'class' => 'Drupal\\breakpoint\\Breakpoint',
Chris@0 109 ],
Chris@0 110 'breakpoint_theme_test.group2.wide' => [
Chris@0 111 'label' => 'wide',
Chris@0 112 'mediaQuery' => '(min-width: 851px)',
Chris@0 113 'weight' => 1,
Chris@0 114 'multipliers' => [
Chris@0 115 '1x',
Chris@0 116 '2x',
Chris@0 117 ],
Chris@0 118 'provider' => 'breakpoint_theme_test',
Chris@0 119 'id' => 'breakpoint_theme_test.group2.wide',
Chris@0 120 'group' => 'breakpoint_theme_test.group2',
Chris@0 121 'class' => 'Drupal\\breakpoint\\Breakpoint',
Chris@0 122 ],
Chris@0 123 'breakpoint_module_test.breakpoint_theme_test.group2.tv' => [
Chris@0 124 'label' => 'tv',
Chris@0 125 'mediaQuery' => '(min-width: 6000px)',
Chris@0 126 'weight' => 2,
Chris@0 127 'multipliers' => [
Chris@0 128 '1x',
Chris@0 129 ],
Chris@0 130 'provider' => 'breakpoint_module_test',
Chris@0 131 'id' => 'breakpoint_module_test.breakpoint_theme_test.group2.tv',
Chris@0 132 'group' => 'breakpoint_theme_test.group2',
Chris@0 133 'class' => 'Drupal\\breakpoint\\Breakpoint',
Chris@0 134 ],
Chris@0 135 ];
Chris@0 136
Chris@0 137 $breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('breakpoint_theme_test.group2');
Chris@0 138 foreach ($expected_breakpoints as $id => $expected_breakpoint) {
Chris@0 139 $this->assertEqual($expected_breakpoint, $breakpoints[$id]->getPluginDefinition());
Chris@0 140 }
Chris@0 141 }
Chris@0 142
Chris@0 143 /**
Chris@0 144 * Test the breakpoint group created for a module.
Chris@0 145 */
Chris@0 146 public function testModuleBreakpoints() {
Chris@0 147 $expected_breakpoints = [
Chris@0 148 'breakpoint_module_test.mobile' => [
Chris@0 149 'label' => 'mobile',
Chris@0 150 'mediaQuery' => '(min-width: 0px)',
Chris@0 151 'weight' => 0,
Chris@0 152 'multipliers' => [
Chris@0 153 '1x',
Chris@0 154 ],
Chris@0 155 'provider' => 'breakpoint_module_test',
Chris@0 156 'id' => 'breakpoint_module_test.mobile',
Chris@0 157 'group' => 'breakpoint_module_test',
Chris@0 158 'class' => 'Drupal\\breakpoint\\Breakpoint',
Chris@0 159 ],
Chris@0 160 'breakpoint_module_test.standard' => [
Chris@0 161 'label' => 'standard',
Chris@0 162 'mediaQuery' => '(min-width: 560px)',
Chris@0 163 'weight' => 1,
Chris@0 164 'multipliers' => [
Chris@0 165 '1x',
Chris@0 166 '2x',
Chris@0 167 ],
Chris@0 168 'provider' => 'breakpoint_module_test',
Chris@0 169 'id' => 'breakpoint_module_test.standard',
Chris@0 170 'group' => 'breakpoint_module_test',
Chris@0 171 'class' => 'Drupal\\breakpoint\\Breakpoint',
Chris@0 172 ],
Chris@0 173 ];
Chris@0 174
Chris@0 175 $breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('breakpoint_module_test');
Chris@0 176 $this->assertEqual(array_keys($expected_breakpoints), array_keys($breakpoints));
Chris@0 177 }
Chris@0 178
Chris@0 179 /**
Chris@0 180 * Test the collection of breakpoint groups.
Chris@0 181 */
Chris@0 182 public function testBreakpointGroups() {
Chris@0 183 $expected = [
Chris@0 184 'bartik' => 'Bartik',
Chris@0 185 'breakpoint_module_test' => 'Breakpoint test module',
Chris@0 186 'breakpoint_theme_test' => 'Breakpoint test theme',
Chris@0 187 'breakpoint_theme_test.group2' => 'breakpoint_theme_test.group2',
Chris@0 188 ];
Chris@0 189 $breakpoint_groups = \Drupal::service('breakpoint.manager')->getGroups();
Chris@0 190 // Ensure the order is as expected. Should be sorted by label.
Chris@0 191 $this->assertIdentical($expected, $this->castSafeStrings($breakpoint_groups));
Chris@0 192
Chris@0 193 $expected = [
Chris@0 194 'breakpoint_theme_test' => 'theme',
Chris@0 195 'breakpoint_module_test' => 'module',
Chris@0 196 ];
Chris@0 197 $breakpoint_group_providers = \Drupal::service('breakpoint.manager')->getGroupProviders('breakpoint_theme_test.group2');
Chris@0 198 $this->assertEqual($expected, $breakpoint_group_providers);
Chris@0 199 }
Chris@0 200
Chris@0 201 }