class SqlTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest
@coversDefaultClass \Drupal\views\Plugin\views\query\Sql
@group views
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\views\Unit\Plugin\query\SqlTest
Expanded class hierarchy of SqlTest
File
- core/
modules/ views/ tests/ src/ Unit/ Plugin/ query/ SqlTest.php, line 19 - Contains \Drupal\Tests\views\Unit\Plugin\query\SqlTest.
Namespace
Drupal\Tests\views\Unit\Plugin\queryView source
class SqlTest extends UnitTestCase {
/**
* @covers ::getCacheTags
* @covers ::getAllEntities
*/
public function testGetCacheTags() {
$view = $this
->prophesize('Drupal\\views\\ViewExecutable')
->reveal();
$query = new Sql([], 'sql', []);
$query->view = $view;
$result = [];
$view->result = $result;
// Add a row with an entity.
$row = new ResultRow();
$prophecy = $this
->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy
->getCacheTags()
->willReturn([
'entity_test:123',
]);
$entity = $prophecy
->reveal();
$row->_entity = $entity;
$result[] = $row;
$view->result = $result;
// Add a row with an entity and a relationship entity.
$row = new ResultRow();
$prophecy = $this
->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy
->getCacheTags()
->willReturn([
'entity_test:124',
]);
$entity = $prophecy
->reveal();
$row->_entity = $entity;
$prophecy = $this
->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy
->getCacheTags()
->willReturn([
'entity_test:125',
]);
$entity = $prophecy
->reveal();
$row->_relationship_entities[] = $entity;
$prophecy = $this
->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy
->getCacheTags()
->willReturn([
'entity_test:126',
]);
$entity = $prophecy
->reveal();
$row->_relationship_entities[] = $entity;
$result[] = $row;
$view->result = $result;
$this
->assertEquals([
'entity_test:123',
'entity_test:124',
'entity_test:125',
'entity_test:126',
], $query
->getCacheTags());
}
/**
* @covers ::getCacheTags
* @covers ::getAllEntities
*/
public function testGetCacheMaxAge() {
$view = $this
->prophesize('Drupal\\views\\ViewExecutable')
->reveal();
$query = new Sql([], 'sql', []);
$query->view = $view;
$view->result = [];
// Add a row with an entity.
$row = new ResultRow();
$prophecy = $this
->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy
->getCacheMaxAge()
->willReturn(10);
$entity = $prophecy
->reveal();
$row->_entity = $entity;
$view->result[] = $row;
// Add a row with an entity and a relationship entity.
$row = new ResultRow();
$prophecy = $this
->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy
->getCacheMaxAge()
->willReturn(20);
$entity = $prophecy
->reveal();
$row->_entity = $entity;
$prophecy = $this
->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy
->getCacheMaxAge()
->willReturn(30);
$entity = $prophecy
->reveal();
$row->_relationship_entities[] = $entity;
$prophecy = $this
->prophesize('Drupal\\Core\\Entity\\EntityInterface');
$prophecy
->getCacheMaxAge()
->willReturn(40);
$entity = $prophecy
->reveal();
$row->_relationship_entities[] = $entity;
$this
->assertEquals(10, $query
->getCacheMaxAge());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SqlTest:: |
public | function | @covers ::getCacheTags @covers ::getAllEntities | |
SqlTest:: |
public | function | @covers ::getCacheTags @covers ::getAllEntities | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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 | 259 |