class UrlProcessorHandlerTest in Facets 8
Unit test for processor.
@group facets
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\facets\Unit\Plugin\processor\UrlProcessorHandlerTest
Expanded class hierarchy of UrlProcessorHandlerTest
File
- tests/
src/ Unit/ Plugin/ processor/ UrlProcessorHandlerTest.php, line 20
Namespace
Drupal\Tests\facets\Unit\Plugin\processorView source
class UrlProcessorHandlerTest extends UnitTestCase {
/**
* Tests that the processor correctly throws an exception.
*/
public function testEmptyProcessorConfiguration() {
$this
->expectException(InvalidProcessorException::class);
$this
->expectExceptionMessage("The UrlProcessorHandler doesn't have the required 'facet' in the configuration array.");
new UrlProcessorHandler([], 'test', []);
}
/**
* Tests that the processor correctly throws an exception.
*/
public function testInvalidProcessorConfiguration() {
$this
->expectException(InvalidProcessorException::class);
$this
->expectExceptionMessage("The UrlProcessorHandler doesn't have the required 'facet' in the configuration array.");
new UrlProcessorHandler([
'facet' => new \stdClass(),
], 'test', []);
}
/**
* Tests that the build method is correctly called.
*/
public function testBuild() {
$facet = new Facet([
'id' => '_test',
], 'facets_facet');
$this
->createContainer();
$processor = new UrlProcessorHandler([
'facet' => $facet,
], 'url_processor_handler', []);
// The actual results of this should be tested in the actual processor.
$processor
->build($facet, []);
}
/**
* Tests configuration.
*/
public function testConfiguration() {
$facet = new Facet([], 'facets_facet');
$this
->createContainer();
$processor = new UrlProcessorHandler([
'facet' => $facet,
], 'url_processor_handler', []);
$config = $processor
->defaultConfiguration();
$this
->assertEquals([], $config);
}
/**
* Tests testDescription().
*/
public function testDescription() {
$facet = new Facet([], 'facets_facet');
$this
->createContainer();
$processor = new UrlProcessorHandler([
'facet' => $facet,
], 'url_processor_handler', []);
$this
->assertEquals('', $processor
->getDescription());
}
/**
* Tests isHidden().
*/
public function testIsHidden() {
$facet = new Facet([], 'facets_facet');
$this
->createContainer();
$processor = new UrlProcessorHandler([
'facet' => $facet,
], 'url_processor_handler', []);
$this
->assertEquals(FALSE, $processor
->isHidden());
}
/**
* Tests isLocked().
*/
public function testIsLocked() {
$facet = new Facet([], 'facets_facet');
$this
->createContainer();
$processor = new UrlProcessorHandler([
'facet' => $facet,
], 'url_processor_handler', []);
$this
->assertEquals(FALSE, $processor
->isLocked());
}
/**
* Sets up a container.
*/
protected function createContainer() {
$url_processor = $this
->getMockBuilder(UrlProcessorInterface::class)
->disableOriginalConstructor()
->getMock();
$manager = $this
->getMockBuilder(FacetSourcePluginManager::class)
->disableOriginalConstructor()
->getMock();
$manager
->expects($this
->exactly(1))
->method('createInstance')
->willReturn($url_processor);
$storage = $this
->createMock(EntityStorageInterface::class);
$em = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$em
->expects($this
->exactly(1))
->method('getStorage')
->willReturn($storage);
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $em);
$container
->set('plugin.manager.facets.url_processor', $manager);
\Drupal::setContainer($container);
}
}
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. | |
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. | |
UnitTestCase:: |
protected | function | 340 | |
UrlProcessorHandlerTest:: |
protected | function | Sets up a container. | |
UrlProcessorHandlerTest:: |
public | function | Tests that the build method is correctly called. | |
UrlProcessorHandlerTest:: |
public | function | Tests configuration. | |
UrlProcessorHandlerTest:: |
public | function | Tests testDescription(). | |
UrlProcessorHandlerTest:: |
public | function | Tests that the processor correctly throws an exception. | |
UrlProcessorHandlerTest:: |
public | function | Tests that the processor correctly throws an exception. | |
UrlProcessorHandlerTest:: |
public | function | Tests isHidden(). | |
UrlProcessorHandlerTest:: |
public | function | Tests isLocked(). |