class CaptchaPointListBuilderTest in CAPTCHA 8
Tests for CaptchaPointListBuilder.
@group captcha
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\captcha\Unit\Controller\CaptchaPointListBuilderTest
Expanded class hierarchy of CaptchaPointListBuilderTest
File
- tests/
src/ Unit/ Controller/ CaptchaPointListBuilderTest.php, line 19
Namespace
Drupal\Tests\captcha\Unit\ControllerView source
class CaptchaPointListBuilderTest extends UnitTestCase {
/**
* Set up.
*/
public function setUp() {
$this->mockModuleHandler = $this
->prophesize(ModuleHandlerInterface::class);
$this->mockModuleHandler
->invokeAll(Argument::any(), Argument::any())
->willReturn([]);
$this->mockModuleHandler
->alter(Argument::any(), Argument::any(), Argument::any())
->willReturn([]);
$this->mockContainer = $this
->prophesize(ContainerInterface::class);
$this->mockContainer
->get('string_translation')
->willReturn($this
->getStringTranslationStub());
$this->mockContainer
->get('module_handler')
->willReturn($this->mockModuleHandler
->reveal());
$this->mockEntityType = $this
->prophesize(EntityTypeInterface::class);
$this->mockEntityStorage = $this
->prophesize(EntityStorageInterface::class);
$this->listBuilder = new CaptchaPointListBuilder($this->mockEntityType
->reveal(), $this->mockEntityStorage
->reveal());
\Drupal::setContainer($this->mockContainer
->reveal());
}
/**
* Test for buildHeader.
*/
public function testBuildHeader() {
$header = $this->listBuilder
->buildHeader();
$this
->assertArrayHasKey('form_id', $header);
$this
->assertArrayHasKey('captcha_type', $header);
$this
->assertArrayHasKey('operations', $header);
}
/**
* Test for buildRow.
*/
public function testBuildRow() {
$mockEntity = $this
->prophesize(CaptchaPoint::class);
$mockEntity
->access(Argument::any())
->willReturn(FALSE);
$mockEntity
->id()
->willReturn('target_form_id');
$mockEntity
->getCaptchaType()
->willReturn('captcha_type');
$row = $this->listBuilder
->buildRow($mockEntity
->reveal());
$this
->assertArrayHasKey('form_id', $row);
$this
->assertEquals('target_form_id', $row['form_id']);
$this
->assertArrayHasKey('captcha_type', $row);
$this
->assertEquals('captcha_type', $row['captcha_type']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CaptchaPointListBuilderTest:: |
public | function |
Set up. Overrides UnitTestCase:: |
|
CaptchaPointListBuilderTest:: |
public | function | Test for buildHeader. | |
CaptchaPointListBuilderTest:: |
public | function | Test for buildRow. | |
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. |