Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,11 @@
|
|||
# Schema for the configuration files of the Responsive image test theme module.
|
||||
field.formatter.settings.responsive_image_test:
|
||||
type: mapping
|
||||
label: 'Responsive image list format settings'
|
||||
mapping:
|
||||
responsive_image_style:
|
||||
type: string
|
||||
label: 'Responsive image style'
|
||||
image_link:
|
||||
type: string
|
||||
label: 'Link image to'
|
|
@ -0,0 +1,33 @@
|
|||
responsive_image_test_module.empty:
|
||||
label: empty
|
||||
mediaQuery: ''
|
||||
weight: 0
|
||||
multipliers:
|
||||
- 1x
|
||||
- 1.5x
|
||||
- 2x
|
||||
|
||||
responsive_image_test_module.mobile:
|
||||
label: mobile
|
||||
mediaQuery: '(min-width: 0px)'
|
||||
weight: 1
|
||||
multipliers:
|
||||
- 1x
|
||||
- 1.5x
|
||||
- 2x
|
||||
responsive_image_test_module.narrow:
|
||||
label: narrow
|
||||
mediaQuery: '(min-width: 560px)'
|
||||
weight: 2
|
||||
multipliers:
|
||||
- 1x
|
||||
- 1.5x
|
||||
- 2x
|
||||
responsive_image_test_module.wide:
|
||||
label: wide
|
||||
mediaQuery: '(min-width: 851px)'
|
||||
weight: 3
|
||||
multipliers:
|
||||
- 1x
|
||||
- 1.5x
|
||||
- 2x
|
|
@ -0,0 +1,7 @@
|
|||
name: 'Responsive image test theme'
|
||||
type: module
|
||||
description: 'Test theme for responsive image.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\responsive_image_test_module\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
|
||||
/**
|
||||
* Plugin to test responsive image formatter.
|
||||
*
|
||||
* @FieldFormatter(
|
||||
* id = "responsive_image_test",
|
||||
* label = @Translation("Responsive image test"),
|
||||
* field_types = {
|
||||
* "image",
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class ResponsiveImageTestFormatter extends ResponsiveImageFormatter {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$elements = parent::viewElements($items, $langcode);
|
||||
// Unset #item_attributes to test that the theme function can handle that.
|
||||
foreach ($elements as &$element) {
|
||||
if (isset($element['#item_attributes'])) {
|
||||
unset($element['#item_attributes']);
|
||||
}
|
||||
}
|
||||
return $elements;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\responsive_image\Kernel;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
|
||||
|
||||
/**
|
||||
* Tests the integration of responsive image with other components.
|
||||
*
|
||||
* @group responsive_image
|
||||
*/
|
||||
class ResponsiveImageIntegrationTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['responsive_image', 'field', 'image', 'file', 'entity_test', 'breakpoint', 'responsive_image_test_module'];
|
||||
|
||||
/**
|
||||
* Tests integration with entity view display.
|
||||
*/
|
||||
public function testEntityViewDisplayDependency() {
|
||||
// Create a responsive image style.
|
||||
ResponsiveImageStyle::create([
|
||||
'id' => 'foo',
|
||||
'label' => 'Foo',
|
||||
'breakpoint_group' => 'responsive_image_test_module',
|
||||
])->save();
|
||||
// Create an image field to be used with a responsive image formatter.
|
||||
FieldStorageConfig::create([
|
||||
'type' => 'image',
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'bar',
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
'field_name' => 'bar',
|
||||
])->save();
|
||||
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
|
||||
$display = EntityViewDisplay::create([
|
||||
'targetEntityType' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
'mode' => 'default',
|
||||
]);
|
||||
$display->setComponent('bar', [
|
||||
'type' => 'responsive_image',
|
||||
'label' => 'hidden',
|
||||
'settings' => ['responsive_image_style' => 'foo', 'image_link' => ''],
|
||||
'third_party_settings' => [],
|
||||
])->save();
|
||||
|
||||
// Check that the 'foo' field is on the display.
|
||||
$this->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
|
||||
$this->assertTrue($display->getComponent('bar'));
|
||||
$this->assertArrayNotHasKey('bar', $display->get('hidden'));
|
||||
|
||||
// Delete the responsive image style.
|
||||
ResponsiveImageStyle::load('foo')->delete();
|
||||
|
||||
// Check that the view display was not deleted.
|
||||
$this->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
|
||||
// Check that the 'foo' field was disabled.
|
||||
$this->assertNull($display->getComponent('bar'));
|
||||
$this->assertArrayHasKey('bar', $display->get('hidden'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,393 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\responsive_image\Unit;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\responsive_image\Entity\ResponsiveImageStyle
|
||||
* @group block
|
||||
*/
|
||||
class ResponsiveImageStyleConfigEntityUnitTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* 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 breakpoint manager used for testing.
|
||||
*
|
||||
* @var \Drupal\breakpoint\BreakpointManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $breakpointManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
$this->entityType->expects($this->any())
|
||||
->method('getProvider')
|
||||
->will($this->returnValue('responsive_image'));
|
||||
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with('responsive_image_style')
|
||||
->will($this->returnValue($this->entityType));
|
||||
|
||||
$this->breakpointManager = $this->getMock('\Drupal\breakpoint\BreakpointManagerInterface');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('breakpoint.manager', $this->breakpointManager);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::calculateDependencies
|
||||
*/
|
||||
public function testCalculateDependencies() {
|
||||
// Set up image style loading mock.
|
||||
$styles = [];
|
||||
foreach (['fallback', 'small', 'medium', 'large'] as $style) {
|
||||
$mock = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
|
||||
$mock->expects($this->any())
|
||||
->method('getConfigDependencyName')
|
||||
->willReturn('image.style.' . $style);
|
||||
$styles[$style] = $mock;
|
||||
}
|
||||
$storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface');
|
||||
$storage->expects($this->any())
|
||||
->method('loadMultiple')
|
||||
->with(array_keys($styles))
|
||||
->willReturn($styles);
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with('image_style')
|
||||
->willReturn($storage);
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getEntityTypeFromClass')
|
||||
->with('Drupal\image\Entity\ImageStyle')
|
||||
->willReturn('image_style');
|
||||
|
||||
$entity = new ResponsiveImageStyle(['breakpoint_group' => 'test_group']);
|
||||
$entity->setBreakpointGroup('test_group');
|
||||
$entity->setFallbackImageStyle('fallback');
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', ['image_mapping_type' => 'image_style', 'image_mapping' => 'small']);
|
||||
$entity->addImageStyleMapping('test_breakpoint', '2x', [
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => [
|
||||
'sizes' => '(min-width:700px) 700px, 100vw',
|
||||
'sizes_image_styles' => [
|
||||
'medium' => 'medium',
|
||||
'large' => 'large',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->breakpointManager->expects($this->any())
|
||||
->method('getGroupProviders')
|
||||
->with('test_group')
|
||||
->willReturn(array('bartik' => 'theme', 'toolbar' => 'module'));
|
||||
|
||||
$dependencies = $entity->calculateDependencies()->getDependencies();
|
||||
$this->assertEquals(['toolbar'], $dependencies['module']);
|
||||
$this->assertEquals(['bartik'], $dependencies['theme']);
|
||||
$this->assertEquals(['image.style.fallback', 'image.style.large', 'image.style.medium', 'image.style.small'], $dependencies['config']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::addImageStyleMapping
|
||||
* @covers ::hasImageStyleMappings
|
||||
*/
|
||||
public function testHasImageStyleMappings() {
|
||||
$entity = new ResponsiveImageStyle(array());
|
||||
$this->assertFalse($entity->hasImageStyleMappings());
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => '',
|
||||
));
|
||||
$this->assertFalse($entity->hasImageStyleMappings());
|
||||
$entity->removeImageStyleMappings();
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', array(
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => array(
|
||||
'sizes' => '(min-width:700px) 700px, 100vw',
|
||||
'sizes_image_styles' => array(),
|
||||
),
|
||||
));
|
||||
$this->assertFalse($entity->hasImageStyleMappings());
|
||||
$entity->removeImageStyleMappings();
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', array(
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => array(
|
||||
'sizes' => '',
|
||||
'sizes_image_styles' => array(
|
||||
'large' => 'large',
|
||||
),
|
||||
),
|
||||
));
|
||||
$this->assertFalse($entity->hasImageStyleMappings());
|
||||
$entity->removeImageStyleMappings();
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
));
|
||||
$this->assertTrue($entity->hasImageStyleMappings());
|
||||
$entity->removeImageStyleMappings();
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', array(
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => array(
|
||||
'sizes' => '(min-width:700px) 700px, 100vw',
|
||||
'sizes_image_styles' => array(
|
||||
'large' => 'large',
|
||||
),
|
||||
),
|
||||
));
|
||||
$this->assertTrue($entity->hasImageStyleMappings());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::addImageStyleMapping
|
||||
* @covers ::getImageStyleMapping
|
||||
*/
|
||||
public function testGetImageStyleMapping() {
|
||||
$entity = new ResponsiveImageStyle(array(''));
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
));
|
||||
$expected = array(
|
||||
'breakpoint_id' => 'test_breakpoint',
|
||||
'multiplier' => '1x',
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
);
|
||||
$this->assertEquals($expected, $entity->getImageStyleMapping('test_breakpoint', '1x'));
|
||||
$this->assertNull($entity->getImageStyleMapping('test_unknown_breakpoint', '1x'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::addImageStyleMapping
|
||||
* @covers ::getKeyedImageStyleMappings
|
||||
*/
|
||||
public function testGetKeyedImageStyleMappings() {
|
||||
$entity = new ResponsiveImageStyle(array(''));
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
));
|
||||
$entity->addImageStyleMapping('test_breakpoint', '2x', array(
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => array(
|
||||
'sizes' => '(min-width:700px) 700px, 100vw',
|
||||
'sizes_image_styles' => array(
|
||||
'large' => 'large',
|
||||
),
|
||||
),
|
||||
));
|
||||
$entity->addImageStyleMapping('test_breakpoint2', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'thumbnail',
|
||||
));
|
||||
$entity->addImageStyleMapping('test_breakpoint2', '2x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => '_original image_',
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
'test_breakpoint' => array(
|
||||
'1x' => array(
|
||||
'breakpoint_id' => 'test_breakpoint',
|
||||
'multiplier' => '1x',
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
),
|
||||
'2x' => array(
|
||||
'breakpoint_id' => 'test_breakpoint',
|
||||
'multiplier' => '2x',
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => array(
|
||||
'sizes' => '(min-width:700px) 700px, 100vw',
|
||||
'sizes_image_styles' => array(
|
||||
'large' => 'large',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'test_breakpoint2' => array(
|
||||
'1x' => array(
|
||||
'breakpoint_id' => 'test_breakpoint2',
|
||||
'multiplier' => '1x',
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'thumbnail',
|
||||
),
|
||||
'2x' => array(
|
||||
'breakpoint_id' => 'test_breakpoint2',
|
||||
'multiplier' => '2x',
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => '_original image_',
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $entity->getKeyedImageStyleMappings());
|
||||
|
||||
// Add another mapping to ensure keyed mapping static cache is rebuilt.
|
||||
$entity->addImageStyleMapping('test_breakpoint2', '2x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'medium',
|
||||
));
|
||||
$expected['test_breakpoint2']['2x'] = array(
|
||||
'breakpoint_id' => 'test_breakpoint2',
|
||||
'multiplier' => '2x',
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'medium',
|
||||
);
|
||||
$this->assertEquals($expected, $entity->getKeyedImageStyleMappings());
|
||||
|
||||
// Overwrite a mapping to ensure keyed mapping static cache is rebuilt.
|
||||
$entity->addImageStyleMapping('test_breakpoint2', '2x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
));
|
||||
$expected['test_breakpoint2']['2x'] = array(
|
||||
'breakpoint_id' => 'test_breakpoint2',
|
||||
'multiplier' => '2x',
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
);
|
||||
$this->assertEquals($expected, $entity->getKeyedImageStyleMappings());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::addImageStyleMapping
|
||||
* @covers ::getImageStyleMappings
|
||||
*/
|
||||
public function testGetImageStyleMappings() {
|
||||
$entity = new ResponsiveImageStyle(array(''));
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
));
|
||||
$entity->addImageStyleMapping('test_breakpoint', '2x', array(
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => array(
|
||||
'sizes' => '(min-width:700px) 700px, 100vw',
|
||||
'sizes_image_styles' => array(
|
||||
'large' => 'large',
|
||||
),
|
||||
),
|
||||
));
|
||||
$entity->addImageStyleMapping('test_breakpoint2', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'thumbnail',
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'breakpoint_id' => 'test_breakpoint',
|
||||
'multiplier' => '1x',
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
),
|
||||
array(
|
||||
'breakpoint_id' => 'test_breakpoint',
|
||||
'multiplier' => '2x',
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => array(
|
||||
'sizes' => '(min-width:700px) 700px, 100vw',
|
||||
'sizes_image_styles' => array(
|
||||
'large' => 'large',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'breakpoint_id' => 'test_breakpoint2',
|
||||
'multiplier' => '1x',
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'thumbnail',
|
||||
),
|
||||
);
|
||||
$this->assertEquals($expected, $entity->getImageStyleMappings());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::addImageStyleMapping
|
||||
* @covers ::removeImageStyleMappings
|
||||
*/
|
||||
public function testRemoveImageStyleMappings() {
|
||||
$entity = new ResponsiveImageStyle(array(''));
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
));
|
||||
$entity->addImageStyleMapping('test_breakpoint', '2x', array(
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => array(
|
||||
'sizes' => '(min-width:700px) 700px, 100vw',
|
||||
'sizes_image_styles' => array(
|
||||
'large' => 'large',
|
||||
),
|
||||
),
|
||||
));
|
||||
$entity->addImageStyleMapping('test_breakpoint2', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'thumbnail',
|
||||
));
|
||||
|
||||
$this->assertTrue($entity->hasImageStyleMappings());
|
||||
$entity->removeImageStyleMappings();
|
||||
$this->assertEmpty($entity->getImageStyleMappings());
|
||||
$this->assertEmpty($entity->getKeyedImageStyleMappings());
|
||||
$this->assertFalse($entity->hasImageStyleMappings());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setBreakpointGroup
|
||||
* @covers ::getBreakpointGroup
|
||||
*/
|
||||
public function testSetBreakpointGroup() {
|
||||
$entity = new ResponsiveImageStyle(array('breakpoint_group' => 'test_group'));
|
||||
$entity->addImageStyleMapping('test_breakpoint', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'large',
|
||||
));
|
||||
$entity->addImageStyleMapping('test_breakpoint', '2x', array(
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => array(
|
||||
'sizes' => '(min-width:700px) 700px, 100vw',
|
||||
'sizes_image_styles' => array(
|
||||
'large' => 'large',
|
||||
),
|
||||
),
|
||||
));
|
||||
$entity->addImageStyleMapping('test_breakpoint2', '1x', array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => 'thumbnail',
|
||||
));
|
||||
|
||||
// Ensure that setting to same group does not remove mappings.
|
||||
$entity->setBreakpointGroup('test_group');
|
||||
$this->assertTrue($entity->hasImageStyleMappings());
|
||||
$this->assertEquals('test_group', $entity->getBreakpointGroup());
|
||||
|
||||
// Ensure that changing the group removes mappings.
|
||||
$entity->setBreakpointGroup('test_group2');
|
||||
$this->assertEquals('test_group2', $entity->getBreakpointGroup());
|
||||
$this->assertFalse($entity->hasImageStyleMappings());
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue