class FieldTargetDefinitionTest in Feeds 8.3
@coversDefaultClass \Drupal\feeds\FieldTargetDefinition @group feeds
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\feeds\Unit\FeedsUnitTestCase uses FeedsMockingTrait, FeedsReflectionTrait
- class \Drupal\Tests\feeds\Unit\FieldTargetDefinitionTest
- class \Drupal\Tests\feeds\Unit\FeedsUnitTestCase uses FeedsMockingTrait, FeedsReflectionTrait
Expanded class hierarchy of FieldTargetDefinitionTest
File
- tests/
src/ Unit/ FieldTargetDefinitionTest.php, line 14
Namespace
Drupal\Tests\feeds\UnitView source
class FieldTargetDefinitionTest extends FeedsUnitTestCase {
/**
* A prophesized data definition for the field item.
*
* @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\TypedData\ComplexDataDefinitionInterface
*/
protected $itemDefinition;
/**
* A prophesized data definition for the field property.
*
* @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\TypedData\DataDefinitionInterface
*/
protected $propertyDefinition;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->itemDefinition = $this
->prophesize(ComplexDataDefinitionInterface::class);
$this->propertyDefinition = $this
->prophesize(DataDefinitionInterface::class);
}
/**
* Creates a prophesized field definition.
*
* @return \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Field\FieldDefinitionInterface
* A prophesized field definition.
*/
protected function createFieldDefinition() {
$field_definition = $this
->prophesize(FieldDefinitionInterface::class);
$field_definition
->getItemDefinition()
->willReturn($this->itemDefinition
->reveal());
return $field_definition;
}
/**
* Tests that the label is taken from field definition.
*
* @covers ::getPropertyLabel
*/
public function testGetPropertyLabel() {
$this->propertyDefinition
->getLabel()
->willReturn('Foo label')
->shouldBeCalled();
$this->itemDefinition
->getPropertyDefinition('foo')
->willReturn($this->propertyDefinition
->reveal())
->shouldBeCalled();
$field_definition = $this
->createFieldDefinition();
$target_definition = FieldTargetDefinition::createFromFieldDefinition($field_definition
->reveal());
$this
->assertEquals('Foo label', $target_definition
->getPropertyLabel('foo'));
}
/**
* Tests that a custom set property label takes precedence.
*
* @covers ::getPropertyLabel
*/
public function testGetPropertyLabelWithCustomSetLabel() {
$this->propertyDefinition
->getLabel()
->willReturn('Foo label');
$this->itemDefinition
->getPropertyDefinition('foo')
->willReturn($this->propertyDefinition
->reveal());
$field_definition = $this
->createFieldDefinition();
$target_definition = FieldTargetDefinition::createFromFieldDefinition($field_definition
->reveal());
$target_definition
->addProperty('foo', 'Custom label');
$this
->assertEquals('Custom label', $target_definition
->getPropertyLabel('foo'));
}
/**
* Tests no errors when the label for a custom property isn't set.
*
* @covers ::getPropertyLabel
*/
public function testGetPropertyLabelOfNonExistingProperty() {
$field_definition = $this
->createFieldDefinition();
$target_definition = FieldTargetDefinition::createFromFieldDefinition($field_definition
->reveal());
$target_definition
->addProperty('bar');
$this
->assertEquals('', $target_definition
->getPropertyLabel('bar'));
}
/**
* Tests that the description is taken from field definition.
*
* @covers ::getPropertyDescription
*/
public function testGetPropertyDescription() {
$this->propertyDefinition
->getDescription()
->willReturn('Foo description')
->shouldBeCalled();
$this->itemDefinition
->getPropertyDefinition('foo')
->willReturn($this->propertyDefinition
->reveal())
->shouldBeCalled();
$field_definition = $this
->createFieldDefinition();
$target_definition = FieldTargetDefinition::createFromFieldDefinition($field_definition
->reveal());
$this
->assertEquals('Foo description', $target_definition
->getPropertyDescription('foo'));
}
/**
* Tests that a custom set property description takes precedence.
*
* @covers ::getPropertyDescription
*/
public function testGetPropertyDescriptionWithCustomSetDescription() {
$this->propertyDefinition
->getDescription()
->willReturn('Foo description');
$this->itemDefinition
->getPropertyDefinition('foo')
->willReturn($this->propertyDefinition
->reveal());
$field_definition = $this
->createFieldDefinition();
$target_definition = FieldTargetDefinition::createFromFieldDefinition($field_definition
->reveal());
$target_definition
->addProperty('foo', 'Custom label', 'Custom description');
$this
->assertEquals('Custom description', $target_definition
->getPropertyDescription('foo'));
}
/**
* Tests no errors when the description for a custom property isn't set.
*
* @covers ::getPropertyDescription
*/
public function testGetPropertyDescriptionOfNonExistingProperty() {
$field_definition = $this
->createFieldDefinition();
$target_definition = FieldTargetDefinition::createFromFieldDefinition($field_definition
->reveal());
$target_definition
->addProperty('bar');
$this
->assertEquals('', $target_definition
->getPropertyDescription('bar'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsMockingTrait:: |
protected | function | Mocks an account object. | |
FeedsMockingTrait:: |
protected | function | Returns a mocked AccountSwitcher object. | |
FeedsMockingTrait:: |
protected | function | Returns a mocked feed entity. | |
FeedsMockingTrait:: |
protected | function | Returns a mocked feed type entity. | |
FeedsMockingTrait:: |
protected | function | Mocks a field definition. | 1 |
FeedsMockingTrait:: |
protected | function | Mocks the file system. | |
FeedsReflectionTrait:: |
protected | function | Calls a protected method on the given object. | |
FeedsReflectionTrait:: |
protected | function | Gets a ReflectionMethod for a class method. | |
FeedsReflectionTrait:: |
protected | function | Returns a dynamically created closure for the object's method. | |
FeedsReflectionTrait:: |
protected | function | Sets a protected property. | |
FeedsUnitTestCase:: |
protected | function | Returns the absolute directory path of the Feeds module. | |
FeedsUnitTestCase:: |
protected | function | Defines stub constants. | |
FeedsUnitTestCase:: |
protected | function | Returns a mock stream wrapper manager. | |
FeedsUnitTestCase:: |
protected | function | Returns the absolute directory path of the resources folder. | |
FieldTargetDefinitionTest:: |
protected | property | A prophesized data definition for the field item. | |
FieldTargetDefinitionTest:: |
protected | property | A prophesized data definition for the field property. | |
FieldTargetDefinitionTest:: |
protected | function | Creates a prophesized field definition. | |
FieldTargetDefinitionTest:: |
public | function |
Overrides FeedsUnitTestCase:: |
|
FieldTargetDefinitionTest:: |
public | function | Tests that the description is taken from field definition. | |
FieldTargetDefinitionTest:: |
public | function | Tests no errors when the description for a custom property isn't set. | |
FieldTargetDefinitionTest:: |
public | function | Tests that a custom set property description takes precedence. | |
FieldTargetDefinitionTest:: |
public | function | Tests that the label is taken from field definition. | |
FieldTargetDefinitionTest:: |
public | function | Tests no errors when the label for a custom property isn't set. | |
FieldTargetDefinitionTest:: |
public | function | Tests that a custom set property label takes precedence. | |
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. | |
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. |