You are here

class VocabularySerializationTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/VocabularySerializationTest.php \Drupal\Tests\taxonomy\Functional\VocabularySerializationTest
  2. 9 core/modules/taxonomy/tests/src/Functional/VocabularySerializationTest.php \Drupal\Tests\taxonomy\Functional\VocabularySerializationTest

Regression test for https://www.drupal.org/node/2807263.

When a Vocabulary entity is unserialized before the modules have been loaded (which happens in the KernelPreHandle Stack middleware), then the constants that the Vocabulary entity uses are not yet available because they are set in taxonomy.module. This means that for example the PageCache middleware cannot load any cached Vocabulary entity, because unserialization will fail.

@group taxonomy

Hierarchy

Expanded class hierarchy of VocabularySerializationTest

File

core/modules/taxonomy/tests/src/Functional/VocabularySerializationTest.php, line 19

Namespace

Drupal\Tests\taxonomy\Functional
View source
class VocabularySerializationTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'taxonomy',
    'vocabulary_serialization_test',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    Vocabulary::create([
      'vid' => 'test',
    ])
      ->save();
  }
  public function testSerialization() {
    $this
      ->drupalGet('/vocabulary_serialization_test/test');
    $this
      ->assertSession()
      ->statusCodeEquals(200);
    $this
      ->assertSame('this is the output', $this
      ->getSession()
      ->getPage()
      ->getContent());
    $this
      ->assertSession()
      ->responseHeaderEquals('X-Drupal-Cache', 'MISS');
    $this
      ->drupalGet('/vocabulary_serialization_test/test');
    $this
      ->assertSession()
      ->statusCodeEquals(200);
    $this
      ->assertSame('this is the output', $this
      ->getSession()
      ->getPage()
      ->getContent());
    $this
      ->assertSession()
      ->responseHeaderEquals('X-Drupal-Cache', 'HIT');
  }

}

Members