upgrades core to 8.4.2
This commit is contained in:
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
@@ -8,8 +8,8 @@ dependencies:
|
||||
- file
|
||||
- views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
@@ -259,7 +259,7 @@ abstract class FileFieldTestBase extends BrowserTestBase {
|
||||
/**
|
||||
* Asserts that a file exists physically on disk.
|
||||
*
|
||||
* Overrides PHPUnit_Framework_Assert::assertFileExists() to also work with
|
||||
* Overrides PHPUnit\Framework\Assert::assertFileExists() to also work with
|
||||
* file entities.
|
||||
*
|
||||
* @param \Drupal\File\FileInterface|string $file
|
||||
@@ -286,7 +286,7 @@ abstract class FileFieldTestBase extends BrowserTestBase {
|
||||
/**
|
||||
* Asserts that a file does not exist on disk.
|
||||
*
|
||||
* Overrides PHPUnit_Framework_Assert::assertFileExists() to also work with
|
||||
* Overrides PHPUnit\Framework\Assert::assertFileExists() to also work with
|
||||
* file entities.
|
||||
*
|
||||
* @param \Drupal\File\FileInterface|string $file
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Functional\Update;
|
||||
|
||||
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests the upgrade path for setting the file usage deletion configuration.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2801777
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class FileUsageTemporaryDeletionConfigurationUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['file'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that make_unused_managed_files_temporary conditions are correct.
|
||||
*
|
||||
* Verify that the before and after conditions for the variable are correct.
|
||||
*/
|
||||
public function testUpdateHookN() {
|
||||
$this->assertIdentical($this->config('file.settings')->get('make_unused_managed_files_temporary'), NULL);
|
||||
$this->runUpdates();
|
||||
$this->assertIdentical($this->config('file.settings')->get('make_unused_managed_files_temporary'), FALSE);
|
||||
$this->assertResponse('200');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,11 @@ class DeleteTest extends FileManagedUnitTestBase {
|
||||
* Tries deleting a file that is in use.
|
||||
*/
|
||||
public function testInUse() {
|
||||
// This test expects unused managed files to be marked as a temporary file
|
||||
// and then deleted up by file_cron().
|
||||
$this->config('file.settings')
|
||||
->set('make_unused_managed_files_temporary', TRUE)
|
||||
->save();
|
||||
$file = $this->createFile();
|
||||
$file_usage = $this->container->get('file.usage');
|
||||
$file_usage->add($file, 'testing', 'test', 1);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Core\StreamWrapper\PublicStream;
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
|
||||
|
||||
/**
|
||||
* A trait to setup the file migration.
|
||||
*/
|
||||
trait FileMigrationSetupTrait {
|
||||
|
||||
/**
|
||||
* Prepare the file migration for running.
|
||||
*/
|
||||
protected function fileMigrationSetup() {
|
||||
$this->installSchema('file', ['file_usage']);
|
||||
$this->installEntitySchema('file');
|
||||
$this->container->get('stream_wrapper_manager')->registerWrapper('public', PublicStream::class, StreamWrapperInterface::NORMAL);
|
||||
|
||||
$fs = \Drupal::service('file_system');
|
||||
// The public file directory active during the test will serve as the
|
||||
// root of the fictional Drupal 7 site we're migrating.
|
||||
$fs->mkdir('public://sites/default/files', NULL, TRUE);
|
||||
file_put_contents('public://sites/default/files/cube.jpeg', str_repeat('*', 3620));
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\Migration $migration */
|
||||
$migration = $this->getMigration('d7_file');
|
||||
// Set the source plugin's source_base_path configuration value, which
|
||||
// would normally be set by the user running the migration.
|
||||
$source = $migration->getSourceConfiguration();
|
||||
$source['constants']['source_base_path'] = $fs->realpath('public://');
|
||||
$migration->set('source', $source);
|
||||
$this->executeMigration($migration);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\file\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\file\FileInterface;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
@@ -14,6 +13,8 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
*/
|
||||
class MigrateFileTest extends MigrateDrupal7TestBase {
|
||||
|
||||
use FileMigrationSetupTrait;
|
||||
|
||||
public static $modules = ['file'];
|
||||
|
||||
/**
|
||||
@@ -22,23 +23,7 @@ class MigrateFileTest extends MigrateDrupal7TestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('file');
|
||||
$this->container->get('stream_wrapper_manager')->registerWrapper('public', 'Drupal\Core\StreamWrapper\PublicStream', StreamWrapperInterface::NORMAL);
|
||||
|
||||
$fs = \Drupal::service('file_system');
|
||||
// The public file directory active during the test will serve as the
|
||||
// root of the fictional Drupal 7 site we're migrating.
|
||||
$fs->mkdir('public://sites/default/files', NULL, TRUE);
|
||||
file_put_contents('public://sites/default/files/cube.jpeg', str_repeat('*', 3620));
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\Migration $migration */
|
||||
$migration = $this->getMigration('d7_file');
|
||||
// Set the source plugin's source_base_path configuration value, which
|
||||
// would normally be set by the user running the migration.
|
||||
$source = $migration->getSourceConfiguration();
|
||||
$source['constants']['source_base_path'] = $fs->realpath('public://');
|
||||
$migration->set('source', $source);
|
||||
$this->executeMigration($migration);
|
||||
$this->fileMigrationSetup();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@ use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\process\d6\CckFile
|
||||
*
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class CckFileTest extends MigrateDrupalTestBase {
|
||||
|
||||
|
||||
@@ -81,6 +81,22 @@ class SaveTest extends FileManagedUnitTestBase {
|
||||
$this->assertEqual(1, count($fids));
|
||||
$this->assertEqual([$uppercase_file->id() => $uppercase_file->id()], $fids);
|
||||
|
||||
// Save a file with zero bytes.
|
||||
$file = File::create([
|
||||
'uid' => 1,
|
||||
'filename' => 'no-druplicon.txt',
|
||||
'uri' => 'public://no-druplicon.txt',
|
||||
'filemime' => 'text/plain',
|
||||
'status' => FILE_STATUS_PERMANENT,
|
||||
]);
|
||||
|
||||
file_put_contents($file->getFileUri(), '');
|
||||
|
||||
// Save it, inserting a new record.
|
||||
$file->save();
|
||||
|
||||
// Check the file size was set to zero.
|
||||
$this->assertSame(0, $file->getSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Kernel;
|
||||
|
||||
use Drupal\file\Entity\File;
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,11 +74,34 @@ class UsageTest extends FileManagedUnitTestBase {
|
||||
$this->assertEqual($usage[2]->count, 2, 'Correct count');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests file usage deletion when files are made temporary.
|
||||
*/
|
||||
public function testRemoveUsageTemporary() {
|
||||
$this->config('file.settings')
|
||||
->set('make_unused_managed_files_temporary', TRUE)
|
||||
->save();
|
||||
$file = $this->doTestRemoveUsage();
|
||||
$this->assertTrue($file->isTemporary());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests file usage deletion when files are made temporary.
|
||||
*/
|
||||
public function testRemoveUsageNonTemporary() {
|
||||
$this->config('file.settings')
|
||||
->set('make_unused_managed_files_temporary', FALSE)
|
||||
->save();
|
||||
$file = $this->doTestRemoveUsage();
|
||||
$this->assertFalse($file->isTemporary());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests \Drupal\file\FileUsage\DatabaseFileUsageBackend::delete().
|
||||
*/
|
||||
public function testRemoveUsage() {
|
||||
public function doTestRemoveUsage() {
|
||||
$file = $this->createFile();
|
||||
$file->setPermanent();
|
||||
$file_usage = $this->container->get('file.usage');
|
||||
db_insert('file_usage')
|
||||
->fields([
|
||||
@@ -116,6 +139,7 @@ class UsageTest extends FileManagedUnitTestBase {
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertIdentical(FALSE, $count, 'Decrementing non-exist record complete.');
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\file\Kernel;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the file_validate() function.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\cckfield\d6;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\file\Plugin\migrate\cckfield\d6\FileField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\cckfield\d6\FileField
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class FileCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new FileField([], 'file', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processFieldValues() method will call
|
||||
// mergeProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to mergeProcessOfProperty().
|
||||
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessCckFieldValues() {
|
||||
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'd6_cck_file',
|
||||
'source' => 'somefieldname',
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['image', 'imagefield_widget'],
|
||||
['file', 'filefield_widget'],
|
||||
['file', 'x_widget']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row();
|
||||
$row->setSourceProperty('widget_type', $widget_type);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\cckfield\d7;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\file\Plugin\migrate\cckfield\d7\FileField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\cckfield\d7\FileField
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class FileCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new FileField([], 'file', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processFieldValues() method will call
|
||||
// mergeProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to mergeProcessOfProperty().
|
||||
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessCckFieldValues() {
|
||||
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'iterator',
|
||||
'source' => 'somefieldname',
|
||||
'process' => [
|
||||
'target_id' => 'fid',
|
||||
'display' => 'display',
|
||||
'description' => 'description',
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['image', 'imagefield_widget'],
|
||||
['file', 'filefield_widget'],
|
||||
['file', 'x_widget']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row();
|
||||
$row->setSourceProperty('widget_type', $widget_type);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\cckfield\d7;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\file\Plugin\migrate\cckfield\d7\ImageField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\cckfield\d7\ImageField
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class ImageCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new ImageField([], 'image', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processFieldValues() method will call
|
||||
// mergeProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to mergeProcessOfProperty().
|
||||
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessCckFieldValues() {
|
||||
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'iterator',
|
||||
'source' => 'somefieldname',
|
||||
'process' => [
|
||||
'target_id' => 'fid',
|
||||
'alt' => 'alt',
|
||||
'title' => 'title',
|
||||
'width' => 'width',
|
||||
'height' => 'height',
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\field\d6;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\file\Plugin\migrate\field\d6\FileField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\field\d6\FileField
|
||||
* @group file
|
||||
*/
|
||||
class FileFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new FileField([], 'file', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processFieldValues() method will call
|
||||
// mergeProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to mergeProcessOfProperty().
|
||||
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processFieldValues
|
||||
*/
|
||||
public function testProcessFieldValues() {
|
||||
$this->plugin->processFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'd6_field_file',
|
||||
'source' => 'somefieldname',
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['image', 'imagefield_widget'],
|
||||
['file', 'filefield_widget'],
|
||||
['file', 'x_widget']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row();
|
||||
$row->setSourceProperty('widget_type', $widget_type);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\field\d7;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\file\Plugin\migrate\field\d7\FileField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\field\d7\FileField
|
||||
* @group file
|
||||
*/
|
||||
class FileFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new FileField([], 'file', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processFieldValues() method will call
|
||||
// mergeProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to mergeProcessOfProperty().
|
||||
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processFieldValues
|
||||
*/
|
||||
public function testProcessFieldValues() {
|
||||
$this->plugin->processFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'iterator',
|
||||
'source' => 'somefieldname',
|
||||
'process' => [
|
||||
'target_id' => 'fid',
|
||||
'display' => 'display',
|
||||
'description' => 'description',
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['image', 'imagefield_widget'],
|
||||
['file', 'filefield_widget'],
|
||||
['file', 'x_widget']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row();
|
||||
$row->setSourceProperty('widget_type', $widget_type);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\field\d7;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\file\Plugin\migrate\field\d7\ImageField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\field\d7\ImageField
|
||||
* @group file
|
||||
*/
|
||||
class ImageFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new ImageField([], 'image', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processFieldValues() method will call
|
||||
// mergeProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to mergeProcessOfProperty().
|
||||
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processFieldValues
|
||||
*/
|
||||
public function testProcessFieldValues() {
|
||||
$this->plugin->processFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'iterator',
|
||||
'source' => 'somefieldname',
|
||||
'process' => [
|
||||
'target_id' => 'fid',
|
||||
'alt' => 'alt',
|
||||
'title' => 'title',
|
||||
'width' => 'width',
|
||||
'height' => 'height',
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class CckFileTest extends UnitTestCase {
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\file\Plugin\migrate\process\d6\FieldFile;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Plugin\MigrateProcessInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @group file
|
||||
*/
|
||||
class FieldFileTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests that alt and title attributes are included in transformed values.
|
||||
*/
|
||||
public function testTransformAltTitle() {
|
||||
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
|
||||
$row = $this->prophesize(Row::class)->reveal();
|
||||
$migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
|
||||
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
|
||||
$migration_plugin->transform(1, $executable, $row, 'foo')->willReturn(1);
|
||||
|
||||
$plugin = new FieldFile([], 'd6_file', [], $migration, $migration_plugin->reveal());
|
||||
|
||||
$options = [
|
||||
'alt' => 'Foobaz',
|
||||
'title' => 'Wambooli',
|
||||
];
|
||||
$value = [
|
||||
'fid' => 1,
|
||||
'list' => TRUE,
|
||||
'data' => serialize($options),
|
||||
];
|
||||
|
||||
$transformed = $plugin->transform($value, $executable, $row, 'foo');
|
||||
$expected = [
|
||||
'target_id' => 1,
|
||||
'display' => TRUE,
|
||||
'description' => '',
|
||||
'alt' => 'Foobaz',
|
||||
'title' => 'Wambooli',
|
||||
];
|
||||
$this->assertSame($expected, $transformed);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user