diff -u b/core/modules/file/tests/src/Unit/Plugin/migrate/source/d7/FileTest.php b/core/modules/file/tests/src/Unit/Plugin/migrate/source/d7/FileTest.php --- b/core/modules/file/tests/src/Unit/Plugin/migrate/source/d7/FileTest.php +++ b/core/modules/file/tests/src/Unit/Plugin/migrate/source/d7/FileTest.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\file\Unit\Plugin\migrate\source\d7; +use Drupal\migrate\Row; use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase; /** @@ -50,2 +51,38 @@ + protected function setProperty($property, $value) { + $reflector = (new \ReflectionClass($this->source))->getProperty($property); + $reflector->setAccessible(TRUE); + $reflector->setValue($this->source, $value); + } + + /** + * Tests that public file URIs are properly transformed by prepareRow(). + */ + public function testPublicUri() { + $this->setProperty('publicPath', 'sites/default/files'); + $row = new Row(['uri' => 'public://foo.png'], ['uri' => []]); + $this->source->prepareRow($row); + $this->assertEquals('sites/default/files/foo.png', $row->getSourceProperty('filepath')); + } + + /** + * Tests that private file URIs are properly transformed by prepareRow(). + */ + public function testPrivateUri() { + $this->setProperty('privatePath', '/path/to/private/files'); + $row = new Row(['uri' => 'private://baz.jpeg'], ['uri' => []]); + $this->source->prepareRow($row); + $this->assertEquals('/path/to/private/files/baz.jpeg', $row->getSourceProperty('filepath')); + } + + /** + * Tests that temporary file URIs are property transformed by prepareRow(). + */ + public function testTemporaryUri() { + $this->setProperty('temporaryPath', '/tmp'); + $row = new Row(['uri' => 'temporary://camelot/lancelot.gif'], ['uri' => []]); + $this->source->prepareRow($row); + $this->assertEquals('/tmp/camelot/lancelot.gif', $row->getSourceProperty('filepath')); + } + }