class AgreementEntityTest in Agreement 8.2
Same name and namespace in other branches
- 3.0.x tests/src/Unit/Plugin/views/field/AgreementEntityTest.php \Drupal\Tests\agreement\Unit\Plugin\views\field\AgreementEntityTest
Tests the agreement entity views field plugin.
@group agreement
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\agreement\Unit\Plugin\views\field\AgreementEntityTest
Expanded class hierarchy of AgreementEntityTest
File
- tests/
src/ Unit/ Plugin/ views/ field/ AgreementEntityTest.php, line 16
Namespace
Drupal\Tests\agreement\Unit\Plugin\views\fieldView source
class AgreementEntityTest extends UnitTestCase {
/**
* Agreement entity plugin.
*
* @var \Drupal\agreement\Plugin\views\field\AgreementEntity
*/
protected $plugin;
/**
* {@inheritdoc}
*/
protected function setUp() {
$agreement = new Agreement([
'id' => 'default',
'label' => 'Default agreement',
'path' => '/agreement',
'agreement' => '',
'settings' => [
'visibility' => [
'settings' => 0,
'pages' => [],
],
'roles' => [
'authenticated',
],
'frequency' => -1,
'title' => 'Our agreement',
],
], 'agreement');
$styleProphet = $this
->prophesize('\\Drupal\\views\\Plugin\\views\\style\\DefaultStyle');
$viewProphet = $this
->prophesize('\\Drupal\\views\\ViewExecutable');
$viewProphet
->getStyle()
->willReturn($styleProphet
->reveal());
$storageProphet = $this
->prophesize('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
$storageProphet
->loadMultiple()
->willReturn([
'default' => $agreement,
]);
$entityManagerProphet = $this
->prophesize('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface');
$entityManagerProphet
->getStorage('agreement')
->willReturn($storageProphet
->reveal());
$definition = [
'id' => 'agreement_entity',
];
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $entityManagerProphet
->reveal());
$container
->set('string_translation', $this
->getStringTranslationStub());
\Drupal::setContainer($container);
$this->plugin = new AgreementEntity([], 'agreement_entity', $definition, $container
->get('entity_type.manager'));
$this->plugin->view = $viewProphet
->reveal();
$this->plugin->field_alias = 'type';
}
/**
* Asserts the default display option.
*/
public function testDefineOptions() {
$expected = [
'default' => [
'label',
],
];
$this
->assertEquals($expected, $this->plugin
->defineOptions()['display']);
}
/**
* Asserts agreement entity set on results.
*/
public function testPreRender() {
$values = [
new ResultRow([
'type' => 'default',
'uid' => 1,
]),
new ResultRow([
'type' => 'default',
'uid' => 2,
]),
new ResultRow([
'uid' => 3,
]),
];
$this->plugin
->preRender($values);
$this
->assertObjectHasAttribute('_agreement', $values[0]);
}
/**
* Asserts that render builds markup based on options.
*
* @param array $options
* An array of "display" options.
* @param string $expected_key
* The expected array key or result.
*
* @dataProvider renderProvider
*/
public function testRender(array $options, $expected_key) {
$this->plugin->options += [
'display' => $options,
];
$values = [
new ResultRow([
'type' => 'default',
'uid' => 2,
]),
];
$this->plugin
->preRender($values);
$markup = $this->plugin
->render($values[0]);
if (empty($options)) {
$this
->assertEquals($expected_key, $markup);
}
else {
$this
->assertArrayHasKey($expected_key, $markup);
}
}
/**
* Provides test arguments for testing render method.
*
* @return array
* An indexed array of tests to run with test arguments.
*/
public function renderProvider() {
return [
[
[],
'default',
],
[
[
'id',
],
'id',
],
[
[
'label',
],
'label',
],
[
[
'path',
],
'path',
],
[
[
'roles',
],
'roles',
],
[
[
'title',
],
'title',
],
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AgreementEntityTest:: |
protected | property | Agreement entity plugin. | |
AgreementEntityTest:: |
public | function | Provides test arguments for testing render method. | |
AgreementEntityTest:: |
protected | function |
Overrides UnitTestCase:: |
|
AgreementEntityTest:: |
public | function | Asserts the default display option. | |
AgreementEntityTest:: |
public | function | Asserts agreement entity set on results. | |
AgreementEntityTest:: |
public | function | Asserts that render builds markup based on options. | |
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. |