Issue #2245727 by alexpott | vijaycs85: Add missing configuration schema in Breakpoint component.
parent
1299c3afcf
commit
f715886fe2
|
@ -0,0 +1,5 @@
|
|||
<?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\Entity\Breakpoint;
|
|||
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 @@ class BreakpointAPITest extends BreakpointTestBase {
|
|||
*/
|
||||
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 @@ class BreakpointCRUDTest extends BreakpointTestBase {
|
|||
*/
|
||||
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\Entity\Breakpoint;
|
|||
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 @@ class BreakpointConfigEntityUnitTest extends UnitTestCase {
|
|||
*/
|
||||
public function testCalculateDependenciesModule() {
|
||||
$values = array(
|
||||
'name' => 'test',
|
||||
'source' => 'test_module',
|
||||
'sourceType' => Breakpoint::SOURCE_TYPE_MODULE,
|
||||
);
|
||||
|
@ -111,6 +112,7 @@ class BreakpointConfigEntityUnitTest extends UnitTestCase {
|
|||
*/
|
||||
public function testCalculateDependenciesTheme() {
|
||||
$values = array(
|
||||
'name' => 'test',
|
||||
'source' => 'test_theme',
|
||||
'sourceType' => Breakpoint::SOURCE_TYPE_THEME,
|
||||
);
|
||||
|
@ -121,4 +123,15 @@ class BreakpointConfigEntityUnitTest extends UnitTestCase {
|
|||
$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 @@ class BreakpointGroupConfigEntityUnitTest extends UnitTestCase {
|
|||
public function testCalculateDependenciesModule() {
|
||||
$this->setUpEntity(
|
||||
array(
|
||||
'name' => 'test',
|
||||
'source' => 'test_module',
|
||||
'sourceType' => Breakpoint::SOURCE_TYPE_MODULE,
|
||||
)
|
||||
|
@ -134,6 +136,7 @@ class BreakpointGroupConfigEntityUnitTest extends UnitTestCase {
|
|||
public function testCalculateDependenciesTheme() {
|
||||
$this->setUpEntity(
|
||||
array(
|
||||
'name' => 'test',
|
||||
'source' => 'test_theme',
|
||||
'sourceType' => Breakpoint::SOURCE_TYPE_THEME,
|
||||
)
|
||||
|
@ -155,4 +158,15 @@ class BreakpointGroupConfigEntityUnitTest extends UnitTestCase {
|
|||
$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 @@ use Drupal\breakpoint\Entity\Breakpoint;
|
|||
*/
|
||||
class ResponsiveImageAdminUITest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* The breakpoint group for testing.
|
||||
*
|
||||
* @var \Drupal\breakpoint\Entity\BreakpointGroupInterface
|
||||
*/
|
||||
protected $breakpointGroup;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
|
@ -47,8 +54,8 @@ class ResponsiveImageAdminUITest extends WebTestBase {
|
|||
$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 @@ class ResponsiveImageAdminUITest extends WebTestBase {
|
|||
),
|
||||
));
|
||||
$breakpoint->save();
|
||||
$breakpoint_group->addBreakpoints(array($breakpoint));
|
||||
$this->breakpointGroup->addBreakpoints(array($breakpoint));
|
||||
}
|
||||
$breakpoint_group->save();
|
||||
$this->breakpointGroup->save();
|
||||
|
||||
}
|
||||
|
||||
|
@ -83,13 +90,13 @@ class ResponsiveImageAdminUITest extends WebTestBase {
|
|||
|
||||
// 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 @@ class ResponsiveImageAdminUITest extends WebTestBase {
|
|||
// 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 @@ class ResponsiveImageAdminUITest extends WebTestBase {
|
|||
// 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 @@ class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase {
|
|||
|
||||
// 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 @@ class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase {
|
|||
$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 @@ class ResponsiveImageMappingEntityTest extends UnitTestCase {
|
|||
$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
|
||||
|
|
Loading…
Reference in New Issue