summaryrefslogtreecommitdiffstats
path: root/core/modules/breakpoint/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/breakpoint/tests/src')
-rw-r--r--core/modules/breakpoint/tests/src/BreakpointConfigEntityUnitTest.php123
-rw-r--r--core/modules/breakpoint/tests/src/BreakpointGroupConfigEntityUnitTest.php158
-rw-r--r--core/modules/breakpoint/tests/src/BreakpointMediaQueryTest.php117
-rw-r--r--core/modules/breakpoint/tests/src/BreakpointTest.php122
4 files changed, 122 insertions, 398 deletions
diff --git a/core/modules/breakpoint/tests/src/BreakpointConfigEntityUnitTest.php b/core/modules/breakpoint/tests/src/BreakpointConfigEntityUnitTest.php
deleted file mode 100644
index 3b10801..0000000
--- a/core/modules/breakpoint/tests/src/BreakpointConfigEntityUnitTest.php
+++ /dev/null
@@ -1,123 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\breakpoint\Tests\BreakpointConfigEntityUnitTest.
- */
-
-namespace Drupal\breakpoint\Tests;
-
-use Drupal\breakpoint\Entity\Breakpoint;
-use Drupal\Core\DependencyInjection\ContainerBuilder;
-use Drupal\Tests\UnitTestCase;
-
-/**
- * @coversDefaultClass \Drupal\breakpoint\Entity\Breakpoint
- * @group breakpoint
- */
-class BreakpointConfigEntityUnitTest extends UnitTestCase {
-
- /**
- * The entity under test.
- *
- * @var \Drupal\breakpoint\Entity\Breakpoint|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $entity;
-
- /**
- * The entity type used for testing.
- *
- * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $entityType;
-
- /**
- * The entity manager used for testing.
- *
- * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $entityManager;
-
- /**
- * The ID of the type of the entity under test.
- *
- * @var string
- */
- protected $entityTypeId;
-
- /**
- * The UUID generator used for testing.
- *
- * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $uuid;
-
- /**
- * {@inheritdoc}
- */
- protected function setUp() {
- $this->entityTypeId = $this->randomMachineName();
-
- $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
- $this->entityType->expects($this->any())
- ->method('getProvider')
- ->will($this->returnValue('breakpoint'));
-
- $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
- $this->entityManager->expects($this->any())
- ->method('getDefinition')
- ->with($this->entityTypeId)
- ->will($this->returnValue($this->entityType));
-
- $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
-
- $container = new ContainerBuilder();
- $container->set('entity.manager', $this->entityManager);
- $container->set('uuid', $this->uuid);
- \Drupal::setContainer($container);
- }
-
- /**
- * @covers ::calculateDependencies
- */
- public function testCalculateDependenciesModule() {
- $values = array(
- 'name' => 'test',
- 'source' => 'test_module',
- 'sourceType' => Breakpoint::SOURCE_TYPE_MODULE,
- );
- $entity = new Breakpoint($values, $this->entityTypeId);
-
- $dependencies = $entity->calculateDependencies();
- $this->assertArrayNotHasKey('theme', $dependencies);
- $this->assertContains('test_module', $dependencies['module']);
- }
-
- /**
- * @covers ::calculateDependencies
- */
- public function testCalculateDependenciesTheme() {
- $values = array(
- 'name' => 'test',
- 'source' => 'test_theme',
- 'sourceType' => Breakpoint::SOURCE_TYPE_THEME,
- );
- $entity = new Breakpoint($values, $this->entityTypeId);
-
- $dependencies = $entity->calculateDependencies();
- $this->assertArrayNotHasKey('module', $dependencies);
- $this->assertContains('test_theme', $dependencies['theme']);
- }
-
- /**
- * @expectedException \Drupal\breakpoint\InvalidBreakpointNameException
- */
- public function testNameException () {
- new Breakpoint(array(
- 'label' => $this->randomMachineName(),
- 'source' => 'custom_module',
- 'sourceType' => 'oops',
- ));
- }
-
-}
diff --git a/core/modules/breakpoint/tests/src/BreakpointGroupConfigEntityUnitTest.php b/core/modules/breakpoint/tests/src/BreakpointGroupConfigEntityUnitTest.php
deleted file mode 100644
index 61ad1ac..0000000
--- a/core/modules/breakpoint/tests/src/BreakpointGroupConfigEntityUnitTest.php
+++ /dev/null
@@ -1,158 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\breakpoint\Tests\BreakpointGroupConfigEntityUnitTest.
- */
-
-namespace Drupal\breakpoint\Tests;
-
-use Drupal\breakpoint\Entity\Breakpoint;
-use Drupal\breakpoint\Entity\BreakpointGroup;
-use Drupal\Core\DependencyInjection\ContainerBuilder;
-use Drupal\Tests\UnitTestCase;
-
-/**
- * @coversDefaultClass \Drupal\breakpoint\Entity\BreakpointGroup
- * @group breakpoint
- */
-class BreakpointGroupConfigEntityUnitTest extends UnitTestCase {
-
- /**
- * The entity under test.
- *
- * @var \Drupal\breakpoint\Entity\BreakpointGroup|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $entity;
-
- /**
- * The entity type used for testing.
- *
- * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $entityType;
-
- /**
- * The entity manager used for testing.
- *
- * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $entityManager;
-
- /**
- * The ID of the type of the entity under test.
- *
- * @var string
- */
- protected $entityTypeId;
-
- /**
- * The UUID generator used for testing.
- *
- * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $uuid;
-
- /**
- * {@inheritdoc}
- */
- protected function setUp() {
- $this->entityTypeId = $this->randomMachineName();
-
- $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
- $this->entityType->expects($this->any())
- ->method('getProvider')
- ->will($this->returnValue('breakpoint'));
-
- $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
- $this->entityManager->expects($this->any())
- ->method('getDefinition')
- ->with($this->entityTypeId)
- ->will($this->returnValue($this->entityType));
-
- $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
-
- $container = new ContainerBuilder();
- $container->set('entity.manager', $this->entityManager);
- $container->set('uuid', $this->uuid);
- \Drupal::setContainer($container);
- }
-
- /**
- * Sets up the entity to test.
- */
- public function setUpEntity($values) {
- // Mocking the entity under test because the class contains calls to
- // procedural code.
- $this->entity = $this->getMockBuilder('\Drupal\breakpoint\Entity\BreakpointGroup')
- ->setConstructorArgs(array($values, $this->entityTypeId))
- ->setMethods(array('getBreakpoints'))
- ->getMock();
- }
-
- /**
- * @covers ::calculateDependencies
- */
- public function testCalculateDependenciesModule() {
- $this->setUpEntity(
- array(
- 'name' => 'test',
- 'source' => 'test_module',
- 'sourceType' => Breakpoint::SOURCE_TYPE_MODULE,
- )
- );
- $breakpoint = $this->getMock('\Drupal\breakpoint\BreakpointInterface');
- $breakpoint->expects($this->once())
- ->method('getConfigDependencyName')
- ->will($this->returnValue('breakpoint.breakpoint.test'));
-
- $this->entity->expects($this->once())
- ->method('getBreakpoints')
- ->will($this->returnValue(array($breakpoint)));
-
- $dependencies = $this->entity->calculateDependencies();
- $this->assertArrayNotHasKey('theme', $dependencies);
- $this->assertContains('test_module', $dependencies['module']);
- $this->assertContains('breakpoint.breakpoint.test', $dependencies['entity']);
- }
-
- /**
- * @covers ::calculateDependencies
- */
- public function testCalculateDependenciesTheme() {
- $this->setUpEntity(
- array(
- 'name' => 'test',
- 'source' => 'test_theme',
- 'sourceType' => Breakpoint::SOURCE_TYPE_THEME,
- )
- );
-
- $breakpoint = $this->getMockBuilder('\Drupal\breakpoint\Entity\Breakpoint')
- ->disableOriginalConstructor()->getMock();
- $breakpoint->expects($this->once())
- ->method('getConfigDependencyName')
- ->will($this->returnValue('breakpoint.breakpoint.test'));
-
- $this->entity->expects($this->once())
- ->method('getBreakpoints')
- ->will($this->returnValue(array($breakpoint)));
-
- $dependencies = $this->entity->calculateDependencies();
- $this->assertArrayNotHasKey('module', $dependencies);
- $this->assertContains('test_theme', $dependencies['theme']);
- $this->assertContains('breakpoint.breakpoint.test', $dependencies['entity']);
- }
-
- /**
- * @expectedException \Drupal\breakpoint\InvalidBreakpointNameException
- */
- public function testNameException () {
- new BreakpointGroup(array(
- 'label' => $this->randomMachineName(),
- 'source' => 'custom_module',
- 'sourceType' => 'oops',
- ));
- }
-
-}
diff --git a/core/modules/breakpoint/tests/src/BreakpointMediaQueryTest.php b/core/modules/breakpoint/tests/src/BreakpointMediaQueryTest.php
deleted file mode 100644
index c8ab81d..0000000
--- a/core/modules/breakpoint/tests/src/BreakpointMediaQueryTest.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-/**
- * @file
- * Definition of Drupal\breakpoint\Tests\BreakpointMediaQueryTest.
- */
-
-namespace Drupal\breakpoint\Tests;
-
-use Drupal\Tests\UnitTestCase;
-use Drupal\breakpoint\Entity\Breakpoint;
-use Drupal\breakpoint\InvalidBreakpointMediaQueryException;
-
-/**
- * Tests validation of media queries.
- *
- * @group breakpoint
- */
-class BreakpointMediaQueryTest extends UnitTestCase {
-
- /**
- * Test valid media queries.
- */
- public function testValidMediaQueries() {
- $media_queries = array(
- // Bartik breakpoints.
- '(min-width: 0px)',
- 'all and (min-width: 560px) and (max-width:850px)',
- 'all and (min-width: 851px)',
- // Seven breakpoints.
- '(min-width: 0em)',
- 'screen and (min-width: 40em)',
- // Stark breakpoints.
- '(min-width: 0px)',
- 'all and (min-width: 480px) and (max-width: 959px)',
- 'all and (min-width: 960px)',
- // Other media queries.
- '(orientation)',
- 'all and (orientation)',
- 'not all and (orientation)',
- 'only all and (orientation)',
- 'screen and (width)',
- 'screen and (width: 0)',
- 'screen and (width: 0px)',
- 'screen and (width: 0em)',
- 'screen and (min-width: -0)',
- 'screen and (max-width: 0)',
- 'screen and (max-width: 0.3)',
- 'screen and (min-width)',
- // Multiline and comments.
- 'screen and /* this is a comment */ (min-width)',
- "screen\nand /* this is a comment */ (min-width)",
- "screen\n\nand /* this is\n a comment */ (min-width)",
- // Unrecognized features are allowed.
- 'screen and (-webkit-min-device-pixel-ratio: 7)',
- 'screen and (min-orientation: landscape)',
- 'screen and (max-orientation: landscape)',
- );
-
- foreach ($media_queries as $media_query) {
- $this->assertTrue(Breakpoint::isValidMediaQuery($media_query), $media_query . ' is valid.');
- }
- }
-
- /**
- * Test invalid media queries.
- */
- public function testInvalidMediaQueries() {
- $media_queries = array(
- '',
- 'not (orientation)',
- 'only (orientation)',
- 'all and not all',
- 'screen and (width: 0xx)',
- 'screen and (width: -8xx)',
- 'screen and (width: -xx)',
- 'screen and (width: xx)',
- 'screen and (width: px)',
- 'screen and (width: -8px)',
- 'screen and (width: -0.8px)',
- 'screen and (height: 0xx)',
- 'screen and (height: -8xx)',
- 'screen and (height: -xx)',
- 'screen and (height: xx)',
- 'screen and (height: px)',
- 'screen and (height: -8px)',
- 'screen and (height: -0.8px)',
- 'screen and (device-width: 0xx)',
- 'screen and (device-width: -8xx)',
- 'screen and (device-width: -xx)',
- 'screen and (device-width: xx)',
- 'screen and (device-width: px)',
- 'screen and (device-width: -8px)',
- 'screen and (device-width: -0.8px)',
- 'screen and (device-height: 0xx)',
- 'screen and (device-height: -8xx)',
- 'screen and (device-height: -xx)',
- 'screen and (device-height: xx)',
- 'screen and (device-height: px)',
- 'screen and (device-height: -8px)',
- 'screen and (device-height: -0.8px)',
- 'screen and (min-orientation)',
- 'screen and (max-orientation)',
- 'screen and (orientation: bogus)',
- '(orientation: bogus)',
- 'screen and (ori"entation: bogus)',
- );
-
- foreach ($media_queries as $media_query) {
- try {
- $this->assertFalse(Breakpoint::isValidMediaQuery($media_query), $media_query . ' is not valid.');
- }
- catch (InvalidBreakpointMediaQueryException $e) {
- $this->assertTrue(TRUE, sprintf('%s is not valid.', $media_query));
- }
- }
- }
-}
diff --git a/core/modules/breakpoint/tests/src/BreakpointTest.php b/core/modules/breakpoint/tests/src/BreakpointTest.php
new file mode 100644
index 0000000..a2b62ea
--- /dev/null
+++ b/core/modules/breakpoint/tests/src/BreakpointTest.php
@@ -0,0 +1,122 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\breakpoint\Tests\BreakpointTest.
+ */
+
+namespace Drupal\breakpoint\Tests;
+
+use Drupal\breakpoint\Breakpoint;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @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 = array(
+ '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;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->stringTranslation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface');
+ }
+
+ /**
+ * Sets up the breakpoint defaults.
+ */
+ protected function setupBreakpoint() {
+ $this->breakpoint = new Breakpoint(array(), $this->pluginId, $this->pluginDefinition);
+ $this->breakpoint->setStringTranslation($this->stringTranslation);
+ }
+
+ /**
+ * @covers ::getLabel
+ */
+ public function testGetLabel() {
+ $this->pluginDefinition['label'] = 'Test label';
+ $this->stringTranslation->expects($this->once())
+ ->method('translate')
+ ->with($this->pluginDefinition['label'], array(), array('context' => 'breakpoint'))
+ ->will($this->returnValue('Test label translated'));
+ $this->setupBreakpoint();
+ $this->assertEquals('Test label translated', $this->breakpoint->getLabel());
+ }
+
+ /**
+ * @covers ::getWeight
+ */
+ public function testGetWeight() {
+ $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() {
+ $this->pluginDefinition['mediaQuery'] = 'only screen and (min-width: 3456px)';
+ $this->setupBreakpoint();
+ $this->assertEquals('only screen and (min-width: 3456px)', $this->breakpoint->getMediaQuery());
+ }
+
+ /**
+ * @covers ::getMultipliers
+ */
+ public function testGetMultipliers() {
+ $this->pluginDefinition['multipliers'] = array('1x', '2x');
+ $this->setupBreakpoint();
+ $this->assertSame(array('1x', '2x'), $this->breakpoint->getMultipliers());
+ }
+
+ /**
+ * @covers ::getProvider
+ */
+ public function testGetProvider() {
+ $this->pluginDefinition['provider'] = 'Breakpoint';
+ $this->setupBreakpoint();
+ $this->assertEquals('Breakpoint', $this->breakpoint->getProvider());
+ }
+
+ /**
+ * @covers ::getGroup
+ */
+ public function testGetGroup() {
+ $this->pluginDefinition['group'] = 'Breakpoint';
+ $this->setupBreakpoint();
+ $this->assertEquals('Breakpoint', $this->breakpoint->getGroup());
+ }
+
+}