View source
<?php
namespace Drupal\Tests\commerce_migrate_csv_example\Kernel\Migrate;
use Drupal\Tests\commerce_migrate\Kernel\CsvTestBase;
use Drupal\file\Entity\File;
use Drupal\file\FileInterface;
class ImageTest extends CsvTestBase {
protected static $modules = [
'action',
'address',
'commerce',
'commerce_migrate_csv_example',
'commerce_price',
'commerce_store',
'entity',
'field',
'file',
'inline_entity_form',
'options',
'system',
'text',
'user',
'views',
];
protected $fixtures = [
__DIR__ . '/../../../fixtures/csv/example-products.csv',
];
protected function setUp() : void {
parent::setUp();
$this->fs = \Drupal::service('file_system');
$this
->installEntitySchema('user');
$this
->fileMigrationSetup(__DIR__ . '/../../../fixtures/images');
$this
->executeMigration('csv_example_image');
}
protected function assertEntity($id, $name, $uri, $mime, $size, $uid) {
$file = File::load($id);
$this
->assertTrue($file instanceof FileInterface);
$this
->assertSame($name, $file
->getFilename());
$this
->assertSame($uri, $file
->getFileUri());
$this
->assertTrue(file_exists($uri));
$this
->assertSame($mime, $file
->getMimeType());
$this
->assertSame($size, $file
->getSize());
$this
->assertTrue($file
->isPermanent());
$this
->assertSame($uid, $file
->getOwnerId());
}
public function testFileMigration() {
$this
->assertEntity(1, 'TherMaxx 3mm - Black - Mens - XS.jpeg', 'public://import/images/TherMaxx%203mm%20-%20Black%20-%20Mens%20-%20XS.jpeg', 'image/jpeg', '4789', '1');
$this
->assertEntity(2, 'image2.png', 'public://import/images/image2.png', 'image/png', '3974', '1');
$this
->assertEntity(3, 'Thumbnail 1.png', 'public://import/images/Thumbnail%201.png', 'image/png', '3974', '1');
$this
->assertEntity(6, 'TherMaxx 3mm - Black - Mens - Small.jpeg', 'public://import/images/TherMaxx%203mm%20-%20Black%20-%20Mens%20-%20Small.jpeg', 'image/jpeg', '4789', '1');
$this
->assertEntity(20, 'Aquaseal 8oz.jpeg', 'public://import/images/Aquaseal%208oz.jpeg', 'image/jpeg', '6131', '1');
$this
->assertEntity(21, 'Thumbnail 2.png', 'public://import/images/Thumbnail%202.png', 'image/png', '5424', '1');
$this
->assertEntity(22, 'Zip Care.jpeg', 'public://import/images/Zip%20Care.jpeg', 'image/jpeg', '4789', '1');
$this
->assertEntity(23, 'Thumbnail 3.png', 'public://import/images/Thumbnail%203.png', 'image/png', '3905', '1');
$this
->assertEntity(34, 'Hero 5 - Black.jpeg', 'public://import/images/Hero%205%20-%20Black.jpeg', 'image/jpeg', '4789', '1');
$this
->assertEntity(35, 'image3.png', 'public://import/images/image3.png', 'image/png', '3905', '1');
$this
->assertEntity(4, 'flying.jpeg', 'public://import/images/flying.jpeg', 'image/jpeg', '4789', '1');
$this
->assertEntity(5, 'rainbow.png', 'public://import/images/rainbow.png', 'image/png', '5424', '1');
}
}