/** * Tests translating a non-revisionable field. */ function testTranslatingNonRevisionableField() { /** @var \Drupal\Core\Entity\ContentEntityBase $entity */ $entity = EntityTestMulRev::create(); $entity->set('non_rev_field', 'Hello'); $entity->save(); $translation = $entity->addTranslation('es'); $translation->set('non_rev_field', 'Hola'); $translation->save(); $reloaded = EntityTestMulRev::load($entity->id()); $this->assertEquals('Hello', $reloaded->getTranslation('en')->get('non_rev_field')->value); $this->assertEquals('Hola', $reloaded->getTranslation('es')->get('non_rev_field')->value); }
/** * Test forward-revisions. */ 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']); }