X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmigrate%2Ftests%2Fsrc%2FUnit%2Fprocess%2FGetTest.php;h=df5f98ab8044f30ade79c357b8662c999bd6fe12;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=01ab2da74d2db11391940aa75164877400cd7ad7;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/migrate/tests/src/Unit/process/GetTest.php b/web/core/modules/migrate/tests/src/Unit/process/GetTest.php index 01ab2da74..df5f98ab8 100644 --- a/web/core/modules/migrate/tests/src/Unit/process/GetTest.php +++ b/web/core/modules/migrate/tests/src/Unit/process/GetTest.php @@ -1,13 +1,8 @@ plugin = new TestGet(); - parent::setUp(); - } - /** * Tests the Get plugin when source is a string. */ @@ -32,9 +19,9 @@ class GetTest extends MigrateProcessTestCase { ->method('getSourceProperty') ->with('test') ->will($this->returnValue('source_value')); - $this->plugin->setSource('test'); + $this->plugin = new Get(['source' => 'test'], '', []); $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame($value, 'source_value'); + $this->assertSame('source_value', $value); } /** @@ -45,12 +32,14 @@ class GetTest extends MigrateProcessTestCase { 'test1' => 'source_value1', 'test2' => 'source_value2', ]; - $this->plugin->setSource(['test1', 'test2']); + $this->plugin = new Get(['source' => ['test1', 'test2']], '', []); $this->row->expects($this->exactly(2)) ->method('getSourceProperty') - ->will($this->returnCallback(function ($argument) use ($map) { return $map[$argument]; } )); + ->will($this->returnCallback(function ($argument) use ($map) { + return $map[$argument]; + })); $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame($value, ['source_value1', 'source_value2']); + $this->assertSame(['source_value1', 'source_value2'], $value); } /** @@ -61,9 +50,9 @@ class GetTest extends MigrateProcessTestCase { ->method('getSourceProperty') ->with('@test') ->will($this->returnValue('source_value')); - $this->plugin->setSource('@@test'); + $this->plugin = new Get(['source' => '@@test'], '', []); $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame($value, 'source_value'); + $this->assertSame('source_value', $value); } /** @@ -76,44 +65,59 @@ class GetTest extends MigrateProcessTestCase { '@test3' => 'source_value3', 'test4' => 'source_value4', ]; - $this->plugin->setSource(['test1', '@@test2', '@@test3', 'test4']); + $this->plugin = new Get(['source' => ['test1', '@@test2', '@@test3', 'test4']], '', []); $this->row->expects($this->exactly(4)) ->method('getSourceProperty') - ->will($this->returnCallback(function ($argument) use ($map) { return $map[$argument]; } )); + ->will($this->returnCallback(function ($argument) use ($map) { + return $map[$argument]; + })); $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame($value, ['source_value1', 'source_value2', 'source_value3', 'source_value4']); + $this->assertSame(['source_value1', 'source_value2', 'source_value3', 'source_value4'], $value); } /** * Tests the Get plugin when source has integer values. + * + * @dataProvider integerValuesDataProvider */ - public function testIntegerValues() { - $this->row->expects($this->exactly(2)) + public function testIntegerValues($source, $expected_value) { + $this->row->expects($this->atMost(2)) ->method('getSourceProperty') ->willReturnOnConsecutiveCalls('val1', 'val2'); - $this->plugin->setSource([0 => 0, 1 => 'test']); + $this->plugin = new Get(['source' => $source], '', []); $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame([0 => 'val1', 1 => 'val2'], $return); - - $this->plugin->setSource([FALSE]); - $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame([NULL], $return); - - $this->plugin->setSource([NULL]); - $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame([NULL], $return); + $this->assertSame($expected_value, $return); } -} - -namespace Drupal\migrate\Plugin\migrate\process; - -class TestGet extends Get { - public function __construct() { + /** + * Provides data for the successful lookup test. + * + * @return array + */ + public function integerValuesDataProvider() { + return [ + [ + 'source' => [0 => 0, 1 => 'test'], + 'expected_value' => [0 => 'val1', 1 => 'val2'], + ], + [ + 'source' => [FALSE], + 'expected_value' => [NULL], + ], + [ + 'source' => [NULL], + 'expected_value' => [NULL], + ], + ]; } - public function setSource($source) { - $this->configuration['source'] = $source; + + /** + * Tests the Get plugin for syntax errors, e.g. "Invalid tag_line detected" by + * creating a prophecy of the class. + */ + public function testPluginSyntax() { + $this->assertNotNull($this->prophesize(Get::class)); } }