You are here

class TreeRebuilderUnitTest in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/TreeRebuilderUnitTest.php \Drupal\Tests\entity_hierarchy\Unit\TreeRebuilderUnitTest

Defines a class for testing tree rebuilder.

@group entity_hierarchy

Hierarchy

Expanded class hierarchy of TreeRebuilderUnitTest

File

tests/src/Unit/TreeRebuilderUnitTest.php, line 14

Namespace

Drupal\Tests\entity_hierarchy\Unit
View 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

Namesort descending Modifiers Type Description 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.
TreeRebuilderUnitTest::testTreeSort public function Tests tree sort.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 308
UnitTestCase::setUpBeforeClass public static function