class TestWrapperTarget in Feeds Paragraphs 8
@group Feeds Paragraphs @coversDefaultClass \Drupal\feeds_para_mapper\Feeds\Target\WrapperTarget
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\feeds_para_mapper\Unit\FpmTestBase
- class \Drupal\Tests\feeds_para_mapper\Unit\TestWrapperTarget uses Common
- class \Drupal\Tests\feeds_para_mapper\Unit\FpmTestBase
Expanded class hierarchy of TestWrapperTarget
File
- tests/
src/ Unit/ TestWrapperTarget.php, line 13
Namespace
Drupal\Tests\feeds_para_mapper\UnitView source
class TestWrapperTarget extends FpmTestBase {
use Common;
/**
* @var string
*/
protected $class;
/**
* @var string
*/
protected $type;
protected function setUp() {
$this->class = Text::class;
$this->type = "text";
$this
->getInstanceMock();
parent::setUp();
$this
->addServices($this->services);
}
/**
* Mocks a form state object.
* @return FormStateInterface
* The form state.
*/
public function getFormStateMock() {
$formState = $this
->createMock(FormStateInterface::class);
$formState
->expects($this
->any())
->method('getTriggeringElement')
->willReturn(array(
'#delta' => 0,
));
$formState
->expects($this
->any())
->method('getValue')
->willReturn(array(
'format' => 'test format',
));
return $formState;
}
/**
*
* @covers ::createTargetInstance
*/
public function testCreateTargetInstance() {
$instance = $this->wrapperTarget
->createTargetInstance();
$this
->assertTrue($instance instanceof Text);
}
/**
*
* @covers ::prepareTarget
*/
public function testPrepareTarget() {
$method = $this
->getMethod(Text::class, 'prepareTarget')
->getClosure();
$field = $this->fieldHelper
->getBundleFields('bundle_two')[0]
->reveal();
$info = $this
->getTargetInfo();
$field
->set('target_info', $info);
$textDef = $method($field);
$textPCount = count($textDef
->getProperties());
$method = $this
->getMethod(WrapperTarget::class, 'prepareTarget')
->getClosure();
$wrapperDef = $method($field);
$wrapperPCount = count($wrapperDef
->getProperties());
$this
->assertSame($textPCount, $wrapperPCount, 'The wrapper has the target properties');
}
/**
*
* @covers ::defaultConfiguration
*/
public function testDefaultConfiguration() {
$textDefaultConfig = $this->target
->defaultConfiguration();
$wrapperDefaultConfig = $this->wrapperTarget
->defaultConfiguration();
$message = "Wrapper has the target's default configuration: ";
foreach ($textDefaultConfig as $key => $configItem) {
$this
->assertArrayHasKey($key, $wrapperDefaultConfig, $message . $key);
}
$this
->assertArrayHasKey('max_values', $wrapperDefaultConfig, $message . 'max_values');
}
/**
*
* @covers ::buildConfigurationForm
*/
public function testBuildConfigurationForm() {
$formState = $this
->getFormStateMock();
$textForm = $this->target
->buildConfigurationForm(array(), $formState);
$wrapperForm = $this->wrapperTarget
->buildConfigurationForm(array(), $formState);
$message = "Wrapper has the target's form element: ";
foreach ($textForm as $field => $formMarkup) {
$this
->assertArrayHasKey($field, $wrapperForm, $message . $field);
}
$this
->assertArrayHasKey('max_values', $wrapperForm, $message . 'max_values');
}
/**
* @covers ::getSummary
*/
public function testGetSummary() {
$res = $this->wrapperTarget
->getSummary();
$res = $res
->getUntranslatedString();
$expected = "test summary<br>Maximum values: -1";
$this
->assertSame($res, $expected, "The target summary exists");
}
/**
* @covers \Drupal\feeds_para_mapper\Feeds\Target\WrapperTarget::targets
*/
public function testTargets() {
$targets = array();
$this->wrapperTarget
->targets($targets, $this->feedType, array());
$this
->assertTrue(isset($targets['bundle_two_text']), 'Target added');
$field_type = $targets['bundle_two_text']
->getFieldDefinition()->field_type;
$this
->assertSame('entity_reference_revisions', $field_type, 'target field type is changed');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Common:: |
function | Returns the target class. | ||
Common:: |
public | function | @inheritdoc | |
Common:: |
public | function | @inheritdoc | |
Common:: |
function | Returns the target type. | ||
FpmTestBase:: |
protected | property | The entity helper instance. | |
FpmTestBase:: |
protected | property | The mocked feed type instance. | |
FpmTestBase:: |
protected | property | The field helper instance. | |
FpmTestBase:: |
protected | property | The mocked paragraphs and node fields. | |
FpmTestBase:: |
protected | property | The target mock | |
FpmTestBase:: |
protected | property | The messenger mock | |
FpmTestBase:: |
protected | property | The mocked node. | |
FpmTestBase:: |
protected | property | The services to mock. | |
FpmTestBase:: |
protected | property | The target object. | |
FpmTestBase:: |
protected | property | The wrapper instance. | |
FpmTestBase:: |
protected | function | Adds services to the container. | |
FpmTestBase:: |
protected | function | Generates plugin definitions array (text plugin for now). | |
FpmTestBase:: |
protected | function | Returns a mocked feed entity. | |
FpmTestBase:: |
protected | function | Creates feed type entity. | |
FpmTestBase:: |
protected | function | Generates a mapper object. | |
FpmTestBase:: |
private | function | Mocks the messenger service. | |
FpmTestBase:: |
protected | function | Calls a protected method on an object. | |
FpmTestBase:: |
private | function | Creates FeedsPluginManager instance. | |
FpmTestBase:: |
private | function | Mocks an entity processor instance. | |
FpmTestBase:: |
protected | function | Returns a protected, private property of an object. | |
FpmTestBase:: |
private | function | Instantiates and returns a WrapperTarget object. | |
FpmTestBase:: |
protected | function | Updates a protected, private property of an object. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
TestWrapperTarget:: |
protected | property | ||
TestWrapperTarget:: |
protected | property | ||
TestWrapperTarget:: |
public | function | Mocks a form state object. | |
TestWrapperTarget:: |
protected | function |
@inheritdoc Overrides FpmTestBase:: |
|
TestWrapperTarget:: |
public | function | @covers ::buildConfigurationForm | |
TestWrapperTarget:: |
public | function | @covers ::createTargetInstance | |
TestWrapperTarget:: |
public | function | @covers ::defaultConfiguration | |
TestWrapperTarget:: |
public | function | @covers ::getSummary | |
TestWrapperTarget:: |
public | function | @covers ::prepareTarget | |
TestWrapperTarget:: |
public | function | @covers \Drupal\feeds_para_mapper\Feeds\Target\WrapperTarget::targets | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed 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. |