VocabularySerializationTest.php 1.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<?php

namespace Drupal\Tests\taxonomy\Functional;

use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\BrowserTestBase;

/**
 * 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
 */
class VocabularySerializationTest extends BrowserTestBase {

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

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    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');
  }

}