diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php index 5fa0260..714e44e 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php @@ -107,6 +107,20 @@ class Breakpoint extends ConfigEntityBase implements BreakpointInterface { /** * {@inheritdoc} + * + * @throws \Drupal\breakpoint\InvalidBreakpointNameException + * Exception thrown if $values['name'] is empty. + */ + public function __construct(array $values, $entity_type = 'breakpoint') { + // Check required properties. + if (empty($values['name'])) { + throw new InvalidBreakpointNameException('Attempt to create an unnamed breakpoint.'); + } + parent::__construct($values, $entity_type); + } + + /** + * {@inheritdoc} */ public function id() { // If no ID is specified, build one from the properties that uniquely define diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php index 595ca76..c2426b7 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php @@ -7,6 +7,7 @@ namespace Drupal\breakpoint\Entity; +use Drupal\breakpoint\InvalidBreakpointNameException; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\breakpoint\BreakpointGroupInterface; use Drupal\breakpoint\InvalidBreakpointSourceException; @@ -90,9 +91,16 @@ class BreakpointGroup extends ConfigEntityBase implements BreakpointGroupInterfa public $sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED; /** - * Overrides Drupal\config\ConfigEntityBase::__construct(). + * {@inheritdoc} + * + * @throws \Drupal\breakpoint\InvalidBreakpointNameException + * Exception thrown if $values['name'] is empty. */ public function __construct(array $values, $entity_type = 'breakpoint_group') { + // Check required properties. + if (empty($values['name'])) { + throw new InvalidBreakpointNameException('Attempt to create an unnamed breakpoint group.'); + } parent::__construct($values, $entity_type); } diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php index e132280..86f9816 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php @@ -11,6 +11,7 @@ use Drupal\breakpoint\InvalidBreakpointNameException; use Drupal\breakpoint\InvalidBreakpointSourceException; use Drupal\breakpoint\InvalidBreakpointSourceTypeException; +use Drupal\Component\Utility\Unicode; /** * Tests for general breakpoint API functions. @@ -30,8 +31,10 @@ public static function getInfo() { */ public function testConfigName() { // Try an invalid sourceType. + $label = $this->randomName(); $breakpoint = entity_create('breakpoint', array( - 'label' => drupal_strtolower($this->randomName()), + 'label' => $label, + 'name' => Unicode::strtolower($label), 'source' => 'custom_module', 'sourceType' => 'oops', )); diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointCRUDTest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointCRUDTest.php index 4358869..646100a 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointCRUDTest.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointCRUDTest.php @@ -27,9 +27,11 @@ public static function getInfo() { */ public function testBreakpointCRUD() { // Add a breakpoint with minimum data only. + $label = $this->randomName(); $breakpoint = entity_create('breakpoint', array( - 'label' => drupal_strtolower($this->randomName()), + 'label' => $label, 'mediaQuery' => '(min-width: 600px)', + 'name' => drupal_strtolower($label), )); $breakpoint->save(); diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php index 7a563f6..52c2ef4 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php @@ -12,6 +12,7 @@ use Drupal\breakpoint\InvalidBreakpointNameException; use Drupal\breakpoint\InvalidBreakpointSourceException; use Drupal\breakpoint\InvalidBreakpointSourceTypeException; +use Drupal\Component\Utility\Unicode; /** * Tests for general breakpoint group API functions. diff --git a/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointConfigEntityUnitTest.php b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointConfigEntityUnitTest.php index 68ff25a..dc59e9c 100644 --- a/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointConfigEntityUnitTest.php +++ b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointConfigEntityUnitTest.php @@ -96,6 +96,7 @@ public function setUp() { */ public function testCalculateDependenciesModule() { $values = array( + 'name' => 'test', 'source' => 'test_module', 'sourceType' => Breakpoint::SOURCE_TYPE_MODULE, ); @@ -111,6 +112,7 @@ public function testCalculateDependenciesModule() { */ public function testCalculateDependenciesTheme() { $values = array( + 'name' => 'test', 'source' => 'test_theme', 'sourceType' => Breakpoint::SOURCE_TYPE_THEME, ); @@ -121,4 +123,15 @@ public function testCalculateDependenciesTheme() { $this->assertContains('test_theme', $dependencies['theme']); } + /** + * @expectedException \Drupal\breakpoint\InvalidBreakpointNameException + */ + public function testNameException () { + new Breakpoint(array( + 'label' => $this->randomName(), + 'source' => 'custom_module', + 'sourceType' => 'oops', + )); + } + } diff --git a/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointGroupConfigEntityUnitTest.php b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointGroupConfigEntityUnitTest.php index 6587e90..4b81a65 100644 --- a/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointGroupConfigEntityUnitTest.php +++ b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointGroupConfigEntityUnitTest.php @@ -8,6 +8,7 @@ namespace Drupal\breakpoint\Tests; use Drupal\breakpoint\Entity\Breakpoint; +use Drupal\breakpoint\Entity\BreakpointGroup; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Tests\UnitTestCase; @@ -109,6 +110,7 @@ public function setUpEntity($values) { public function testCalculateDependenciesModule() { $this->setUpEntity( array( + 'name' => 'test', 'source' => 'test_module', 'sourceType' => Breakpoint::SOURCE_TYPE_MODULE, ) @@ -134,6 +136,7 @@ public function testCalculateDependenciesModule() { public function testCalculateDependenciesTheme() { $this->setUpEntity( array( + 'name' => 'test', 'source' => 'test_theme', 'sourceType' => Breakpoint::SOURCE_TYPE_THEME, ) @@ -155,4 +158,15 @@ public function testCalculateDependenciesTheme() { $this->assertContains('breakpoint.breakpoint.test', $dependencies['entity']); } + /** + * @expectedException \Drupal\breakpoint\InvalidBreakpointNameException + */ + public function testNameException () { + new BreakpointGroup(array( + 'label' => $this->randomName(), + 'source' => 'custom_module', + 'sourceType' => 'oops', + )); + } + } diff --git a/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageAdminUITest.php b/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageAdminUITest.php index 41e152e..b752a16 100644 --- a/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageAdminUITest.php +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageAdminUITest.php @@ -16,6 +16,13 @@ class ResponsiveImageAdminUITest extends WebTestBase { /** + * The breakpoint group for testing. + * + * @var \Drupal\breakpoint\Entity\BreakpointGroupInterface + */ + protected $breakpointGroup; + + /** * Modules to enable. * * @var array @@ -47,8 +54,8 @@ public function setUp() { $this->drupalLogin($this->admin_user); // Add breakpoint_group and breakpoints. - $breakpoint_group = entity_create('breakpoint_group', array( - 'id' => 'atestset', + $this->breakpointGroup = entity_create('breakpoint_group', array( + 'name' => 'atestset', 'label' => 'A test set', 'sourceType' => Breakpoint::SOURCE_TYPE_USER_DEFINED, )); @@ -67,9 +74,9 @@ public function setUp() { ), )); $breakpoint->save(); - $breakpoint_group->addBreakpoints(array($breakpoint)); + $this->breakpointGroup->addBreakpoints(array($breakpoint)); } - $breakpoint_group->save(); + $this->breakpointGroup->save(); } @@ -83,13 +90,13 @@ public function testResponsiveImageAdmin() { // Add a new responsive image mapping, our breakpoint set should be selected. $this->drupalGet('admin/config/media/responsive-image-mapping/add'); - $this->assertFieldByName('breakpointGroup', 'atestset'); + $this->assertFieldByName('breakpointGroup', $this->breakpointGroup->id()); // Create a new group. $edit = array( 'label' => 'Mapping One', 'id' => 'mapping_one', - 'breakpointGroup' => 'atestset', + 'breakpointGroup' => $this->breakpointGroup->id(), ); $this->drupalPostForm('admin/config/media/responsive-image-mapping/add', $edit, t('Save')); @@ -103,7 +110,7 @@ public function testResponsiveImageAdmin() { // Edit the group. $this->drupalGet('admin/config/media/responsive-image-mapping/mapping_one'); $this->assertFieldByName('label', 'Mapping One'); - $this->assertFieldByName('breakpointGroup', 'atestset'); + $this->assertFieldByName('breakpointGroup', $this->breakpointGroup->id()); // Check if the dropdows are present for the mappings. $this->assertFieldByName('mappings[custom.user.small][1x]', ''); @@ -116,7 +123,7 @@ public function testResponsiveImageAdmin() { // Save mappings for 1x variant only. $edit = array( 'label' => 'Mapping One', - 'breakpointGroup' => 'atestset', + 'breakpointGroup' => $this->breakpointGroup->id(), 'mappings[custom.user.small][1x]' => 'thumbnail', 'mappings[custom.user.medium][1x]' => 'medium', 'mappings[custom.user.large][1x]' => 'large', diff --git a/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageFieldDisplayTest.php index e7e54a6..5d34845 100644 --- a/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageFieldDisplayTest.php @@ -60,7 +60,7 @@ public function setUp() { // Add breakpoint_group and breakpoints. $breakpoint_group = entity_create('breakpoint_group', array( - 'id' => 'atestset', + 'name' => 'atestset', 'label' => 'A test set', 'sourceType' => Breakpoint::SOURCE_TYPE_USER_DEFINED, )); @@ -87,7 +87,7 @@ public function setUp() { $responsive_image_mapping = entity_create('responsive_image_mapping', array( 'id' => 'mapping_one', 'label' => 'Mapping One', - 'breakpointGroup' => 'atestset', + 'breakpointGroup' => $breakpoint_group->id(), )); $responsive_image_mapping->save(); $mappings = array(); diff --git a/core/modules/responsive_image/tests/Drupal/responsive_image/Tests/ResponsiveImageMappingEntityTest.php b/core/modules/responsive_image/tests/Drupal/responsive_image/Tests/ResponsiveImageMappingEntityTest.php index 43ccb05..8565c3b 100644 --- a/core/modules/responsive_image/tests/Drupal/responsive_image/Tests/ResponsiveImageMappingEntityTest.php +++ b/core/modules/responsive_image/tests/Drupal/responsive_image/Tests/ResponsiveImageMappingEntityTest.php @@ -99,7 +99,7 @@ public function setUp() { $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); $this->breakpointGroupId = $this->randomName(9); - $this->breakpointGroup = $this->getMock('Drupal\breakpoint\Entity\BreakpointGroup', array(), array(array('id' => $this->breakpointGroupId))); + $this->breakpointGroup = $this->getMock('Drupal\breakpoint\Entity\BreakpointGroup', array(), array(array('name' => 'test', 'id' => $this->breakpointGroupId))); $this->breakpointGroupStorage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface'); $this->breakpointGroupStorage