first commit

This commit is contained in:
2024-07-15 12:33:27 +02:00
commit ce50ae282b
22084 changed files with 2623791 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
breakpoint_module_test.mobile:
label: mobile
mediaQuery: '(min-width: 0px)'
weight: 0
# Don't include multipliers. A 1x multiplier this will be enforced by default.
breakpoint_module_test.standard:
label: standard
mediaQuery: '(min-width: 560px)'
weight: 1
# Don't include a 1x multiplier this will be enforced by default.
multipliers:
- 2x
# Test providing a breakpoint for group matching the group provided by
# breakpoint_test_theme.
breakpoint_module_test.breakpoint_theme_test.group2.tv:
label: tv
mediaQuery: '(min-width: 6000px)'
weight: 2
multipliers:
- 1x
group: breakpoint_theme_test.group2

View File

@@ -0,0 +1,10 @@
name: 'Breakpoint test module'
type: module
description: 'Test module for breakpoint.'
package: Testing
# version: VERSION
# Information added by Drupal.org packaging script on 2024-07-04
version: '10.3.1'
project: 'drupal'
datestamp: 1720094222

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\breakpoint\Functional;
use Drupal\Tests\system\Functional\Module\GenericModuleTestBase;
/**
* Generic module test for breakpoint.
*
* @group breakpoint
*/
class GenericTest extends GenericModuleTestBase {}

View File

@@ -0,0 +1,210 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\breakpoint\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests discovery of breakpoints provided by themes and modules.
*
* @group breakpoint
*/
class BreakpointDiscoveryTest extends KernelTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'system',
'breakpoint',
'breakpoint_module_test',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
\Drupal::service('theme_installer')->install(['breakpoint_theme_test']);
}
/**
* Tests the breakpoint group created for a theme.
*/
public function testThemeBreakpoints(): void {
// Verify the breakpoint group for breakpoint_theme_test was created.
$expected_breakpoints = [
'breakpoint_theme_test.mobile' => [
'label' => 'mobile',
'mediaQuery' => '(min-width: 0px)',
'weight' => 0,
'multipliers' => [
'1x',
],
'provider' => 'breakpoint_theme_test',
'id' => 'breakpoint_theme_test.mobile',
'group' => 'breakpoint_theme_test',
'class' => 'Drupal\\breakpoint\\Breakpoint',
],
'breakpoint_theme_test.narrow' => [
'label' => 'narrow',
'mediaQuery' => '(min-width: 560px)',
'weight' => 1,
'multipliers' => [
'1x',
],
'provider' => 'breakpoint_theme_test',
'id' => 'breakpoint_theme_test.narrow',
'group' => 'breakpoint_theme_test',
'class' => 'Drupal\\breakpoint\\Breakpoint',
],
'breakpoint_theme_test.wide' => [
'label' => 'wide',
'mediaQuery' => '(min-width: 851px)',
'weight' => 2,
'multipliers' => [
'1x',
],
'provider' => 'breakpoint_theme_test',
'id' => 'breakpoint_theme_test.wide',
'group' => 'breakpoint_theme_test',
'class' => 'Drupal\\breakpoint\\Breakpoint',
],
'breakpoint_theme_test.tv' => [
'label' => 'tv',
'mediaQuery' => 'only screen and (min-width: 1220px)',
'weight' => 3,
'multipliers' => [
'1x',
],
'provider' => 'breakpoint_theme_test',
'id' => 'breakpoint_theme_test.tv',
'group' => 'breakpoint_theme_test',
'class' => 'Drupal\\breakpoint\\Breakpoint',
],
];
$breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('breakpoint_theme_test');
foreach ($expected_breakpoints as $id => $expected_breakpoint) {
$this->assertEquals($expected_breakpoint, $breakpoints[$id]->getPluginDefinition());
}
// Test that the order is as expected.
$this->assertSame(array_keys($expected_breakpoints), array_keys($breakpoints));
}
/**
* Tests the custom breakpoint group provided by a theme and a module.
*/
public function testCustomBreakpointGroups(): void {
// Verify the breakpoint group for breakpoint_theme_test.group2 was created.
$expected_breakpoints = [
'breakpoint_theme_test.group2.narrow' => [
'label' => 'narrow',
'mediaQuery' => '(min-width: 560px)',
'weight' => 0,
'multipliers' => [
'1x',
'2x',
],
'provider' => 'breakpoint_theme_test',
'id' => 'breakpoint_theme_test.group2.narrow',
'group' => 'breakpoint_theme_test.group2',
'class' => 'Drupal\\breakpoint\\Breakpoint',
],
'breakpoint_theme_test.group2.wide' => [
'label' => 'wide',
'mediaQuery' => '(min-width: 851px)',
'weight' => 1,
'multipliers' => [
'1x',
'2x',
],
'provider' => 'breakpoint_theme_test',
'id' => 'breakpoint_theme_test.group2.wide',
'group' => 'breakpoint_theme_test.group2',
'class' => 'Drupal\\breakpoint\\Breakpoint',
],
'breakpoint_module_test.breakpoint_theme_test.group2.tv' => [
'label' => 'tv',
'mediaQuery' => '(min-width: 6000px)',
'weight' => 2,
'multipliers' => [
'1x',
],
'provider' => 'breakpoint_module_test',
'id' => 'breakpoint_module_test.breakpoint_theme_test.group2.tv',
'group' => 'breakpoint_theme_test.group2',
'class' => 'Drupal\\breakpoint\\Breakpoint',
],
];
$breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('breakpoint_theme_test.group2');
foreach ($expected_breakpoints as $id => $expected_breakpoint) {
$this->assertEquals($expected_breakpoint, $breakpoints[$id]->getPluginDefinition());
}
}
/**
* Tests the breakpoint group created for a module.
*/
public function testModuleBreakpoints(): void {
$expected_breakpoints = [
'breakpoint_module_test.mobile' => [
'label' => 'mobile',
'mediaQuery' => '(min-width: 0px)',
'weight' => 0,
'multipliers' => [
'1x',
],
'provider' => 'breakpoint_module_test',
'id' => 'breakpoint_module_test.mobile',
'group' => 'breakpoint_module_test',
'class' => 'Drupal\\breakpoint\\Breakpoint',
],
'breakpoint_module_test.standard' => [
'label' => 'standard',
'mediaQuery' => '(min-width: 560px)',
'weight' => 1,
'multipliers' => [
'1x',
'2x',
],
'provider' => 'breakpoint_module_test',
'id' => 'breakpoint_module_test.standard',
'group' => 'breakpoint_module_test',
'class' => 'Drupal\\breakpoint\\Breakpoint',
],
];
$breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('breakpoint_module_test');
$this->assertEquals(array_keys($expected_breakpoints), array_keys($breakpoints));
}
/**
* Tests the collection of breakpoint groups.
*/
public function testBreakpointGroups(): void {
$expected = [
'olivero' => 'Olivero',
'breakpoint_module_test' => 'Breakpoint test module',
'breakpoint_theme_test' => 'Breakpoint test theme',
'breakpoint_theme_test.group2' => 'breakpoint_theme_test.group2',
];
$breakpoint_groups = \Drupal::service('breakpoint.manager')->getGroups();
// Ensure the order is as expected. Should be sorted by label.
$this->assertEquals($expected, $breakpoint_groups);
$expected = [
'breakpoint_theme_test' => 'theme',
'breakpoint_module_test' => 'module',
];
$breakpoint_group_providers = \Drupal::service('breakpoint.manager')->getGroupProviders('breakpoint_theme_test.group2');
$this->assertEquals($expected, $breakpoint_group_providers);
}
}

View File

@@ -0,0 +1,119 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\breakpoint\Unit;
use Drupal\breakpoint\Breakpoint;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* @coversDefaultClass \Drupal\breakpoint\Breakpoint
* @group Breakpoint
*/
class BreakpointTest extends UnitTestCase {
/**
* The used plugin ID.
*
* @var string
*/
protected $pluginId = 'breakpoint';
/**
* The used plugin definition.
*
* @var array
*/
protected $pluginDefinition = [
'id' => 'breakpoint',
];
/**
* The breakpoint under test.
*
* @var \Drupal\breakpoint\Breakpoint
*/
protected $breakpoint;
/**
* The mocked translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $stringTranslation;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->stringTranslation = $this->createMock('Drupal\Core\StringTranslation\TranslationInterface');
}
/**
* Sets up the breakpoint defaults.
*/
protected function setupBreakpoint() {
$this->breakpoint = new Breakpoint([], $this->pluginId, $this->pluginDefinition);
$this->breakpoint->setStringTranslation($this->stringTranslation);
}
/**
* @covers ::getLabel
*/
public function testGetLabel(): void {
$this->pluginDefinition['label'] = 'Test label';
$this->setupBreakpoint();
$this->assertEquals(new TranslatableMarkup('Test label', [], ['context' => 'breakpoint'], $this->stringTranslation), $this->breakpoint->getLabel());
}
/**
* @covers ::getWeight
*/
public function testGetWeight(): void {
$this->pluginDefinition['weight'] = '4';
$this->setupBreakpoint();
// Assert that the type returned in an integer.
$this->assertSame(4, $this->breakpoint->getWeight());
}
/**
* @covers ::getMediaQuery
*/
public function testGetMediaQuery(): void {
$this->pluginDefinition['mediaQuery'] = 'only screen and (min-width: 1220px)';
$this->setupBreakpoint();
$this->assertEquals('only screen and (min-width: 1220px)', $this->breakpoint->getMediaQuery());
}
/**
* @covers ::getMultipliers
*/
public function testGetMultipliers(): void {
$this->pluginDefinition['multipliers'] = ['1x', '2x'];
$this->setupBreakpoint();
$this->assertSame(['1x', '2x'], $this->breakpoint->getMultipliers());
}
/**
* @covers ::getProvider
*/
public function testGetProvider(): void {
$this->pluginDefinition['provider'] = 'Breakpoint';
$this->setupBreakpoint();
$this->assertEquals('Breakpoint', $this->breakpoint->getProvider());
}
/**
* @covers ::getGroup
*/
public function testGetGroup(): void {
$this->pluginDefinition['group'] = 'Breakpoint';
$this->setupBreakpoint();
$this->assertEquals('Breakpoint', $this->breakpoint->getGroup());
}
}

View File

@@ -0,0 +1,41 @@
breakpoint_theme_test.mobile:
label: mobile
mediaQuery: '(min-width: 0px)'
weight: 0
multipliers:
- 1x
breakpoint_theme_test.narrow:
label: narrow
mediaQuery: '(min-width: 560px)'
weight: 1
multipliers:
- 1x
# Out of order breakpoint to test sorting.
breakpoint_theme_test.tv:
label: tv
mediaQuery: 'only screen and (min-width: 1220px)'
weight: 3
multipliers:
- 1x
breakpoint_theme_test.wide:
label: wide
mediaQuery: '(min-width: 851px)'
weight: 2
multipliers:
- 1x
breakpoint_theme_test.group2.narrow:
label: narrow
mediaQuery: '(min-width: 560px)'
weight: 0
multipliers:
- 1x
- 2x
group: breakpoint_theme_test.group2
breakpoint_theme_test.group2.wide:
label: wide
mediaQuery: '(min-width: 851px)'
weight: 1
multipliers:
- 1x
- 2x
group: breakpoint_theme_test.group2

View File

@@ -0,0 +1,10 @@
name: 'Breakpoint test theme'
type: theme
description: 'Test theme for breakpoint.'
# version: VERSION
base theme: olivero
# Information added by Drupal.org packaging script on 2024-07-04
version: '10.3.1'
project: 'drupal'
datestamp: 1720094222