Commit eccef6a9 authored by heddn's avatar heddn Committed by heddn
Browse files

Issue #3009345 by MegaChriz, heddn, jamesdixon:...

Issue #3009345 by MegaChriz, heddn, jamesdixon: DataParserPluginBase::nextSource() fails when the $urls property holds no actual values
parent 92f54a94
......@@ -149,6 +149,10 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug
* TRUE if a valid source URL was opened
*/
protected function nextSource() {
if (empty($this->urls)) {
return FALSE;
}
while ($this->activeUrl === NULL || (count($this->urls) - 1) > $this->activeUrl) {
if (is_null($this->activeUrl)) {
$this->activeUrl = 0;
......
<?php
namespace Drupal\Tests\migrate_plus\Unit;
use Drupal\migrate_plus\DataParserPluginBase;
use Drupal\Tests\migrate\Unit\MigrateTestCase;
/**
* @coversDefaultClass \Drupal\migrate_plus\DataParserPluginBase
*
* @group migrate_plus
*/
class DataParserPluginBaseTest extends MigrateTestCase {
/**
* @covers ::nextSource
*/
public function testNextSourceWithOneUrl() {
$parser = $this->getMockedDataParser();
$parser->expects($this->once())
->method('openSourceUrl')
->willReturn(TRUE);
$this->assertTrue($parser->nextSource());
}
/**
* @covers ::nextSource
*/
public function testNextSourceWithoutUrls() {
$config = [
'urls' => [],
];
$parser = $this->getMockedDataParser($config);
$parser->expects($this->never())
->method('openSourceUrl');
$this->assertFalse($parser->nextSource());
}
/**
* @covers ::count
*/
public function testCountWithoutUrls() {
$config = [
'urls' => [],
];
$parser = $this->getMockedDataParser($config);
$parser->expects($this->never())
->method('openSourceUrl');
$this->assertEquals(0, $parser->count());
}
/**
* Returns a mocked data parser.
*
* @param array $configuration
* The configuration to pass to the data parser.
*
* @return \PHPUnit\Framework\MockObject\MockObject|\Drupal\Tests\migrate_plus\Unit\DataParserPluginBaseMock
* An mock instance of DataParserPluginBase.
*/
protected function getMockedDataParser(array $configuration = []) {
// Set constructor arguments.
$configuration += [
'urls' => ['http://example.org/data_parser_test'],
'item_selector' => 0,
];
$plugin_id = 'foo';
$plugin_definition = [
'id' => 'foo',
'title' => 'Foo',
];
return $this->getMockBuilder(DataParserPluginBaseMock::class)
->setConstructorArgs([$configuration, $plugin_id, $plugin_definition])
->setMethods(['openSourceUrl'])
->getMockForAbstractClass();
}
}
/**
* Mock for abstract class DataParserPluginBase.
*
* This mock is used to make certain methods publicly accessible.
*/
abstract class DataParserPluginBaseMock extends DataParserPluginBase {
/**
* {@inheritdoc}
*/
public function nextSource() {
return parent::nextSource();
}
}
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