You are here

public function EntityQueryTest::testForwardRevisions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityQueryTest.php \Drupal\system\Tests\Entity\EntityQueryTest::testForwardRevisions()

Test forward-revisions.

File

core/modules/system/src/Tests/Entity/EntityQueryTest.php, line 813
Contains \Drupal\system\Tests\Entity\EntityQueryTest.

Class

EntityQueryTest
Tests Entity Query functionality.

Namespace

Drupal\system\Tests\Entity

Code

public function testForwardRevisions() {

  // Ensure entity 14 is returned.
  $result = \Drupal::entityQuery('entity_test_mulrev')
    ->condition('id', [
    14,
  ], 'IN')
    ->execute();
  $this
    ->assertEqual(count($result), 1);

  // Set a revision on entity 14 that isn't the current default.
  $entity = EntityTestMulRev::load(14);
  $current_values = $entity->{$this->figures}
    ->getValue();
  $entity
    ->setNewRevision(TRUE);
  $entity
    ->isDefaultRevision(FALSE);
  $entity->{$this->figures}
    ->setValue([
    'color' => 'red',
    'shape' => 'square',
  ]);
  $entity
    ->save();

  // Entity query should still return entity 14.
  $result = \Drupal::entityQuery('entity_test_mulrev')
    ->condition('id', [
    14,
  ], 'IN')
    ->execute();
  $this
    ->assertEqual(count($result), 1);

  // Verify that field conditions on the default and forward revision are
  // work as expected.
  $result = \Drupal::entityQuery('entity_test_mulrev')
    ->condition('id', [
    14,
  ], 'IN')
    ->condition("{$this->figures}.color", $current_values[0]['color'])
    ->execute();
  $this
    ->assertEqual($result, [
    14 => '14',
  ]);
  $result = $this->factory
    ->get('entity_test_mulrev')
    ->condition('id', [
    14,
  ], 'IN')
    ->condition("{$this->figures}.color", 'red')
    ->allRevisions()
    ->execute();
  $this
    ->assertEqual($result, [
    16 => '14',
  ]);
}