/**
  * Tests the translation values when saving a forward revision.
  */
 public function testTranslationValuesWhenSavingForwardRevisions()
 {
     $user = $this->createUser();
     $storage = $this->entityManager->getStorage('entity_test_mulrev');
     // Create a test entity and a translation for it.
     $entity = EntityTestMulRev::create(['name' => 'default revision - en', 'user_id' => $user->id(), 'language' => 'en']);
     $entity->addTranslation('de', ['name' => 'default revision - de']);
     $entity->save();
     // Create a forward revision for the entity and change a field value for
     // both languages.
     $forward_revision = $this->reloadEntity($entity);
     $forward_revision->setNewRevision();
     $forward_revision->isDefaultRevision(FALSE);
     $forward_revision->name = 'forward revision - en';
     $forward_revision->save();
     $forward_revision_translation = $forward_revision->getTranslation('de');
     $forward_revision_translation->name = 'forward revision - de';
     $forward_revision_translation->save();
     $forward_revision_id = $forward_revision->getRevisionId();
     $forward_revision = $storage->loadRevision($forward_revision_id);
     // Change the value of the field in the default language, save the forward
     // revision and check that the value of the field in the second language is
     // also taken from the forward revision, *not* from the default revision.
     $forward_revision->name = 'updated forward revision - en';
     $forward_revision->save();
     $forward_revision = $storage->loadRevision($forward_revision_id);
     $this->assertEquals($forward_revision->name->value, 'updated forward revision - en');
     $this->assertEquals($forward_revision->getTranslation('de')->name->value, 'forward revision - de');
 }
 /**
  * Tests non-revisionable fields on revisionable and translatable entities.
  */
 public function testMulNonRevisionableField()
 {
     $user1 = $this->createUser();
     $user2 = $this->createUser();
     // Create a test entity.
     $entity = EntityTestMulRev::create(array('name' => $this->randomString(), 'user_id' => $user1->id(), 'language' => 'en', 'non_rev_field' => 'Huron'));
     $entity->save();
     // Create a test entity.
     $entity2 = EntityTestMulRev::create(array('name' => $this->randomString(), 'user_id' => $user1->id(), 'language' => 'en', 'non_rev_field' => 'Michigan'));
     $entity2->save();
     $this->assertEquals('Huron', $entity->get('non_rev_field')->value, 'Huron found on entity 1');
     $this->assertEquals('Michigan', $entity2->get('non_rev_field')->value, 'Michigan found on entity 2');
     $entity->setNewRevision();
     $entity->setOwner($user2);
     $entity->save();
     $entity2->setNewRevision();
     $entity2->setOwner($user2);
     $entity2->save();
     $this->assertEquals($user2->id(), $entity->getOwner()->id(), 'User 2 found on entity 1');
     $this->assertEquals($user2->id(), $entity2->getOwner()->id(), 'User 2 found on entity 2');
     $entity->addTranslation('de');
     $entity->save();
     $entity2->addTranslation('de');
     $entity2->save();
     $expected_revision_ids = [4 => 2, 3 => 1, 2 => 2, 1 => 1];
     $revision_ids = $this->mulRev->getQuery()->allRevisions()->sort('revision_id', 'DESC')->execute();
     $this->assertEquals($expected_revision_ids, $revision_ids, 'Revision ids found');
     $expected_non_rev_field_revision_ids = [3 => 1, 1 => 1];
     $non_rev_field_revision_ids = $this->mulRev->getQuery()->allRevisions()->condition('non_rev_field', 'Huron')->sort('revision_id', 'DESC')->execute();
     $this->assertEquals($expected_non_rev_field_revision_ids, $non_rev_field_revision_ids, 'Revision ids found');
 }
 /**
  * Tests if the translation object has the right revision id after new revision.
  */
 public function testNewRevisionAfterTranslation()
 {
     $user = $this->createUser();
     // Create a test entity.
     $entity = EntityTestMulRev::create(['name' => $this->randomString(), 'user_id' => $user->id(), 'language' => 'en']);
     $entity->save();
     $old_rev_id = $entity->getRevisionId();
     $translation = $entity->addTranslation('de');
     $translation->setNewRevision();
     $translation->save();
     $this->assertTrue($translation->getRevisionId() > $old_rev_id, 'The saved translation in new revision has a newer revision id.');
     $this->assertTrue($this->reloadEntity($entity)->getRevisionId() > $old_rev_id, 'The entity from the storage has a newer revision id.');
 }
 /**
  * Test that fields referencing UUIDs can be denormalized.
  */
 function testUuidEntityResolver()
 {
     // Create an entity to get the UUID from.
     $entity = EntityTestMulRev::create(array('type' => 'entity_test_mulrev'));
     $entity->set('name', 'foobar');
     $entity->set('field_test_entity_reference', array(array('target_id' => 1)));
     $entity->save();
     $field_uri = Url::fromUri('base:rest/relation/entity_test_mulrev/entity_test_mulrev/field_test_entity_reference', array('absolute' => TRUE))->toString();
     $data = array('_links' => array('type' => array('href' => Url::fromUri('base:rest/type/entity_test_mulrev/entity_test_mulrev', array('absolute' => TRUE))->toString()), $field_uri => array(array('href' => $entity->url()))), '_embedded' => array($field_uri => array(array('_links' => array('self' => $entity->url()), 'uuid' => array(array('value' => $entity->uuid()))))));
     $denormalized = $this->container->get('serializer')->denormalize($data, 'Drupal\\entity_test\\Entity\\EntityTestMulRev', $this->format);
     $field_value = $denormalized->get('field_test_entity_reference')->getValue();
     $this->assertEqual($field_value[0]['target_id'], 1, 'Entity reference resolved using UUID.');
 }
 /**
  * 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);
 }
Esempio n. 6
0
 /**
  * Tests the field item save workflow.
  */
 public function testSaveWorkflow()
 {
     $entity = EntityTestMulRev::create(['name' => $this->randomString(), 'field_test_item' => $this->randomString(), $this->fieldName => $this->randomString()]);
     // Save a new entity and verify that the initial field value is overwritten
     // with a value containing the entity id, which implies a resave. Check that
     // the entity data structure and the stored values match.
     $this->assertSavedFieldItemValue($entity, "field_test:{$this->fieldName}:1:1");
     // Update the entity and verify that the field value is overwritten on
     // presave if it is not resaved.
     $this->assertSavedFieldItemValue($entity, 'overwritten');
     // Flag the field value as needing to be resaved and verify it actually is.
     $entity->field_test_item->value = $entity->{$this->fieldName}->value = 'resave';
     $this->assertSavedFieldItemValue($entity, "field_test:{$this->fieldName}:1:3");
 }
 protected function setUp()
 {
     parent::setUp();
     // User create needs sequence table.
     $this->installSchema('system', array('sequences'));
     // Create a test user to use as the entity owner.
     $this->user = \Drupal::entityManager()->getStorage('user')->create(['name' => 'serialization_test_user', 'mail' => '*****@*****.**', 'pass' => '123456']);
     $this->user->save();
     // Create a test entity to serialize.
     $this->values = array('name' => $this->randomMachineName(), 'user_id' => $this->user->id(), 'field_test_text' => array('value' => $this->randomMachineName(), 'format' => 'full_html'));
     $this->entity = EntityTestMulRev::create($this->values);
     $this->entity->save();
     $this->serializer = $this->container->get('serializer');
     $this->installConfig(array('field'));
 }
 /**
  * Tests if the translation object has the right revision id after new revision.
  */
 public function testRevertRevisionAfterTranslation()
 {
     $user = $this->createUser();
     $storage = $this->entityManager->getStorage('entity_test_mulrev');
     // Create a test entity.
     $entity = EntityTestMulRev::create(['name' => $this->randomString(), 'user_id' => $user->id(), 'language' => 'en']);
     $entity->save();
     $old_rev_id = $entity->getRevisionId();
     $translation = $entity->addTranslation('de');
     $translation->setNewRevision();
     $translation->save();
     $entity = $this->reloadEntity($entity);
     $this->assertTrue($entity->hasTranslation('de'));
     $entity = $storage->loadRevision($old_rev_id);
     $entity->setNewRevision();
     $entity->isDefaultRevision(TRUE);
     $entity->save();
     $entity = $this->reloadEntity($entity);
     $this->assertFalse($entity->hasTranslation('de'));
 }
 /**
  * Check that field translatability is handled properly.
  */
 function testFieldDefinitions()
 {
     // Check that field translatability can be altered to be enabled or disabled
     // in field definitions.
     $entity_type = 'entity_test_mulrev';
     $this->state->set('entity_test.field_definitions.translatable', array('name' => FALSE));
     $this->entityManager->clearCachedFieldDefinitions();
     $definitions = $this->entityManager->getBaseFieldDefinitions($entity_type);
     $this->assertFalse($definitions['name']->isTranslatable(), 'Field translatability can be disabled programmatically.');
     $this->state->set('entity_test.field_definitions.translatable', array('name' => TRUE));
     $this->entityManager->clearCachedFieldDefinitions();
     $definitions = $this->entityManager->getBaseFieldDefinitions($entity_type);
     $this->assertTrue($definitions['name']->isTranslatable(), 'Field translatability can be enabled programmatically.');
     // Check that field translatability is disabled by default.
     $base_field_definitions = EntityTestMulRev::baseFieldDefinitions($this->entityManager->getDefinition($entity_type));
     $this->assertTrue(!isset($base_field_definitions['id']->translatable), 'Translatability for the <em>id</em> field is not defined.');
     $this->assertFalse($definitions['id']->isTranslatable(), 'Field translatability is disabled by default.');
     // Check that entity ids and langcode fields cannot be translatable.
     foreach (array('id', 'uuid', 'revision_id', 'type', 'langcode') as $name) {
         $this->state->set('entity_test.field_definitions.translatable', array($name => TRUE));
         $this->entityManager->clearCachedFieldDefinitions();
         $message = format_string('Field %field cannot be translatable.', array('%field' => $name));
         try {
             $this->entityManager->getBaseFieldDefinitions($entity_type);
             $this->fail($message);
         } catch (\LogicException $e) {
             $this->pass($message);
         }
     }
 }
Esempio n. 10
0
 /**
  * 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']);
 }
Esempio n. 11
0
 /**
  * Tests fields on the revision table.
  */
 public function testRevisionTableFields()
 {
     $entity_type = $this->baseEntityType->set('base_table', 'entity_test_mulrev')->set('revision_table', 'entity_test_mulrev_revision')->set('data_table', 'entity_test_mulrev_property_data')->set('revision_data_table', 'entity_test_mulrev_property_revision')->set('id', 'entity_test_mulrev')->set('translatable', TRUE);
     $base_field_definitions = $this->setupBaseFields(EntityTestMulRev::baseFieldDefinitions($this->baseEntityType));
     $user_base_field_definitions = ['uid' => BaseFieldDefinition::create('integer')->setLabel('ID')->setDescription('The ID of the user entity.')->setReadOnly(TRUE)->setSetting('unsigned', TRUE)];
     $this->entityManager->expects($this->any())->method('getBaseFieldDefinitions')->will($this->returnValueMap([['user', $user_base_field_definitions], ['entity_test_mulrev', $base_field_definitions]]));
     $this->viewsData->setEntityType($entity_type);
     // Setup the table mapping.
     $table_mapping = $this->getMock('Drupal\\Core\\Entity\\Sql\\TableMappingInterface');
     $table_mapping->expects($this->any())->method('getTableNames')->willReturn(['entity_test_mulrev', 'entity_test_mulrev_revision', 'entity_test_mulrev_property_data', 'entity_test_mulrev_property_revision']);
     $table_mapping->expects($this->any())->method('getColumnNames')->willReturnMap([['id', ['value' => 'id']], ['uuid', ['value' => 'uuid']], ['type', ['value' => 'type']], ['langcode', ['value' => 'langcode']], ['name', ['value' => 'name']], ['description', ['value' => 'description__value', 'format' => 'description__format']], ['homepage', ['value' => 'homepage']], ['user_id', ['target_id' => 'user_id']], ['revision_id', ['value' => 'id']]]);
     $table_mapping->expects($this->any())->method('getFieldNames')->willReturnMap([['entity_test_mulrev', ['id', 'revision_id', 'uuid', 'type']], ['entity_test_mulrev_revision', ['id', 'revision_id', 'langcode']], ['entity_test_mulrev_property_data', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']], ['entity_test_mulrev_property_revision', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']]]);
     $table_mapping->expects($this->any())->method('getFieldTableName')->willReturnCallback(function ($field) {
         if ($field == 'uuid') {
             return 'entity_test_mulrev';
         }
         return 'entity_test_mulrev_property_data';
     });
     $this->entityStorage->expects($this->once())->method('getTableMapping')->willReturn($table_mapping);
     $this->setupFieldStorageDefinition();
     $data = $this->viewsData->getViewsData();
     // Check the base fields.
     $this->assertFalse(isset($data['entity_test_mulrev']['id']));
     $this->assertFalse(isset($data['entity_test_mulrev']['type']));
     $this->assertFalse(isset($data['entity_test_mulrev']['revision_id']));
     $this->assertUuidField($data['entity_test_mulrev']['uuid']);
     $this->assertField($data['entity_test_mulrev']['uuid'], 'uuid');
     // Also ensure that field_data only fields don't appear on the base table.
     $this->assertFalse(isset($data['entity_test_mulrev']['name']));
     $this->assertFalse(isset($data['entity_test_mul']['description']));
     $this->assertFalse(isset($data['entity_test_mul']['description__value']));
     $this->assertFalse(isset($data['entity_test_mul']['description__format']));
     $this->assertFalse(isset($data['entity_test_mul']['homepage']));
     $this->assertFalse(isset($data['entity_test_mulrev']['langcode']));
     $this->assertFalse(isset($data['entity_test_mulrev']['user_id']));
     // Check the revision fields. The revision ID should only appear in the data
     // table.
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['revision_id']));
     // Also ensure that field_data only fields don't appear on the revision table.
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['id']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['name']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description__value']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description__format']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['homepage']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['user_id']));
     // Check the data fields.
     $this->assertNumericField($data['entity_test_mulrev_property_data']['id']);
     $this->assertField($data['entity_test_mulrev_property_data']['id'], 'id');
     $this->assertNumericField($data['entity_test_mulrev_property_data']['revision_id']);
     $this->assertField($data['entity_test_mulrev_property_data']['revision_id'], 'revision_id');
     $this->assertLanguageField($data['entity_test_mulrev_property_data']['langcode']);
     $this->assertField($data['entity_test_mulrev_property_data']['langcode'], 'langcode');
     $this->assertStringField($data['entity_test_mulrev_property_data']['name']);
     $this->assertField($data['entity_test_mulrev_property_data']['name'], 'name');
     $this->assertLongTextField($data['entity_test_mulrev_property_data'], 'description');
     $this->assertField($data['entity_test_mulrev_property_data']['description__value'], 'description');
     $this->assertField($data['entity_test_mulrev_property_data']['description__format'], 'description');
     $this->assertUriField($data['entity_test_mulrev_property_data']['homepage']);
     $this->assertField($data['entity_test_mulrev_property_data']['homepage'], 'homepage');
     $this->assertEntityReferenceField($data['entity_test_mulrev_property_data']['user_id']);
     $this->assertField($data['entity_test_mulrev_property_data']['user_id'], 'user_id');
     $relationship = $data['entity_test_mulrev_property_data']['user_id']['relationship'];
     $this->assertEquals('users_field_data', $relationship['base']);
     $this->assertEquals('uid', $relationship['base field']);
     // Check the property data fields.
     $this->assertNumericField($data['entity_test_mulrev_property_revision']['id']);
     $this->assertField($data['entity_test_mulrev_property_revision']['id'], 'id');
     $this->assertLanguageField($data['entity_test_mulrev_property_revision']['langcode']);
     $this->assertField($data['entity_test_mulrev_property_revision']['langcode'], 'langcode');
     $this->assertEquals('Translation language', $data['entity_test_mulrev_property_revision']['langcode']['title']);
     $this->assertStringField($data['entity_test_mulrev_property_revision']['name']);
     $this->assertField($data['entity_test_mulrev_property_revision']['name'], 'name');
     $this->assertLongTextField($data['entity_test_mulrev_property_revision'], 'description');
     $this->assertField($data['entity_test_mulrev_property_revision']['description__value'], 'description');
     $this->assertField($data['entity_test_mulrev_property_revision']['description__format'], 'description');
     $this->assertUriField($data['entity_test_mulrev_property_revision']['homepage']);
     $this->assertField($data['entity_test_mulrev_property_revision']['homepage'], 'homepage');
     $this->assertEntityReferenceField($data['entity_test_mulrev_property_revision']['user_id']);
     $this->assertField($data['entity_test_mulrev_property_revision']['user_id'], 'user_id');
     $relationship = $data['entity_test_mulrev_property_revision']['user_id']['relationship'];
     $this->assertEquals('users_field_data', $relationship['base']);
     $this->assertEquals('uid', $relationship['base field']);
 }
 /**
  * Tests fields on the revision table.
  */
 public function testRevisionTableFields()
 {
     $entity_type = $this->baseEntityType->set('base_table', 'entity_test_mulrev')->set('revision_table', 'entity_test_mulrev_revision')->set('data_table', 'entity_test_mulrev_property_data')->set('revision_data_table', 'entity_test_mulrev_property_revision')->set('id', 'entity_test_mulrev');
     $base_field_definitions = $this->setupBaseFields(EntityTestMulRev::baseFieldDefinitions($this->baseEntityType));
     $this->entityManager->expects($this->once())->method('getBaseFieldDefinitions')->with('entity_test_mulrev')->willReturn($base_field_definitions);
     $this->viewsData->setEntityType($entity_type);
     // Setup the table mapping.
     $table_mapping = $this->getMock('Drupal\\Core\\Entity\\Sql\\TableMappingInterface');
     $table_mapping->expects($this->any())->method('getTableNames')->willReturn(['entity_test_mulrev', 'entity_test_mulrev_revision', 'entity_test_mulrev_property_data', 'entity_test_mulrev_property_revision']);
     $table_mapping->expects($this->any())->method('getColumnNames')->willReturnMap([['id', ['value' => 'id']], ['uuid', ['value' => 'uuid']], ['type', ['value' => 'type']], ['langcode', ['value' => 'langcode']], ['name', ['value' => 'name']], ['description', ['value' => 'description__value', 'format' => 'description__format']], ['homepage', ['value' => 'homepage']], ['user_id', ['target_id' => 'user_id']], ['revision_id', ['value' => 'id']]]);
     $table_mapping->expects($this->any())->method('getFieldNames')->willReturnMap([['entity_test_mulrev', ['id', 'revision_id', 'uuid', 'type']], ['entity_test_mulrev_revision', ['id', 'revision_id', 'langcode']], ['entity_test_mulrev_property_data', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']], ['entity_test_mulrev_property_revision', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']]]);
     $this->entityStorage->expects($this->once())->method('getTableMapping')->willReturn($table_mapping);
     $this->setupFieldStorageDefinition();
     $data = $this->viewsData->getViewsData();
     // Check the base fields.
     $this->assertNumericField($data['entity_test_mulrev']['id']);
     $this->assertNumericField($data['entity_test_mulrev']['revision_id']);
     $this->assertUuidField($data['entity_test_mulrev']['uuid']);
     $this->assertStringField($data['entity_test_mulrev']['type']);
     // Also ensure that field_data only fields don't appear on the base table.
     $this->assertFalse(isset($data['entity_test_mulrev']['name']));
     $this->assertFalse(isset($data['entity_test_mul']['description']));
     $this->assertFalse(isset($data['entity_test_mul']['description__value']));
     $this->assertFalse(isset($data['entity_test_mul']['description__format']));
     $this->assertFalse(isset($data['entity_test_mul']['homepage']));
     $this->assertFalse(isset($data['entity_test_mulrev']['langcode']));
     $this->assertFalse(isset($data['entity_test_mulrev']['user_id']));
     // Check the revision fields.
     $this->assertNumericField($data['entity_test_mulrev_revision']['id']);
     $this->assertNumericField($data['entity_test_mulrev_revision']['revision_id']);
     $this->assertLanguageField($data['entity_test_mulrev_revision']['langcode']);
     $this->assertEquals('Original language', $data['entity_test_mulrev_revision']['langcode']['title']);
     // Also ensure that field_data only fields don't appear on the revision table.
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['name']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description__value']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description__format']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['homepage']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['user_id']));
     // Check the data fields.
     $this->assertNumericField($data['entity_test_mulrev_property_data']['id']);
     $this->assertLanguageField($data['entity_test_mulrev_property_data']['langcode']);
     $this->assertStringField($data['entity_test_mulrev_property_data']['name']);
     $this->assertLongTextField($data['entity_test_mulrev_property_data'], 'description');
     $this->assertUriField($data['entity_test_mulrev_property_data']['homepage']);
     $this->assertEntityReferenceField($data['entity_test_mulrev_property_data']['user_id']);
     $relationship = $data['entity_test_mulrev_property_data']['user_id']['relationship'];
     $this->assertEquals('users', $relationship['base']);
     $this->assertEquals('uid', $relationship['base field']);
     // Check the property data fields.
     $this->assertNumericField($data['entity_test_mulrev_property_revision']['id']);
     $this->assertLanguageField($data['entity_test_mulrev_property_revision']['langcode']);
     $this->assertEquals('Translation language', $data['entity_test_mulrev_property_revision']['langcode']['title']);
     $this->assertStringField($data['entity_test_mulrev_property_revision']['name']);
     $this->assertLongTextField($data['entity_test_mulrev_property_revision'], 'description');
     $this->assertUriField($data['entity_test_mulrev_property_revision']['homepage']);
     $this->assertEntityReferenceField($data['entity_test_mulrev_property_revision']['user_id']);
     $relationship = $data['entity_test_mulrev_property_revision']['user_id']['relationship'];
     $this->assertEquals('users', $relationship['base']);
     $this->assertEquals('uid', $relationship['base field']);
 }
Esempio n. 13
0
 /**
  * Tests that an entity revision is upcasted in the correct language.
  */
 public function testEntityRevisionParamConverter()
 {
     // Create a test entity with multiple revisions and translations for them.
     $entity = EntityTestMulRev::create(['name' => 'default revision - en', 'user_id' => $this->webUser, 'language' => 'en']);
     $entity->addTranslation('de', ['name' => 'default revision - de']);
     $entity->save();
     $forward_revision = \Drupal::entityTypeManager()->getStorage('entity_test_mulrev')->loadUnchanged($entity->id());
     $forward_revision->setNewRevision();
     $forward_revision->isDefaultRevision(FALSE);
     $forward_revision->name = 'forward revision - en';
     $forward_revision->save();
     $forward_revision_translation = $forward_revision->getTranslation('de');
     $forward_revision_translation->name = 'forward revision - de';
     $forward_revision_translation->save();
     // Check that the entity revision is upcasted in the correct language.
     $revision_url = 'entity_test_mulrev/' . $entity->id() . '/revision/' . $forward_revision->getRevisionId() . '/view';
     $this->drupalGet($revision_url);
     $this->assertText('forward revision - en');
     $this->assertNoText('forward revision - de');
     $this->drupalGet('de/' . $revision_url);
     $this->assertText('forward revision - de');
     $this->assertNoText('forward revision - en');
 }
 /**
  * Tests multi column non revisionable base field for revisionable entity.
  */
 public function testMultiColumnNonRevisionableBaseField()
 {
     \Drupal::state()->set('entity_test.multi_column', TRUE);
     \Drupal::entityDefinitionUpdateManager()->applyUpdates();
     // Refresh the storage.
     $this->mulRev = $this->entityManager->getStorage('entity_test_mulrev');
     $user1 = $this->createUser();
     // Create a test entity.
     $entity = EntityTestMulRev::create(['name' => $this->randomString(), 'user_id' => $user1->id(), 'language' => 'en', 'non_rev_field' => 'Huron', 'description' => ['shape' => 'shape', 'color' => 'color']]);
     $entity->save();
     $entity = $this->mulRev->loadUnchanged($entity->id());
     $expected = [['shape' => 'shape', 'color' => 'color']];
     $this->assertEquals('Huron', $entity->get('non_rev_field')->value, 'Huron found on entity 1');
     $this->assertEquals($expected, $entity->description->getValue());
 }
Esempio n. 15
0
 /**
  * Test case sensitive and in-sensitive query conditions.
  */
 public function testCaseSensitivity()
 {
     $bundle = $this->randomMachineName();
     $field_storage = FieldStorageConfig::create(array('field_name' => 'field_ci', 'entity_type' => 'entity_test_mulrev', 'type' => 'string', 'cardinality' => 1, 'translatable' => FALSE, 'settings' => array('case_sensitive' => FALSE)));
     $field_storage->save();
     FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => $bundle))->save();
     $field_storage = FieldStorageConfig::create(array('field_name' => 'field_cs', 'entity_type' => 'entity_test_mulrev', 'type' => 'string', 'cardinality' => 1, 'translatable' => FALSE, 'settings' => array('case_sensitive' => TRUE)));
     $field_storage->save();
     FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => $bundle))->save();
     $fixtures = array();
     for ($i = 0; $i < 2; $i++) {
         // If the last 4 of the string are all numbers, then there is no
         // difference between upper and lowercase and the case sensitive CONTAINS
         // test will fail. Ensure that can not happen by appending a non-numeric
         // character. See https://www.drupal.org/node/2397297.
         $string = $this->randomMachineName(7) . 'a';
         $fixtures[] = array('original' => $string, 'uppercase' => Unicode::strtoupper($string), 'lowercase' => Unicode::strtolower($string));
     }
     EntityTestMulRev::create(array('type' => $bundle, 'name' => $this->randomMachineName(), 'langcode' => 'en', 'field_ci' => $fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 'field_cs' => $fixtures[0]['uppercase'] . $fixtures[1]['lowercase']))->save();
     // Check the case insensitive field, = operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['lowercase'] . $fixtures[1]['lowercase'])->execute();
     $this->assertIdentical(count($result), 1, 'Case insensitive, lowercase');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['uppercase'] . $fixtures[1]['uppercase'])->execute();
     $this->assertIdentical(count($result), 1, 'Case insensitive, uppercase');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['uppercase'] . $fixtures[1]['lowercase'])->execute();
     $this->assertIdentical(count($result), 1, 'Case insensitive, mixed.');
     // Check the case sensitive field, = operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['lowercase'] . $fixtures[1]['lowercase'])->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['uppercase'] . $fixtures[1]['uppercase'])->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, uppercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['uppercase'] . $fixtures[1]['lowercase'])->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
     // Check the case insensitive field, STARTS_WITH operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['lowercase'], 'STARTS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['uppercase'], 'STARTS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
     // Check the case sensitive field, STARTS_WITH operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['lowercase'], 'STARTS_WITH')->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['uppercase'], 'STARTS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
     // Check the case insensitive field, ENDS_WITH operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[1]['lowercase'], 'ENDS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[1]['uppercase'], 'ENDS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
     // Check the case sensitive field, ENDS_WITH operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[1]['lowercase'], 'ENDS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[1]['uppercase'], 'ENDS_WITH')->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, exact match.');
     // Check the case insensitive field, CONTAINS operator, use the inner 8
     // characters of the uppercase and lowercase strings.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8), 'CONTAINS')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', Unicode::strtolower(Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8)), 'CONTAINS')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
     // Check the case sensitive field, CONTAINS operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8), 'CONTAINS')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', Unicode::strtolower(Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8)), 'CONTAINS')->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, exact match.');
 }