X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffile%2Ftests%2Fsrc%2FUnit%2FPlugin%2Fmigrate%2Fcckfield%2Fd7%2FFileCckTest.php;fp=web%2Fcore%2Fmodules%2Ffile%2Ftests%2Fsrc%2FUnit%2FPlugin%2Fmigrate%2Fcckfield%2Fd7%2FFileCckTest.php;h=414d9c21d9f9fe6dd76d0dbb27f6b0f90724c80e;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/file/tests/src/Unit/Plugin/migrate/cckfield/d7/FileCckTest.php b/web/core/modules/file/tests/src/Unit/Plugin/migrate/cckfield/d7/FileCckTest.php new file mode 100644 index 000000000..414d9c21d --- /dev/null +++ b/web/core/modules/file/tests/src/Unit/Plugin/migrate/cckfield/d7/FileCckTest.php @@ -0,0 +1,87 @@ +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' => 'sub_process', + '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)); + } + +}