abstract class MigrateSqlSourceTestCase in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php \Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase
Base class for Migrate module source unit tests.
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of MigrateSqlSourceTestCase
65 files declare their use of MigrateSqlSourceTestCase
- ActionTest.php in core/
modules/ action/ tests/ src/ Unit/ Plugin/ migrate/ source/ d6/ ActionTest.php - Contains \Drupal\Tests\action\Unit\Plugin\migrate\source\d6\ActionTest.
- AggregatorFeedTest.php in core/
modules/ aggregator/ tests/ src/ Unit/ Plugin/ migrate/ source/ d6/ AggregatorFeedTest.php - Contains \Drupal\Tests\aggregator\Unit\Plugin\migrate\source\d6\AggregatorFeedTest.
- AggregatorFeedTest.php in core/
modules/ aggregator/ tests/ src/ Unit/ Plugin/ migrate/ source/ d7/ AggregatorFeedTest.php - Contains \Drupal\Tests\aggregator\Unit\Plugin\migrate\source\d7\AggregatorFeedTest.
- AggregatorItemTest.php in core/
modules/ aggregator/ tests/ src/ Unit/ Plugin/ migrate/ source/ AggregatorItemTest.php - Contains \Drupal\Tests\aggregator\Unit\Plugin\migrate\source\AggregatorItemTest.
- BlockCustomTest.php in core/
modules/ block_content/ tests/ src/ Unit/ Plugin/ migrate/ source/ d7/ BlockCustomTest.php - Contains \Drupal\Tests\block_content\Unit\Plugin\migrate\source\d7\BlockCustomTest.
File
- core/
modules/ migrate/ tests/ src/ Unit/ MigrateSqlSourceTestCase.php, line 15 - Contains \Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase.
Namespace
Drupal\Tests\migrate\UnitView source
abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
/**
* The tested source plugin.
*
* @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase.
*/
protected $source;
/**
* The database contents.
*
* Database contents represents a mocked database. It should contain an
* associative array with the table name as key, and as many nested arrays as
* the number of mocked rows. Each of those faked rows must be another array
* with the column name as the key and the value as the cell.
*
* @var array
*/
protected $databaseContents = array();
/**
* The plugin class under test.
*
* The plugin system is not working during unit testing so the source plugin
* class needs to be manually specified.
*
* @var string
*/
const PLUGIN_CLASS = '';
/**
* The high water mark at the beginning of the import operation.
*
* Once the migration is run, we save a mark of the migrated sources, so the
* migration can run again and update only new sources or changed sources.
*
* @var string
*/
const ORIGINAL_HIGH_WATER = '';
/**
* Expected results after the source parsing.
*
* @var array
*/
protected $expectedResults = array();
/**
* Expected count of source rows.
*
* @var int
*/
protected $expectedCount = 0;
/**
* The source plugin instance under test.
*
* @var \Drupal\migrate\Plugin\MigrateSourceInterface
*/
protected $plugin;
/**
* {@inheritdoc}
*/
protected function setUp() {
$module_handler = $this
->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$state = $this
->getMock('Drupal\\Core\\State\\StateInterface');
$entity_manager = $this
->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$migration = $this
->getMigration();
$migration
->expects($this
->any())
->method('getHighWater')
->will($this
->returnValue(static::ORIGINAL_HIGH_WATER));
// Setup the plugin.
$plugin_class = static::PLUGIN_CLASS;
$plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $migration, $state, $entity_manager);
// Do some reflection to set the database and moduleHandler.
$plugin_reflection = new \ReflectionClass($plugin);
$database_property = $plugin_reflection
->getProperty('database');
$database_property
->setAccessible(TRUE);
$module_handler_property = $plugin_reflection
->getProperty('moduleHandler');
$module_handler_property
->setAccessible(TRUE);
// Set the database and the module handler onto our plugin.
$database_property
->setValue($plugin, $this
->getDatabase($this->databaseContents + array(
'test_map' => array(),
)));
$module_handler_property
->setValue($plugin, $module_handler);
$plugin
->setStringTranslation($this
->getStringTranslationStub());
$migration
->expects($this
->any())
->method('getSourcePlugin')
->will($this
->returnValue($plugin));
$this->source = $plugin;
$this->expectedCount = count($this->expectedResults);
}
/**
* Test the source returns the same rows as expected.
*/
public function testRetrieval() {
$this
->assertInstanceOf(SelectInterface::class, $this->source
->query());
$this
->queryResultTest($this->source, $this->expectedResults);
}
/**
* Test the source returns the row count expected.
*/
public function testSourceCount() {
$count = $this->source
->count();
$this
->assertTrue(is_numeric($count));
$this
->assertEquals($count, $this->expectedCount);
}
/**
* Test the source defines a valid ID.
*/
public function testSourceId() {
$this
->assertNotEmpty($this->source
->getIds());
}
/**
* @param \Drupal\migrate\Row $row
* @param string $key
* @return mixed
*/
protected function getValue($row, $key) {
return $row
->getSourceProperty($key);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateSqlSourceTestCase:: |
protected | property | The database contents. | 5 |
MigrateSqlSourceTestCase:: |
protected | property | Expected count of source rows. | |
MigrateSqlSourceTestCase:: |
protected | property | Expected results after the source parsing. | 66 |
MigrateSqlSourceTestCase:: |
protected | property | The source plugin instance under test. | |
MigrateSqlSourceTestCase:: |
protected | property | The tested source plugin. | |
MigrateSqlSourceTestCase:: |
protected | function |
Overrides MigrateTestCase:: |
|
MigrateSqlSourceTestCase:: |
constant | The high water mark at the beginning of the import operation. | 1 | |
MigrateSqlSourceTestCase:: |
constant | The plugin class under test. | 66 | |
MigrateSqlSourceTestCase:: |
protected | function |
Overrides UnitTestCase:: |
61 |
MigrateSqlSourceTestCase:: |
public | function | Test the source returns the same rows as expected. | |
MigrateSqlSourceTestCase:: |
public | function | Test the source returns the row count expected. | |
MigrateSqlSourceTestCase:: |
public | function | Test the source defines a valid ID. | |
MigrateTestCase:: |
protected | property | ||
MigrateTestCase:: |
protected | property | 74 | |
MigrateTestCase:: |
protected | property | Local store for mocking setStatus()/getStatus(). | |
MigrateTestCase:: |
protected | function | Generates a table schema from a row. | |
MigrateTestCase:: |
protected | function | Get an SQLite database connection object for use in tests. | |
MigrateTestCase:: |
protected | function | Retrieve a mocked migration. | |
MigrateTestCase:: |
public | function | Tests a query | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |