Commit 14c552f3 authored by webchick's avatar webchick

Issue #2549783 by lostkangaroo, phenaproxima: RequirementsException gives...

Issue #2549783 by lostkangaroo, phenaproxima: RequirementsException gives foreach error when single requirement present
parent 32a53442
......@@ -60,6 +60,10 @@ public function getRequirements() {
public function getRequirementsString() {
$output = '';
foreach ($this->requirements as $requirement_type => $requirements) {
if (!is_array($requirements)) {
$requirements = array($requirements);
}
foreach ($requirements as $value) {
$output .= "$requirement_type: $value. ";
}
......
<?php
/**
* @file
* Contains \Drupal\Tests\migrate\Unit\Exception\RequirementsExceptionTest.
*/
namespace Drupal\Tests\migrate\Unit\Exception;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\migrate\Exception\RequirementsException
* @group migration
*/
class RequirementsExceptionTest extends UnitTestCase {
protected $missingRequirements = ['random_jackson_pivot', '51_Eridani_b'];
/**
* @covers ::getRequirements
*/
public function testGetRequirements() {
$exception = new RequirementsException('Missing requirements ', ['requirements' => $this->missingRequirements]);
$this->assertArrayEquals(['requirements' => $this->missingRequirements], $exception->getRequirements());
}
/**
* @covers ::getRequirementsString
* @dataProvider getRequirementsProvider
*/
public function testGetExceptionString($expected, $message, $requirements) {
$exception = new RequirementsException($message, $requirements);
$this->assertEquals($expected, $exception->getRequirementsString());
}
/**
* Provides a list of requirements to test.
*/
public function getRequirementsProvider() {
return array(
array(
'requirements: random_jackson_pivot.',
'Single Requirement',
array('requirements' => $this->missingRequirements[0]),
),
array(
'requirements: random_jackson_pivot. requirements: 51_Eridani_b.',
'Multiple Requirements',
array('requirements' => $this->missingRequirements),
),
);
}
}
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