Commit 060fac27 authored by heddn's avatar heddn Committed by heddn

Issue #2818891 by heddn, Grimreaper: Fatal error: plugin csv not found

parent 1e90e303
<?php
/**
* @file
* Contains \Drupal\migrate_source_csv\CSVFileObject.php.
*/
namespace Drupal\migrate_source_csv;
......
<?php
/**
* @file
* Contains \Drupal\migrate_source_csv\Plugin\migrate\source\CSV.
*/
namespace Drupal\migrate_source_csv\Plugin\migrate\source;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
use Drupal\migrate_source_csv\CSVFileObject;
use Drupal\migrate\Plugin\MigrationInterface;
/**
* Source for CSV.
......@@ -70,11 +65,11 @@ class CSV extends SourcePluginBase {
throw new MigrateException('You must declare "keys" as a unique array of fields in your source settings.');
}
$this->fileClass = empty($configuration['file_class']) ? CSVFileObject::class : $configuration['file_class'];
$this->fileClass = empty($configuration['file_class']) ? 'Drupal\migrate_source_csv\CSVFileObject' : $configuration['file_class'];
}
/**
* Return a string representing the source query.
* Return a string representing the source file path.
*
* @return string
* The file path.
......
<?php
namespace Drupal\Tests\migrate_source_csv\Unit\Plugin\migrate\source;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\Plugin\MigratePluginManagerInterface;
/**
* @coversDefaultClass \Drupal\migrate_source_csv\Plugin\migrate\source\CSV
*
* @group migrate_source_csv
*/
class CSVTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['migrate', 'migrate_source_csv'];
/**
* Tests the construction of CSV.
*
* @covers ::__construct
*/
public function testCreate() {
/** @var MigratePluginManagerInterface $migrationSourceManager */
$migrationSourceManager = $this->container->get('plugin.manager.migrate.source');
$this->assertTrue($migrationSourceManager->hasDefinition('csv'));
}
}
<?php
/**
* @file
* Code for CSVFileObjectTest.php.
*/
namespace Drupal\Tests\migrate_source_csv\Unit;
......@@ -13,7 +9,7 @@ use Drupal\migrate_source_csv\CSVFileObject;
*
* @group migrate_source_csv
*/
class CSVFileObjectTest extends CSVUnitTestCase {
class CSVFileObjectTest extends CSVUnitBase {
/**
* The CSV file object.
......@@ -41,27 +37,16 @@ class CSVFileObjectTest extends CSVUnitTestCase {
$this->assertSame($flags, $this->csvFileObject->getFlags());
}
/**
* Tests that the header row count is correctly set.
*
* @covers ::setHeaderRowCount
*/
public function testSetHeaderRowCount() {
$expected = 2;
$this->csvFileObject->setHeaderRowCount($expected);
return $this->csvFileObject->getHeaderRowCount();
}
/**
* Tests that the header row count is correctly returned.
*
* @depends setHeaderRowCount
*
* @covers ::setHeaderRowCount
* @covers ::getHeaderRowCount
*/
public function testGetHeaderRowCount($actual) {
public function testGetHeaderRowCount() {
$expected = 2;
$this->csvFileObject->setHeaderRowCount($expected);
$actual = $this->csvFileObject->getHeaderRowCount();
$this->assertEquals($expected, $actual);
}
......
<?php
/**
* @file
* Code for CSVFileObjectTest.php.
*/
namespace Drupal\Tests\migrate_source_csv\Unit;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
/**
* Base unit test to build csv file contents.
* Base class for CSV unit tests.
*
* @group migrate_source_csv
*/
abstract class CSVUnitTestCase extends UnitTestCase {
abstract class CSVUnitBase extends UnitTestCase {
/**
* The happy path file url.
......@@ -84,5 +79,4 @@ EOD;
->url();
}
}
<?php
/**
* @file
* Code for CSVTest.php.
*/
namespace Drupal\Tests\migrate_source_csv\Unit\Plugin\migrate\source;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_source_csv\CSVFileObject;
use Drupal\migrate_source_csv\Plugin\migrate\source\CSV;
use Drupal\Tests\migrate_source_csv\Unit\CSVUnitTestCase;
use Drupal\Tests\migrate_source_csv\Unit\CSVUnitBase;
/**
* @coversDefaultClass \Drupal\migrate_source_csv\Plugin\migrate\source\CSV
*
* @group migrate_source_csv
*/
class CSVTest extends CSVUnitTestCase {
class CSVUnitTest extends CSVUnitBase {
/**
* The plugin id.
......@@ -35,11 +31,9 @@ class CSVTest extends CSVUnitTestCase {
/**
* The migration plugin.
*
* @topo Swap it out for a mock instance after https://www.drupal.org/node/2694009
*
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $plugin;
protected $migration;
/**
* {@inheritdoc}
......@@ -49,11 +43,11 @@ class CSVTest extends CSVUnitTestCase {
$this->pluginId = 'test csv migration';
$this->pluginDefinition = [];
$plugin = $this->prophesize(MigrationInterface::class);
$plugin->getIdMap()
$migration = $this->prophesize(MigrationInterface::class);
$migration->getIdMap()
->willReturn(NULL);
$this->plugin = $plugin->reveal();
$this->migration = $migration->reveal();
}
/**
......@@ -68,7 +62,7 @@ class CSVTest extends CSVUnitTestCase {
'header_row_count' => 1,
];
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration);
$this->assertInstanceOf(CSV::class, $csv);
}
......@@ -81,7 +75,7 @@ class CSVTest extends CSVUnitTestCase {
* @expectedExceptionMessage You must declare the "path" to the source CSV file in your source settings.
*/
public function testMigrateExceptionPathMissing() {
new CSV([], $this->pluginId, $this->pluginDefinition, $this->plugin);
new CSV([], $this->pluginId, $this->pluginDefinition, $this->migration);
}
/**
......@@ -96,7 +90,7 @@ class CSVTest extends CSVUnitTestCase {
'path' => $this->happyPath,
];
new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin);
new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration);
}
/**
......@@ -111,7 +105,7 @@ class CSVTest extends CSVUnitTestCase {
'header_row_count' => 1,
];
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration);
$this->assertEquals($configuration['path'], (string) $csv);
}
......@@ -136,17 +130,17 @@ class CSVTest extends CSVUnitTestCase {
$config_enclosure = ['enclosure' => '%'];
$config_escape = ['escape' => '`'];
$csv = new CSV($config_common + $config_delimiter, $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($config_common + $config_delimiter, $this->pluginId, $this->pluginDefinition, $this->migration);
$this->assertEquals(current($config_delimiter), $csv->initializeIterator()
->getCsvControl()[0]);
$this->assertEquals('"', $csv->initializeIterator()->getCsvControl()[1]);
$csv = new CSV($config_common + $config_enclosure, $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($config_common + $config_enclosure, $this->pluginId, $this->pluginDefinition, $this->migration);
$this->assertEquals(',', $csv->initializeIterator()->getCsvControl()[0]);
$this->assertEquals(current($config_enclosure), $csv->initializeIterator()
->getCsvControl()[1]);
$csv = new CSV($config_common + $config_delimiter + $config_enclosure + $config_escape, $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($config_common + $config_delimiter + $config_enclosure + $config_escape, $this->pluginId, $this->pluginDefinition, $this->migration);
$csv_file_object = $csv->initializeIterator();
$row = [
'1',
......@@ -160,7 +154,7 @@ class CSVTest extends CSVUnitTestCase {
$current = $csv_file_object->current();
$this->assertArrayEquals($row, $current);
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration);
$csv_file_object = $csv->initializeIterator();
$row = [
'id' => '1',
......@@ -192,7 +186,7 @@ class CSVTest extends CSVUnitTestCase {
2 => ['last_name' => 'User last name'],
],
];
$csv = new CSV($configuration + $column_names, $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($configuration + $column_names, $this->pluginId, $this->pluginDefinition, $this->migration);
$csv_file_object = $csv->initializeIterator();
$row = [
'id' => '1',
......@@ -223,7 +217,7 @@ class CSVTest extends CSVUnitTestCase {
'header_row_count' => 1,
];
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration);
$expected = ['id' => ['type' => 'string']];
$this->assertArrayEquals($expected, $csv->getIds());
......@@ -252,8 +246,7 @@ class CSVTest extends CSVUnitTestCase {
'ip_address' => 'ip_address',
];
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($configuration + ['fields' => $fields], $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($configuration + ['fields' => $fields], $this->pluginId, $this->pluginDefinition, $this->migration);
$this->assertArrayEquals($expected, $csv->fields());
$column_names = [
......@@ -263,7 +256,7 @@ class CSVTest extends CSVUnitTestCase {
$csv = new CSV($configuration + [
'fields' => $fields,
'column_names' => $column_names,
], $this->pluginId, $this->pluginDefinition, $this->plugin);
], $this->pluginId, $this->pluginDefinition, $this->migration);
$this->assertArrayEquals($fields, $csv->fields());
}
......@@ -280,7 +273,7 @@ class CSVTest extends CSVUnitTestCase {
'file_class' => FooCSVFileObject::class ,
];
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin);
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration);
$csv->initializeIterator();
$fileObject = $this->readAttribute($csv, 'file');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment