class TreeRebuilderUnitTest in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 tests/src/Unit/TreeRebuilderUnitTest.php \Drupal\Tests\entity_hierarchy\Unit\TreeRebuilderUnitTest
Defines a class for testing tree rebuilder.
@group entity_hierarchy
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\entity_hierarchy\Unit\TreeRebuilderUnitTest
Expanded class hierarchy of TreeRebuilderUnitTest
File
- tests/
src/ Unit/ TreeRebuilderUnitTest.php, line 14
Namespace
Drupal\Tests\entity_hierarchy\UnitView source
class TreeRebuilderUnitTest extends UnitTestCase {
/**
* Tests tree sort.
*
* Structure
* - 789
* -- 991
* -- 891
* --- 784
* ---- 999
* --- 23
* - 123
* - 781
* - 782
* -- 783
*/
public function testTreeSort() {
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$treeRebuilder = new TreeRebuilder($entity_type_manager
->reveal());
$reflection = new \ReflectionClass($treeRebuilder);
$method = $reflection
->getMethod('treeSort');
$method
->setAccessible(TRUE);
$records = [
[
'nid' => 789,
'field_parent_target_id' => 456,
'field_parent_weight' => -50,
],
[
'nid' => 123,
'field_parent_target_id' => 456,
'field_parent_weight' => -49,
],
[
'nid' => 781,
'field_parent_target_id' => 656,
'field_parent_weight' => -50,
],
[
'nid' => 782,
'field_parent_target_id' => 656,
'field_parent_weight' => -50,
],
[
'nid' => 783,
'field_parent_target_id' => 782,
'field_parent_weight' => -50,
],
[
'nid' => 999,
'field_parent_target_id' => 784,
'field_parent_weight' => -50,
],
[
'nid' => 991,
'field_parent_target_id' => 789,
'field_parent_weight' => -50,
],
[
'nid' => 891,
'field_parent_target_id' => 789,
'field_parent_weight' => -49,
],
[
'nid' => 784,
'field_parent_target_id' => 891,
'field_parent_weight' => -50,
],
[
'nid' => 23,
'field_parent_target_id' => 891,
'field_parent_weight' => -49,
],
];
$result = $method
->invoke($treeRebuilder, 'field_parent', $records, 'nid');
$this
->assertSame([
789,
991,
891,
784,
999,
23,
123,
781,
782,
783,
], array_keys($result));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
TreeRebuilderUnitTest:: |
public | function | Tests tree sort. | |
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 | 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 | 308 | |
UnitTestCase:: |
public static | function |