Commit f715886f authored by webchick's avatar webchick

Issue #2245727 by alexpott | vijaycs85: Add missing configuration schema in Breakpoint component.

parent 1299c3af
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpProjectSharedConfiguration" php_language_level="5.5.0" />
</project>
......@@ -105,6 +105,20 @@ class Breakpoint extends ConfigEntityBase implements BreakpointInterface {
*/
public $multipliers = array();
/**
* {@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}
*/
......
......@@ -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);
}
......
......@@ -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',
));
......
......@@ -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();
......
......@@ -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.
......
......@@ -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',
));
}
}
......@@ -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',
));
}
}
......@@ -15,6 +15,13 @@
*/
class ResponsiveImageAdminUITest extends WebTestBase {
/**
* The breakpoint group for testing.
*
* @var \Drupal\breakpoint\Entity\BreakpointGroupInterface
*/
protected $breakpointGroup;
/**
* Modules to enable.
*
......@@ -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',
......
......@@ -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();
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment