class ResultTest
Same name in other branches
- 9 core/modules/views/tests/src/Unit/Plugin/area/ResultTest.php \Drupal\Tests\views\Unit\Plugin\area\ResultTest
- 8.9.x core/modules/views/tests/src/Unit/Plugin/area/ResultTest.php \Drupal\Tests\views\Unit\Plugin\area\ResultTest
- 11.x core/modules/views/tests/src/Unit/Plugin/area/ResultTest.php \Drupal\Tests\views\Unit\Plugin\area\ResultTest
@coversDefaultClass \Drupal\views\Plugin\views\area\Result @group views
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\views\Unit\Plugin\area\ResultTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ResultTest
2 string references to 'ResultTest'
- ResultTest::providerTestResultArea in core/
modules/ views/ tests/ src/ Unit/ Plugin/ area/ ResultTest.php - Data provider for testResultArea.
- ResultTest::setUp in core/
modules/ views/ tests/ src/ Unit/ Plugin/ area/ ResultTest.php
File
-
core/
modules/ views/ tests/ src/ Unit/ Plugin/ area/ ResultTest.php, line 22
Namespace
Drupal\Tests\views\Unit\Plugin\areaView source
class ResultTest extends UnitTestCase {
/**
* The view executable object.
*
* @var \Drupal\views\ViewExecutable
*/
protected $view;
/**
* The Result handler.
*
* @var \Drupal\views\Plugin\views\area\Result
*/
protected $resultHandler;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$storage = $this->prophesize(View::class);
$storage->label()
->willReturn('ResultTest');
$storage->set(Argument::cetera())
->willReturn(NULL);
$user = $this->prophesize(AccountInterface::class)
->reveal();
$views_data = $this->prophesize(ViewsData::class)
->reveal();
$route_provider = $this->prophesize(RouteProviderInterface::class)
->reveal();
$display_plugin_manager = $this->prophesize(ViewsPluginManager::class)
->reveal();
$this->view = new ViewExecutable($storage->reveal(), $user, $views_data, $route_provider, $display_plugin_manager);
$this->resultHandler = new Result([], 'result', []);
$this->resultHandler->view = $this->view;
}
/**
* Tests the query method.
*/
public function testQuery() : void {
$this->assertNull($this->view->get_total_rows);
// @total should set get_total_rows.
$this->resultHandler->options['content'] = '@total';
$this->resultHandler
->query();
$this->assertTrue($this->view->get_total_rows);
// A different token should not.
$this->view->get_total_rows = NULL;
$this->resultHandler->options['content'] = '@current_page';
$this->resultHandler
->query();
$this->assertNull($this->view->get_total_rows);
}
/**
* Tests the rendered output of the Result area handler.
*
* @param string $content
* The content to use when rendering the handler.
* @param string $expected
* The expected content string.
* @param int $items_per_page
* The items per page of the configuration.
*
* @dataProvider providerTestResultArea
*/
public function testResultArea($content, $expected, $items_per_page = 0) : void {
$this->setupViewPager($items_per_page);
$this->resultHandler->options['content'] = $content;
$this->assertEquals([
'#markup' => $expected,
], $this->resultHandler
->render());
}
/**
* Data provider for testResultArea.
*
* @return array
*/
public static function providerTestResultArea() {
return [
[
'@label',
'ResultTest',
],
[
'@start',
'1',
],
[
'@start',
'1',
1,
],
[
'@end',
'100',
],
[
'@end',
'1',
1,
],
[
'@total',
'100',
],
[
'@total',
'100',
1,
],
[
'@per_page',
'0',
],
[
'@per_page',
'1',
1,
],
[
'@current_page',
'1',
],
[
'@current_page',
'1',
1,
],
[
'@current_record_count',
'100',
],
[
'@current_record_count',
'1',
1,
],
[
'@page_count',
'1',
],
[
'@page_count',
'100',
1,
],
[
'@start | @end | @total',
'1 | 100 | 100',
],
[
'@start | @end | @total',
'1 | 1 | 100',
1,
],
];
}
/**
* Sets up a mock pager on the view executable object.
*
* @param int $items_per_page
* The value to return from getItemsPerPage().
*/
protected function setupViewPager($items_per_page = 0) {
$pager = $this->prophesize(PagerPluginBase::class);
$pager->getItemsPerPage()
->willReturn($items_per_page)
->shouldBeCalledTimes(1);
$pager->getCurrentPage()
->willReturn(0)
->shouldBeCalledTimes(1);
$this->view->pager = $pager->reveal();
$this->view->style_plugin = new \stdClass();
$this->view->total_rows = 100;
$this->view->result = [
1,
2,
3,
4,
5,
];
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |||
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |||
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
ResultTest::$resultHandler | protected | property | The Result handler. | |||
ResultTest::$view | protected | property | The view executable object. | |||
ResultTest::providerTestResultArea | public static | function | Data provider for testResultArea. | |||
ResultTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
ResultTest::setupViewPager | protected | function | Sets up a mock pager on the view executable object. | |||
ResultTest::testQuery | public | function | Tests the query method. | |||
ResultTest::testResultArea | public | function | Tests the rendered output of the Result area handler. | |||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::setUpBeforeClass | public static | function | ||||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.