View source
<?php
namespace Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait;
class FieldFormatterSettingsTest extends Commerce1TestBase {
use CommerceMigrateTestTrait;
public static $modules = [
'comment',
'commerce_order',
'commerce_price',
'commerce_product',
'commerce_store',
'datetime',
'field',
'file',
'image',
'link',
'menu_ui',
'migrate_plus',
'node',
'path',
'system',
'taxonomy',
'telephone',
'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 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']);
}
protected function assertComponentNotExists($display_id, $component_id) {
$component = EntityViewDisplay::load($display_id)
->getComponent($component_id);
$this
->assertTrue(is_null($component));
}
public function testMigration() {
$this
->assertEntity('comment.comment_node_ad_push.default');
$this
->assertEntity('comment.comment_node_bags_cases.default');
$this
->assertEntity('comment.comment_node_blog_post.default');
$this
->assertEntity('comment.comment_node_drinks.default');
$this
->assertEntity('comment.comment_node_hats.default');
$this
->assertEntity('comment.comment_node_page.default');
$this
->assertEntity('comment.comment_node_shoes.default');
$this
->assertEntity('comment.comment_node_slideshow.default');
$this
->assertEntity('comment.comment_node_storage_devices.default');
$this
->assertEntity('comment.comment_node_tops.default');
$this
->assertEntity('commerce_product.bags_cases.default');
$this
->assertComponent('commerce_product.bags_cases.default', 'body', 'text_default', 'hidden', 4);
$this
->assertComponent('commerce_product.bags_cases.default', 'variations', 'commerce_add_to_cart', 'above', 10);
$this
->assertEntity('commerce_product.drinks.default');
$this
->assertEntity('commerce_product.hats.default');
$this
->assertEntity('commerce_product.shoes.default');
$this
->assertEntity('commerce_product.storage_devices.default');
$this
->assertEntity('commerce_product.tops.default');
$this
->assertEntity('commerce_product_variation.bags_cases.default');
$this
->assertEntity('commerce_product_variation.drinks.default');
$this
->assertComponent('commerce_product_variation.drinks.default', 'field_images', 'image', 'above', 1);
$this
->assertComponent('commerce_product_variation.drinks.default', 'price', 'commerce_price_default', 'above', 0);
$this
->assertEntity('commerce_product_variation.hats.default');
$this
->assertEntity('commerce_product_variation.shoes.default');
$this
->assertEntity('commerce_product_variation.storage_devices.default');
$this
->assertEntity('commerce_product_variation.tops.default');
$this
->assertEntity('node.ad_push.default');
$this
->assertEntity('node.ad_push.teaser');
$this
->assertEntity('node.ad_push.default');
$this
->assertComponent('node.ad_push.default', 'field_image', 'image', 'hidden', -1);
$this
->assertComponent('node.ad_push.default', 'field_link', 'link', 'above', 2);
$this
->assertComponent('node.ad_push.default', 'field_tagline', 'string', 'above', 3);
$this
->assertEntity('node.ad_push.teaser');
$this
->assertEntity('node.bags_cases.default');
$this
->assertEntity('node.bags_cases.teaser');
$this
->assertEntity('node.blog_post.default');
$this
->assertComponent('node.blog_post.default', 'body', 'text_default', 'hidden', 1);
$this
->assertEntity('node.blog_post.teaser');
$this
->assertComponent('node.blog_post.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 1);
$this
->assertEntity('node.drinks.default');
$this
->assertEntity('node.drinks.teaser');
$this
->assertEntity('node.hats.default');
$this
->assertEntity('node.hats.teaser');
$this
->assertEntity('node.page.default');
$this
->assertComponent('node.page.default', 'body', 'text_default', 'hidden', 0);
$this
->assertEntity('node.page.teaser');
$this
->assertComponent('node.page.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
$this
->assertEntity('node.shoes.default');
$this
->assertEntity('node.shoes.teaser');
$this
->assertEntity('node.slideshow.default');
$this
->assertEntity('node.slideshow.teaser');
$this
->assertEntity('node.storage_devices.default');
$this
->assertEntity('node.storage_devices.teaser');
$this
->assertEntity('node.tops.default');
$this
->assertEntity('node.tops.teaser');
$this
->assertEntity('taxonomy_term.category.default');
$this
->assertEntity('taxonomy_term.collection.default');
$migration = $this
->getMigration('d7_field_formatter_settings');
$errors = $migration
->getIdMap()
->errorCount();
$this
->assertSame(0, $errors);
}
}