Created
September 21, 2016 15:51
-
-
Save heddn/23de12a6446d61c8fbd56300137b1319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\Tests\file\Kernel\Migrate\d6; | |
use Drupal\Core\Cache\CacheBackendInterface; | |
use Drupal\Core\Extension\ModuleHandlerInterface; | |
use Drupal\file\Plugin\migrate\process\d6\CckFile; | |
use Drupal\migrate\Plugin\migrate\process\Migration; | |
use Drupal\migrate\Plugin\MigratePluginManager; | |
use Drupal\migrate\Plugin\MigrationInterface; | |
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; | |
/** | |
* Cck file field migration. | |
* | |
* @coversDefaultClass \Drupal\file\Plugin\migrate\process\d6\CckFile | |
* | |
* @group migrate_drupal_6 | |
*/ | |
class MigrateCckFileTest extends MigrateDrupal6TestBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function setUp() { | |
parent::setUp(); | |
$this->installEntitySchema('file'); | |
$this->installConfig(['file']); | |
} | |
/** | |
* Tests configurability of file migration name. | |
* | |
* @covers ::__construct | |
*/ | |
public function testConfigurableFileMigration() { | |
$migration = $this->prophesize(MigrationInterface::class)->reveal(); | |
$cache = $this->prophesize(CacheBackendInterface::class)->reveal(); | |
$moduleHandler = $this->prophesize(ModuleHandlerInterface::class)->reveal(); | |
$migrationPluginManager = new TestableMigratePluginManager('process', new \ArrayObject(), $cache, $moduleHandler); | |
$this->container->set('plugin.manager.migrate.process', $migrationPluginManager); | |
$testableMigration = TestableCckFile::create($this->container, ['migration' => 'custom_file'], 'custom_file', [], $migration); | |
$this->assertEquals('custom_file', $testableMigration->getMigrationPlugin()->getConfiguration()['migration']); | |
} | |
} | |
/** | |
* Class TestableMigration | |
* | |
* Provide a means to test the cck file migration. | |
*/ | |
class TestableCckFile extends CckFile { | |
/** | |
* Return the migration process plugin. | |
* | |
* @return array | |
* The migration process plugin. | |
*/ | |
public function getMigrationPlugin() { | |
return $this->migrationPlugin; | |
} | |
} | |
/** | |
* Class TestableMigration | |
* | |
* Provide a means to test the cck file migration. | |
*/ | |
class TestableMigration extends Migration { | |
/** | |
* Return the migration process plugin. | |
* | |
* @return array | |
* The configuration for the migration process plugin. | |
*/ | |
public function getConfiguration() { | |
return $this->configuration; | |
} | |
} | |
/** | |
* Class TestableMigratePluginManager | |
* | |
* Provides a means to provide a testable migration process plugin. | |
*/ | |
class TestableMigratePluginManager extends MigratePluginManager { | |
public function createInstance($pluginId, array $configuration = [], MigrationInterface $migration = NULL) { | |
return TestableMigration::create(\Drupal::getContainer(), $configuration, $pluginId, [], $migration); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment