class ItemFieldTest in Search API 8
Tests functionality of the field class.
@coversDefaultClass \Drupal\search_api\Item\Field
@group search_api
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\search_api\Unit\ItemFieldTest
Expanded class hierarchy of ItemFieldTest
File
- tests/
src/ Unit/ ItemFieldTest.php, line 17
Namespace
Drupal\Tests\search_api\UnitView source
class ItemFieldTest extends UnitTestCase {
/**
* The field object being tested.
*
* @var \Drupal\search_api\Item\Field
*/
protected $field;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$data_type = $this
->createMock(DataTypeInterface::class);
$data_type
->expects($this
->any())
->method('getValue')
->willReturnCallback(function ($v) {
return "*{$v}";
});
/** @var \Drupal\search_api\DataType\DataTypePluginManager|\PHPUnit\Framework\MockObject\MockObject $data_type_manager */
$data_type_manager = $this
->getMockBuilder('Drupal\\search_api\\DataType\\DataTypePluginManager')
->disableOriginalConstructor()
->getMock();
$data_type_manager
->expects($this
->any())
->method('hasDefinition')
->willReturn(TRUE);
$data_type_manager
->expects($this
->any())
->method('createInstance')
->willReturn($data_type);
$index = new Index([], 'search_api_index');
$this->field = new Field($index, 'field');
$this->field
->setDataTypeManager($data_type_manager);
}
/**
* Tests setting the Values.
*
* @covers ::setValues
*/
public function testSetValues() {
$values = [
'*foo',
'*bar',
];
$this->field
->setValues($values);
$this
->assertEquals($values, $this->field
->getValues());
}
/**
* Tests adding a value.
*
* Ensures that a string passed to addValue() is processed by the data type
* plugin.
*
* @covers ::addValue
*/
public function testAddValue() {
$this->field
->setValues([
'*foo',
]);
$this->field
->addValue('bar');
$this
->assertEquals([
'*foo',
'*bar',
], $this->field
->getValues());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ItemFieldTest:: |
protected | property | The field object being tested. | |
ItemFieldTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ItemFieldTest:: |
public | function | Tests adding a value. | |
ItemFieldTest:: |
public | function | Tests setting the Values. | |
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. |