View source
<?php
namespace Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc7;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
class FieldFormatterSettingsTest extends Ubercart7TestBase {
public static $modules = [
'comment',
'commerce_price',
'commerce_product',
'commerce_store',
'file',
'image',
'migrate_plus',
'node',
'path',
'taxonomy',
'text',
];
protected function setUp() {
parent::setUp();
$this
->migrateFields();
$this
->executeMigrations([
'd7_view_modes',
'd7_field_formatter_settings',
]);
}
protected function assertEntity($id) {
$display = EntityViewDisplay::load($id);
$this
->assertInstanceOf(EntityViewDisplayInterface::class, $display);
}
protected function assertNotEntity($id) {
$display = EntityViewDisplay::load($id);
$this
->assertNull($display);
}
protected function assertComponent($display_id, $component_id, $type, $label, $weight) {
$component = EntityViewDisplay::load($display_id)
->getComponent($component_id);
$this
->assertTrue(is_array($component));
$this
->assertSame($type, $component['type']);
$this
->assertSame($label, $component['label']);
$this
->assertSame($weight, $component['weight']);
}
public function testEntityDisplaySettings() {
$this
->assertNotEntity('node.product.default');
$this
->assertNotEntity('commerce_product.page.default');
$this
->assertNotEntity('commerce_product.article.default');
$this
->assertEntity('node.article.default');
$this
->assertComponent('node.article.default', 'field_image', 'image', 'hidden', -1);
$this
->assertComponent('node.article.default', 'field_tags', 'entity_reference_label', 'above', 10);
$this
->assertEntity('commerce_product.default.default');
$this
->assertComponent('commerce_product.default.default', 'body', 'text_default', 'hidden', 0);
$this
->assertComponent('commerce_product.default.default', 'variations', 'commerce_add_to_cart', 'hidden', 1);
$this
->assertComponent('commerce_product.default.default', 'title', 'string', 'hidden', -5);
$this
->assertEntity('commerce_product.product.default');
$this
->assertComponent('commerce_product.product.default', 'body', 'text_default', 'hidden', 0);
$this
->assertComponent('commerce_product.product.default', 'variations', 'commerce_add_to_cart', 'above', 10);
$this
->assertComponent('commerce_product.product.default', 'field_number', 'number_integer', 'above', 3);
$this
->assertComponent('commerce_product.product.default', 'field_sustainability', 'string', 'above', 4);
$this
->assertComponent('commerce_product.product.default', 'taxonomy_catalog', 'entity_reference_label', 'above', 2);
$this
->assertComponent('commerce_product.product.default', 'uc_product_image', 'image', 'above', 1);
$this
->assertEntity('taxonomy_term.catalog.default');
$this
->assertComponent('taxonomy_term.catalog.default', 'uc_catalog_image', 'image', 'above', 0);
}
}