class ShowTextWhenEmptyProcessorTest in Facets 8
Class ShowTextWhenEmptyProcessorTest.
@group facets @coversDefaultClass \Drupal\facets_summary\Plugin\facets_summary\processor\ShowTextWhenEmptyProcessor
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\facets_summary\Unit\Plugin\Processor\ShowTextWhenEmptyProcessorTest
Expanded class hierarchy of ShowTextWhenEmptyProcessorTest
File
- modules/
facets_summary/ tests/ src/ Unit/ Plugin/ Processor/ ShowTextWhenEmptyProcessorTest.php, line 18
Namespace
Drupal\Tests\facets_summary\Unit\Plugin\ProcessorView source
class ShowTextWhenEmptyProcessorTest extends UnitTestCase {
/**
* The processor we're testing.
*
* @var \Drupal\facets_summary\Processor\ProcessorInterface|\Drupal\facets_summary\Processor\BuildProcessorInterface
*/
protected $processor;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$string_translation = $this
->prophesize(TranslationInterface::class);
$container = new ContainerBuilder();
$container
->set('string_translation', $string_translation
->reveal());
\Drupal::setContainer($container);
$this->processor = new ShowTextWhenEmptyProcessor([], 'show_text_when_empty', []);
}
/**
* Tests the is hidden method.
*
* @covers ::isHidden
*/
public function testIsHidden() {
$this
->assertFalse($this->processor
->isHidden());
}
/**
* Tests the is locked method.
*
* @covers ::isLocked
*/
public function testIsLocked() {
$this
->assertFalse($this->processor
->isLocked());
}
/**
* Tests the build method.
*
* @covers ::build
*/
public function testBuild() {
$summary = new FacetsSummary([], 'facets_summary');
$summary
->setFacetSourceId('foo');
$result = $this->processor
->build($summary, [
'foo',
], []);
$this
->assertSame('array', gettype($result));
$this
->assertArrayHasKey('#theme', $result);
$this
->assertEquals('facets_summary_empty', $result['#theme']);
$this
->assertArrayHasKey('#message', $result);
$configuration = [
'text' => [
'value' => 'llama',
'format' => 'html',
],
];
$this->processor
->setConfiguration($configuration);
$result = $this->processor
->build($summary, [
'foo',
], []);
$this
->assertEquals('llama', $result['#message']['#text']);
}
/**
* Tests the build method.
*
* @covers ::build
*/
public function testBuildWithEmptyItems() {
$summary = new FacetsSummary([], 'facets_summary');
$summary
->setFacetSourceId('foo');
$build = [
'#items' => [],
];
$result = $this->processor
->build($summary, $build, []);
$this
->assertSame('array', gettype($result));
$this
->assertArrayHasKey('#theme', $result);
$this
->assertEquals('facets_summary_empty', $result['#theme']);
$this
->assertArrayHasKey('#message', $result);
$this
->assertArrayHasKey('#text', $result['#message']);
$this
->assertEquals(new TranslatableMarkup('No results found.'), (string) $result['#message']['#text']);
$this
->assertEquals('plain_text', $result['#message']['#format']);
}
/**
* Tests build with config changes.
*
* @covers ::build
*/
public function testBuildWithConfigChange() {
$summary = new FacetsSummary([], 'facets_summary');
$summary
->setFacetSourceId('foo');
$build = [
'#items' => [],
];
$this->processor
->setConfiguration([
'text' => [
'value' => 'Owl',
'format' => 'llama',
],
]);
$result = $this->processor
->build($summary, $build, []);
$this
->assertSame('array', gettype($result));
$this
->assertArrayHasKey('#text', $result['#message']);
$this
->assertEquals('Owl', (string) $result['#message']['#text']);
$this
->assertEquals('llama', $result['#message']['#format']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
ShowTextWhenEmptyProcessorTest:: |
protected | property | The processor we're testing. | |
ShowTextWhenEmptyProcessorTest:: |
public | function |
Overrides UnitTestCase:: |
|
ShowTextWhenEmptyProcessorTest:: |
public | function | Tests the build method. | |
ShowTextWhenEmptyProcessorTest:: |
public | function | Tests build with config changes. | |
ShowTextWhenEmptyProcessorTest:: |
public | function | Tests the build method. | |
ShowTextWhenEmptyProcessorTest:: |
public | function | Tests the is hidden method. | |
ShowTextWhenEmptyProcessorTest:: |
public | function | Tests the is locked method. | |
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. |