class PostSaveProcessTest

Tests Drupal\views\PostSaveProcess.

Attributes

#[CoversClass(PostSaveProcess::class)] #[Group('views')]

Hierarchy

Expanded class hierarchy of PostSaveProcessTest

File

core/modules/views/tests/src/Unit/PostSaveProcessTest.php, line 17

Namespace

Drupal\Tests\views\Unit
View source
class PostSaveProcessTest extends UnitTestCase {
  
  /**
   * Tests router rebuild flagging.
   */
  public function testNeedsRouterRebuild() : void {
    $postSaveProcess = new PostSaveProcess();
    $this->assertFalse($postSaveProcess->needsRouterRebuild());
    $postSaveProcess->setRouterRebuild();
    $this->assertTrue($postSaveProcess->needsRouterRebuild());
  }
  
  /**
   * Tests queueing discoveries to clear, deduplicated by class name.
   */
  public function testDiscoveriesToClear() : void {
    $postSaveProcess = new PostSaveProcess();
    $this->assertSame([], $postSaveProcess->getDiscoveriesToClear());
    // Two distinct CachedDiscoveryInterface implementations.
    [$discoveryA, $discoveryB] = \array_map(fn(string $class) => $this->createStub($class), [
      EntityTypeManagerInterface::class,
      TypedDataManagerInterface::class,
    ]);
    $postSaveProcess->addDiscoveryToClear($discoveryA);
    // Adding the same instance again must not create a duplicate entry.
    $postSaveProcess->addDiscoveryToClear($discoveryA);
    $this->assertCount(1, $postSaveProcess->getDiscoveriesToClear());
    // A discovery of a different class is queued as its own entry.
    $postSaveProcess->addDiscoveryToClear($discoveryB);
    $this->assertSame([
      get_class($discoveryA) => $discoveryA,
      get_class($discoveryB) => $discoveryB,
    ], $postSaveProcess->getDiscoveriesToClear());
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.