Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['revision_id'] = BaseFieldDefinition::create('integer')->setLabel(t('Revision ID'))->setDescription(t('The version id of the test entity.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['langcode']->setRevisionable(TRUE);
     $fields['name']->setRevisionable(TRUE);
     $fields['user_id']->setRevisionable(TRUE);
     $fields['changed']->setRevisionable(TRUE);
     return $fields;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['revision_id'] = BaseFieldDefinition::create('integer')->setLabel(t('Revision ID'))->setDescription(t('The version id of the test entity.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean')->setLabel(t('Revision translation affected'))->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))->setReadOnly(TRUE)->setRevisionable(TRUE)->setTranslatable(TRUE);
     $fields['langcode']->setRevisionable(TRUE);
     $fields['name']->setRevisionable(TRUE);
     $fields['user_id']->setRevisionable(TRUE);
     $fields['changed']->setRevisionable(TRUE);
     return $fields;
 }
 /**
  * Tests basic EntityChangedInterface functionality.
  */
 public function testChanged()
 {
     $user1 = $this->createUser();
     $user2 = $this->createUser();
     // Create a test entity.
     $entity = EntityTestMulChanged::create(array('name' => $this->randomString(), 'user_id' => $user1->id(), 'language' => 'en'));
     $entity->save();
     $this->assertTrue($entity->getChangedTime() >= REQUEST_TIME, 'Changed time of original language is valid.');
     // We can't assert equality here because the created time is set to the
     // request time, while instances of ChangedTestItem use the current
     // timestamp every time. Therefor we check if the changed timestamp is
     // between the created time and now.
     $this->assertTrue($entity->getChangedTime() >= $entity->get('created')->value && $entity->getChangedTime() - $entity->get('created')->value <= time() - REQUEST_TIME, 'Changed and created time of original language can be assumed to be identical.');
     $this->assertEqual($entity->getChangedTime(), $entity->getChangedTimeAcrossTranslations(), 'Changed time of original language is the same as changed time across all translations.');
     $changed_en = $entity->getChangedTime();
     /** @var \Drupal\entity_test\Entity\EntityTestMulRevChanged $german */
     $german = $entity->addTranslation('de');
     $entity->save();
     $this->assertEqual($entity->getChangedTime(), $changed_en, 'Changed time of original language did not change.');
     $this->assertTrue($german->getChangedTime() > $entity->getChangedTime(), 'Changed time of the German translation is newer then the original language.');
     $this->assertEqual($german->getChangedTime(), $entity->getChangedTimeAcrossTranslations(), 'Changed time of the German translation is the newest time across all translations.');
     $changed_de = $german->getChangedTime();
     $entity->save();
     $this->assertEqual($entity->getChangedTime(), $changed_en, 'Changed time of original language did not change.');
     $this->assertEqual($german->getChangedTime(), $changed_de, 'Changed time of the German translation did not change.');
     $entity->setOwner($user2);
     $entity->save();
     $this->assertTrue($entity->getChangedTime() > $changed_en, 'Changed time of original language did change.');
     $this->assertEqual($german->getChangedTime(), $changed_de, 'Changed time of the German translation did not change.');
     $this->assertTrue($entity->getChangedTime() > $german->getChangedTime(), 'Changed time of original language is newer then the German translation.');
     $this->assertEqual($entity->getChangedTime(), $entity->getChangedTimeAcrossTranslations(), 'Changed time of the original language is the newest time across all translations.');
     $changed_en = $entity->getChangedTime();
     // Save entity without any changes.
     $entity->save();
     $this->assertEqual($entity->getChangedTime(), $changed_en, 'Changed time of original language did not change.');
     $this->assertEqual($german->getChangedTime(), $changed_de, 'Changed time of the German translation did not change.');
     // At this point the changed time of the original language (en) is newer
     // than the changed time of the German translation. Now test that entity
     // queries work as expected.
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_en)->execute();
     $this->assertEqual(reset($ids), $entity->id(), 'Entity query can access changed time of original language.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_en, '=', 'en')->execute();
     $this->assertEqual(reset($ids), $entity->id(), 'Entity query can access changed time of original language by setting the original language as condition.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_de, '=', 'en')->execute();
     $this->assertFalse($ids, 'There\'s no original entity stored having the changed time of the German translation.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_en)->condition('default_langcode', '1')->execute();
     $this->assertEqual(reset($ids), $entity->id(), 'Entity query can access changed time of default language.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_de)->condition('default_langcode', '1')->execute();
     $this->assertFalse($ids, 'There\'s no entity stored using the default language having the changed time of the German translation.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_de)->execute();
     $this->assertEqual(reset($ids), $entity->id(), 'Entity query can access changed time of the German translation.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_de, '=', 'de')->execute();
     $this->assertEqual(reset($ids), $entity->id(), 'Entity query can access changed time of the German translation.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_en, '=', 'de')->execute();
     $this->assertFalse($ids, 'There\'s no German translation stored having the changed time of the original language.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_de, '>')->execute();
     $this->assertEqual(reset($ids), $entity->id(), 'Entity query can access changed time regardless of translation.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_en, '<')->execute();
     $this->assertEqual(reset($ids), $entity->id(), 'Entity query can access changed time regardless of translation.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', 0, '>')->execute();
     $this->assertEqual(reset($ids), $entity->id(), 'Entity query can access changed time regardless of translation.');
     $query = $this->mulChangedStorage->getQuery();
     $ids = $query->condition('changed', $changed_en, '>')->execute();
     $this->assertFalse($ids, 'Entity query can access changed time regardless of translation.');
 }
 /**
  * Tests views data generated for relationship.
  *
  * @see entity_reference_field_views_data()
  */
 public function testDataTableRelationshipWithLongFieldName()
 {
     // Create some test entities which link each other.
     $referenced_entity = EntityTest::create();
     $referenced_entity->save();
     $entity = EntityTestMulChanged::create();
     $entity->field_test_data_with_a_long_name->target_id = $referenced_entity->id();
     $entity->save();
     $this->entities[] = $entity;
     $entity = EntityTestMulChanged::create();
     $entity->field_test_data_with_a_long_name->target_id = $referenced_entity->id();
     $entity->save();
     $this->entities[] = $entity;
     Views::viewsData()->clear();
     // Check an actual test view.
     $view = Views::getView('test_entity_reference_entity_test_view_long');
     $this->executeView($view);
     /** @var \Drupal\views\ResultRow $row */
     foreach ($view->result as $index => $row) {
         // Check that the actual ID of the entity is the expected one.
         $this->assertEqual($row->id, $this->entities[$index]->id());
         // Also check that we have the correct result entity.
         $this->assertEqual($row->_entity->id(), $this->entities[$index]->id());
         // Test the forward relationship.
         //$this->assertEqual($row->entity_test_entity_test_mul__field_data_test_id, 1);
         // Test that the correct relationship entity is on the row.
         $this->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']->id(), 1);
         $this->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']->bundle(), 'entity_test');
     }
 }