Issue #2723607 by valthebald, deepakaryan1988: Remove entity_load* usage for dynamic entity types
							parent
							
								
									03f46efe54
								
							
						
					
					
						commit
						ad76a96a40
					
				| 
						 | 
				
			
			@ -67,7 +67,9 @@ class EntityReference extends DataReferenceBase {
 | 
			
		|||
  public function getTarget() {
 | 
			
		||||
    if (!isset($this->target) && isset($this->id)) {
 | 
			
		||||
      // If we have a valid reference, return the entity's TypedData adapter.
 | 
			
		||||
      $entity = entity_load($this->getTargetDefinition()->getEntityTypeId(), $this->id);
 | 
			
		||||
      $entity = \Drupal::entityTypeManager()
 | 
			
		||||
        ->getStorage($this->getTargetDefinition()->getEntityTypeId())
 | 
			
		||||
        ->load($this->id);
 | 
			
		||||
      $this->target = isset($entity) ? $entity->getTypedData() : NULL;
 | 
			
		||||
    }
 | 
			
		||||
    return $this->target;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -179,7 +179,10 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationEdit() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -146,7 +146,10 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestAuthoringInfo() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
    $values = array();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -166,7 +169,8 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
      $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
      $metadata = $this->manager->getTranslationMetadata($entity->getTranslation($langcode));
 | 
			
		||||
      $this->assertEqual($metadata->getAuthor()->id(), $values[$langcode]['uid'], 'Translation author correctly stored.');
 | 
			
		||||
| 
						 | 
				
			
			@ -195,7 +199,10 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationEdit() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -412,7 +412,8 @@ function content_translation_entity_presave(EntityInterface $entity) {
 | 
			
		|||
    // as original language, since source values are the only ones available to
 | 
			
		||||
    // compare against.
 | 
			
		||||
    if (!isset($entity->original)) {
 | 
			
		||||
      $entity->original = entity_load_unchanged($entity->entityType(), $entity->id());
 | 
			
		||||
      $entity->original = \Drupal::entityTypeManager()
 | 
			
		||||
        ->getStorage($entity->entityType())->loadUnchanged($entity->id());
 | 
			
		||||
    }
 | 
			
		||||
    $langcode = $entity->language()->getId();
 | 
			
		||||
    /** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -77,7 +77,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
    $this->drupalLogin($this->editor);
 | 
			
		||||
    $this->entityId = $this->createEntity($values[$default_langcode], $default_langcode);
 | 
			
		||||
    $this->drupalLogin($this->translator);
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $this->assertTrue($entity, 'Entity found in the database.');
 | 
			
		||||
    $this->drupalGet($entity->urlInfo());
 | 
			
		||||
    $this->assertResponse(200, 'Entity URL is valid.');
 | 
			
		||||
| 
						 | 
				
			
			@ -119,7 +122,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
 | 
			
		||||
    // Ensure that the content language cache context is not yet added to the
 | 
			
		||||
    // page.
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $this->drupalGet($entity->urlInfo());
 | 
			
		||||
    $this->assertCacheContexts(Cache::mergeContexts(['languages:language_content'], $this->defaultCacheContexts));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -154,7 +160,8 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
    if ($this->testLanguageSelector) {
 | 
			
		||||
      $this->assertNoFieldByXPath('//select[@id="edit-langcode-0-value"]', NULL, 'Language selector correctly disabled on translations.');
 | 
			
		||||
    }
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $this->drupalGet($entity->urlInfo('drupal:content-translation-overview'));
 | 
			
		||||
    $this->assertNoText('Source language', 'Source language column correctly hidden.');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -184,7 +191,8 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
      'target' => $langcode
 | 
			
		||||
    ], array('language' => $language));
 | 
			
		||||
    $this->drupalPostForm($add_url, $edit, $this->getFormSubmitActionForNewTranslation($entity, $langcode));
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $this->drupalGet($entity->urlInfo('drupal:content-translation-overview'));
 | 
			
		||||
    $this->assertText('Source language', 'Source language column correctly shown.');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -204,7 +212,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
   * Tests that the translation overview shows the correct values.
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationOverview() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $translate_url = $entity->urlInfo('drupal:content-translation-overview');
 | 
			
		||||
    $this->drupalGet($translate_url);
 | 
			
		||||
    $translate_url->setAbsolute(FALSE);
 | 
			
		||||
| 
						 | 
				
			
			@ -226,7 +237,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
   * Tests up-to-date status tracking.
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestOutdatedStatus() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $langcode = 'fr';
 | 
			
		||||
    $languages = \Drupal::languageManager()->getLanguages();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -234,7 +248,8 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
    $edit = array('content_translation[retranslate]' => TRUE);
 | 
			
		||||
    $edit_path = $entity->urlInfo('edit-form', array('language' => $languages[$langcode]));
 | 
			
		||||
    $this->drupalPostForm($edit_path, $edit, $this->getFormSubmitAction($entity, $langcode));
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
 | 
			
		||||
    // Check that every translation has the correct "outdated" status, and that
 | 
			
		||||
    // the Translation fieldset is open if the translation is "outdated".
 | 
			
		||||
| 
						 | 
				
			
			@ -252,7 +267,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
        $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $added_langcode));
 | 
			
		||||
        $this->drupalGet($url);
 | 
			
		||||
        $this->assertFieldByXPath('//input[@name="content_translation[retranslate]"]', FALSE, 'The retranslate flag is now shown.');
 | 
			
		||||
        $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
        $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
          ->getStorage($this->entityTypeId);
 | 
			
		||||
        $storage->resetCache([$this->entityId]);
 | 
			
		||||
        $entity = $storage->load($this->entityId);
 | 
			
		||||
        $this->assertFalse($this->manager->getTranslationMetadata($entity->getTranslation($added_langcode))->isOutdated(), 'The "outdated" status has been correctly stored.');
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -262,7 +280,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
   * Tests the translation publishing status.
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestPublishedStatus() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
 | 
			
		||||
    // Unpublish translations.
 | 
			
		||||
    foreach ($this->langcodes as $index => $langcode) {
 | 
			
		||||
| 
						 | 
				
			
			@ -270,7 +291,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
        $url = $entity->urlInfo('edit-form', array('language' => ConfigurableLanguage::load($langcode)));
 | 
			
		||||
        $edit = array('content_translation[status]' => FALSE);
 | 
			
		||||
        $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode));
 | 
			
		||||
        $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
        $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
          ->getStorage($this->entityTypeId);
 | 
			
		||||
        $storage->resetCache([$this->entityId]);
 | 
			
		||||
        $entity = $storage->load($this->entityId);
 | 
			
		||||
        $this->assertFalse($this->manager->getTranslationMetadata($entity->getTranslation($langcode))->isPublished(), 'The translation has been correctly unpublished.');
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -284,7 +308,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
   * Tests the translation authoring information.
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestAuthoringInfo() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $values = array();
 | 
			
		||||
 | 
			
		||||
    // Post different authoring information for each translation.
 | 
			
		||||
| 
						 | 
				
			
			@ -302,7 +329,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
      $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
      $metadata = $this->manager->getTranslationMetadata($entity->getTranslation($langcode));
 | 
			
		||||
      $this->assertEqual($metadata->getAuthor()->id(), $values[$langcode]['uid'], 'Translation author correctly stored.');
 | 
			
		||||
| 
						 | 
				
			
			@ -330,12 +360,16 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
    // Confirm and delete a translation.
 | 
			
		||||
    $this->drupalLogin($this->translator);
 | 
			
		||||
    $langcode = 'fr';
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $language = ConfigurableLanguage::load($langcode);
 | 
			
		||||
    $url = $entity->urlInfo('edit-form', array('language' => $language));
 | 
			
		||||
    $this->drupalPostForm($url, array(), t('Delete translation'));
 | 
			
		||||
    $this->drupalPostForm(NULL, array(), t('Delete @language translation', array('@language' => $language->getName())));
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId, TRUE);
 | 
			
		||||
    if ($this->assertTrue(is_object($entity), 'Entity found')) {
 | 
			
		||||
      $translations = $entity->getTranslationLanguages();
 | 
			
		||||
      $this->assertTrue(count($translations) == 2 && empty($translations[$langcode]), 'Translation successfully deleted.');
 | 
			
		||||
| 
						 | 
				
			
			@ -465,7 +499,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
   * Tests edit content translation.
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationEdit() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
| 
						 | 
				
			
			@ -484,7 +521,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
   * Tests the basic translation workflow.
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationChanged() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $changed_field_name = $this->getChangedFieldName($entity);
 | 
			
		||||
    $definition = $entity->getFieldDefinition($changed_field_name);
 | 
			
		||||
    $config = $definition->getConfig($entity->bundle());
 | 
			
		||||
| 
						 | 
				
			
			@ -517,7 +557,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
        $edit_path = $entity->urlInfo('edit-form', array('language' => $language));
 | 
			
		||||
        $this->drupalPostForm($edit_path, $edit, $this->getFormSubmitAction($entity, $langcode));
 | 
			
		||||
 | 
			
		||||
        $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
        $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
          ->getStorage($this->entityTypeId);
 | 
			
		||||
        $storage->resetCache([$this->entityId]);
 | 
			
		||||
        $entity = $storage->load($this->entityId);
 | 
			
		||||
        $this->assertEqual(
 | 
			
		||||
          $entity->getChangedTimeAcrossTranslations(), $entity->getTranslation($langcode)->getChangedTime(),
 | 
			
		||||
          format_string('Changed time for language %language is the latest change over all languages.', array('%language' => $language->getName()))
 | 
			
		||||
| 
						 | 
				
			
			@ -551,13 +594,19 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
   * Test the changed time after API and FORM save without changes.
 | 
			
		||||
   */
 | 
			
		||||
  public function doTestChangedTimeAfterSaveWithoutChanges() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    // Test only entities, which implement the EntityChangedInterface.
 | 
			
		||||
    if ($entity->getEntityType()->isSubclassOf('Drupal\Core\Entity\EntityChangedInterface')) {
 | 
			
		||||
      $changed_timestamp = $entity->getChangedTime();
 | 
			
		||||
 | 
			
		||||
      $entity->save();
 | 
			
		||||
      $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
      $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
        ->getStorage($this->entityTypeId);
 | 
			
		||||
      $storage->resetCache([$this->entityId]);
 | 
			
		||||
      $entity = $storage->load($this->entityId);
 | 
			
		||||
      $this->assertEqual($changed_timestamp, $entity->getChangedTime(), 'The entity\'s changed time wasn\'t updated after API save without changes.');
 | 
			
		||||
 | 
			
		||||
      // Ensure different save timestamps.
 | 
			
		||||
| 
						 | 
				
			
			@ -568,7 +617,8 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
 | 
			
		|||
      $edit_path = $entity->urlInfo('edit-form', array('language' => $language));
 | 
			
		||||
      $this->drupalPostForm($edit_path, [], $this->getFormSubmitAction($entity, $language->getId()));
 | 
			
		||||
 | 
			
		||||
      $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
      $storage->resetCache([$this->entityId]);
 | 
			
		||||
      $entity = $storage->load($this->entityId);
 | 
			
		||||
      $this->assertNotEqual($changed_timestamp, $entity->getChangedTime(), 'The entity\'s changed time was updated after form save without changes.');
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -64,7 +64,10 @@ class ContentTranslationWorkflowsTest extends ContentTranslationTestBase {
 | 
			
		|||
      $this->fieldName => array(array('value' => $this->randomMachineName(16))),
 | 
			
		||||
    );
 | 
			
		||||
    $id = $this->createEntity($values, $default_langcode);
 | 
			
		||||
    $this->entity = entity_load($this->entityTypeId, $id, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$id]);
 | 
			
		||||
    $this->entity = $storage->load($id);
 | 
			
		||||
 | 
			
		||||
    // Create a translation.
 | 
			
		||||
    $this->drupalLogin($this->translator);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -82,7 +82,9 @@ class EntityReferenceIntegrationTest extends WebTestBase {
 | 
			
		|||
 | 
			
		||||
      // Try to post the form again with no modification and check if the field
 | 
			
		||||
      // values remain the same.
 | 
			
		||||
      $entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
 | 
			
		||||
      /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
 | 
			
		||||
      $storage = $this->container->get('entity_type.manager')->getStorage($this->entityType);
 | 
			
		||||
      $entity = current($storage->loadByProperties(['name' => $entity_name]));
 | 
			
		||||
      $this->drupalGet($this->entityType . '/manage/' . $entity->id() . '/edit');
 | 
			
		||||
      $this->assertFieldByName($this->fieldName . '[0][target_id]', $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')');
 | 
			
		||||
      $this->assertFieldByName($this->fieldName . '[1][target_id]', $referenced_entities[1]->label() . ' (' . $referenced_entities[1]->id() . ')');
 | 
			
		||||
| 
						 | 
				
			
			@ -108,7 +110,7 @@ class EntityReferenceIntegrationTest extends WebTestBase {
 | 
			
		|||
 | 
			
		||||
      // Try to post the form again with no modification and check if the field
 | 
			
		||||
      // values remain the same.
 | 
			
		||||
      $entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
 | 
			
		||||
      $entity = current($storage->loadByProperties(['name' => $entity_name]));
 | 
			
		||||
      $this->drupalGet($this->entityType . '/manage/' . $entity->id() . '/edit');
 | 
			
		||||
      $this->assertFieldByName($this->fieldName . '[target_id]', $target_id . ' (' . $referenced_entities[1]->id() . ')');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -119,7 +121,7 @@ class EntityReferenceIntegrationTest extends WebTestBase {
 | 
			
		|||
      // Since we don't know the form structure for these widgets, just test
 | 
			
		||||
      // that editing and saving an already created entity works.
 | 
			
		||||
      $exclude = array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags');
 | 
			
		||||
      $entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
 | 
			
		||||
      $entity = current($storage->loadByProperties(['name' => $entity_name]));
 | 
			
		||||
      $supported_widgets = \Drupal::service('plugin.manager.field.widget')->getOptions('entity_reference');
 | 
			
		||||
      $supported_widget_types = array_diff(array_keys($supported_widgets), $exclude);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -173,7 +175,8 @@ class EntityReferenceIntegrationTest extends WebTestBase {
 | 
			
		|||
   *   An array of referenced entities.
 | 
			
		||||
   */
 | 
			
		||||
  protected function assertFieldValues($entity_name, $referenced_entities) {
 | 
			
		||||
    $entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
 | 
			
		||||
    $entity = current($this->container->get('entity_type.manager')->getStorage(
 | 
			
		||||
    $this->entityType)->loadByProperties(['name' => $entity_name]));
 | 
			
		||||
 | 
			
		||||
    $this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $this->entityType)));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,8 +47,11 @@ abstract class FieldTestBase extends WebTestBase {
 | 
			
		|||
   */
 | 
			
		||||
  function assertFieldValues(EntityInterface $entity, $field_name, $expected_values, $langcode = LanguageInterface::LANGCODE_DEFAULT, $column = 'value') {
 | 
			
		||||
    // Re-load the entity to make sure we have the latest changes.
 | 
			
		||||
    \Drupal::entityManager()->getStorage($entity->getEntityTypeId())->resetCache(array($entity->id()));
 | 
			
		||||
    $e = entity_load($entity->getEntityTypeId(), $entity->id());
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity->getEntityTypeId());
 | 
			
		||||
    $storage->resetCache([$entity->id()]);
 | 
			
		||||
    $e = $storage->load($entity->id());
 | 
			
		||||
 | 
			
		||||
    $field = $values = $e->getTranslation($langcode)->$field_name;
 | 
			
		||||
    // Filter out empty values so that they don't mess with the assertions.
 | 
			
		||||
    $field->filterEmptyItems();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -555,7 +555,9 @@ class FormTest extends FieldTestBase {
 | 
			
		|||
    $id = $match[1];
 | 
			
		||||
 | 
			
		||||
    // Check that the default value was saved.
 | 
			
		||||
    $entity = entity_load($entity_type, $id);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type);
 | 
			
		||||
    $entity = $storage->load($id);
 | 
			
		||||
    $this->assertEqual($entity->$field_name_no_access->value, 99, 'Default value was saved for the field with no edit access.');
 | 
			
		||||
    $this->assertEqual($entity->$field_name->value, 1, 'Entered value vas saved for the field with edit access.');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -567,8 +569,8 @@ class FormTest extends FieldTestBase {
 | 
			
		|||
    $this->drupalPostForm($entity_type . '/manage/' . $id . '/edit', $edit, t('Save'));
 | 
			
		||||
 | 
			
		||||
    // Check that the new revision has the expected values.
 | 
			
		||||
    $this->container->get('entity.manager')->getStorage($entity_type)->resetCache(array($id));
 | 
			
		||||
    $entity = entity_load($entity_type, $id);
 | 
			
		||||
    $storage->resetCache([$id]);
 | 
			
		||||
    $entity = $storage->load($id);
 | 
			
		||||
    $this->assertEqual($entity->$field_name_no_access->value, 99, 'New revision has the expected value for the field with no edit access.');
 | 
			
		||||
    $this->assertEqual($entity->$field_name->value, 2, 'New revision has the expected value for the field with edit access.');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -606,7 +608,10 @@ class FormTest extends FieldTestBase {
 | 
			
		|||
    preg_match('|' . $entity_type . '/manage/(\d+)|', $this->url, $match);
 | 
			
		||||
    $id = $match[1];
 | 
			
		||||
    $this->assertText(t('entity_test_rev @id has been created.', array('@id' => $id)), 'Entity was created');
 | 
			
		||||
    $entity = entity_load($entity_type, $id);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type);
 | 
			
		||||
 | 
			
		||||
    $entity = $storage->load($id);
 | 
			
		||||
    $this->assertEqual($entity->{$field_name}->value, 99, 'Default value was saved');
 | 
			
		||||
 | 
			
		||||
    // Update the field to remove the default value, and switch to the default
 | 
			
		||||
| 
						 | 
				
			
			@ -628,8 +633,8 @@ class FormTest extends FieldTestBase {
 | 
			
		|||
    $edit = array("{$field_name}[0][value]" => $value);
 | 
			
		||||
    $this->drupalPostForm(NULL, $edit, t('Save'));
 | 
			
		||||
    $this->assertText(t('entity_test_rev @id has been updated.', array('@id' => $id)), 'Entity was updated');
 | 
			
		||||
    \Drupal::entityManager()->getStorage($entity_type)->resetCache(array($id));
 | 
			
		||||
    $entity = entity_load($entity_type, $id);
 | 
			
		||||
    $storage->resetCache([$id]);
 | 
			
		||||
    $entity = $storage->load($id);
 | 
			
		||||
    $this->assertEqual($entity->{$field_name}->value, $value, 'Field value was updated');
 | 
			
		||||
 | 
			
		||||
    // Set the field back to hidden.
 | 
			
		||||
| 
						 | 
				
			
			@ -642,8 +647,8 @@ class FormTest extends FieldTestBase {
 | 
			
		|||
    $this->drupalPostForm($entity_type . '/manage/' . $id . '/edit', $edit, t('Save'));
 | 
			
		||||
 | 
			
		||||
    // Check that the expected value has been carried over to the new revision.
 | 
			
		||||
    \Drupal::entityManager()->getStorage($entity_type)->resetCache(array($id));
 | 
			
		||||
    $entity = entity_load($entity_type, $id);
 | 
			
		||||
    $storage->resetCache(array($id));
 | 
			
		||||
    $entity = $storage->load($id);
 | 
			
		||||
    $this->assertEqual($entity->{$field_name}->value, $value, 'New revision has the expected value for the field with the Hidden widget');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -71,17 +71,16 @@ class NestedFormTest extends FieldTestBase {
 | 
			
		|||
 | 
			
		||||
    // Create two entities.
 | 
			
		||||
    $entity_type = 'entity_test';
 | 
			
		||||
    $entity_1 = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type)
 | 
			
		||||
      ->create(array('id' => 1));
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type);
 | 
			
		||||
 | 
			
		||||
    $entity_1 = $storage->create(['id' => 1]);
 | 
			
		||||
    $entity_1->enforceIsNew();
 | 
			
		||||
    $entity_1->field_single->value = 0;
 | 
			
		||||
    $entity_1->field_unlimited->value = 1;
 | 
			
		||||
    $entity_1->save();
 | 
			
		||||
 | 
			
		||||
    $entity_2 = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type)
 | 
			
		||||
      ->create(array('id' => 2));
 | 
			
		||||
    $entity_2 = $storage->create(array('id' => 2));
 | 
			
		||||
    $entity_2->enforceIsNew();
 | 
			
		||||
    $entity_2->field_single->value = 10;
 | 
			
		||||
    $entity_2->field_unlimited->value = 11;
 | 
			
		||||
| 
						 | 
				
			
			@ -104,8 +103,8 @@ class NestedFormTest extends FieldTestBase {
 | 
			
		|||
      'entity_2[field_unlimited][1][value]' => 13,
 | 
			
		||||
    );
 | 
			
		||||
    $this->drupalPostForm(NULL, $edit, t('Save'));
 | 
			
		||||
    $entity_1 = entity_load($entity_type, 1);
 | 
			
		||||
    $entity_2 = entity_load($entity_type, 2);
 | 
			
		||||
    $entity_1 = $storage->load(1);
 | 
			
		||||
    $entity_2 = $storage->load(2);
 | 
			
		||||
    $this->assertFieldValues($entity_1, 'field_single', array(1));
 | 
			
		||||
    $this->assertFieldValues($entity_1, 'field_unlimited', array(2, 3));
 | 
			
		||||
    $this->assertFieldValues($entity_2, 'field_single', array(11));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -137,7 +137,8 @@ class BulkDeleteTest extends FieldKernelTestBase {
 | 
			
		|||
        $entity->save();
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    $this->entities = entity_load_multiple($this->entityTypeId);
 | 
			
		||||
    $this->entities = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId)->loadMultiple();
 | 
			
		||||
    foreach ($this->entities as $entity) {
 | 
			
		||||
      // This test relies on the entities having stale field definitions
 | 
			
		||||
      // so that the deleted field can be accessed on them. Access the field
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -186,8 +186,11 @@ abstract class FieldKernelTestBase extends KernelTestBase {
 | 
			
		|||
   */
 | 
			
		||||
  protected function assertFieldValues(EntityInterface $entity, $field_name, $expected_values, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $column = 'value') {
 | 
			
		||||
    // Re-load the entity to make sure we have the latest changes.
 | 
			
		||||
    \Drupal::entityManager()->getStorage($entity->getEntityTypeId())->resetCache(array($entity->id()));
 | 
			
		||||
    $e = entity_load($entity->getEntityTypeId(), $entity->id());
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity->getEntityTypeId());
 | 
			
		||||
    $storage->resetCache([$entity->id()]);
 | 
			
		||||
    $e = $storage->load($this->entityId);
 | 
			
		||||
 | 
			
		||||
    $field = $values = $e->getTranslation($langcode)->$field_name;
 | 
			
		||||
    // Filter out empty values so that they don't mess with the assertions.
 | 
			
		||||
    $field->filterEmptyItems();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1482,7 +1482,8 @@ function file_get_file_references(FileInterface $file, FieldDefinitionInterface
 | 
			
		|||
    $usage_list = \Drupal::service('file.usage')->listUsage($file);
 | 
			
		||||
    $file_usage_list = isset($usage_list['file']) ? $usage_list['file'] : array();
 | 
			
		||||
    foreach ($file_usage_list as $entity_type_id => $entity_ids) {
 | 
			
		||||
      $entities = entity_load_multiple($entity_type_id, array_keys($entity_ids));
 | 
			
		||||
      $entities = \Drupal::entityTypeManager()
 | 
			
		||||
        ->getStorage($entity_type_id)->loadMultiple(array_keys($entity_ids));
 | 
			
		||||
      foreach ($entities as $entity) {
 | 
			
		||||
        $bundle = $entity->bundle();
 | 
			
		||||
        // We need to find file fields for this entity type and bundle.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -98,7 +98,10 @@ class MenuLinkContentTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationEdit() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -83,7 +83,10 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
    $default_langcode = $this->langcodes[0];
 | 
			
		||||
    $values[$default_langcode] = array('title' => array(array('value' => $this->randomMachineName())));
 | 
			
		||||
    $entity_id = $this->createEntity($values[$default_langcode], $default_langcode);
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $entity_id, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
 | 
			
		||||
    // Add a content translation.
 | 
			
		||||
    $langcode = 'fr';
 | 
			
		||||
| 
						 | 
				
			
			@ -98,7 +101,8 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
    ], array('language' => $language));
 | 
			
		||||
    $this->drupalPostForm($add_url, $this->getEditValues($values, $langcode), t('Save and unpublish (this translation)'));
 | 
			
		||||
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $translation = $entity->getTranslation($langcode);
 | 
			
		||||
    // Make sure we unpublished the node correctly.
 | 
			
		||||
    $this->assertFalse($this->manager->getTranslationMetadata($translation)->isPublished(), 'The translation has been correctly unpublished.');
 | 
			
		||||
| 
						 | 
				
			
			@ -148,7 +152,10 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestPublishedStatus() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
 | 
			
		||||
    $actions = array(
 | 
			
		||||
| 
						 | 
				
			
			@ -164,7 +171,8 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
        $url = $entity->urlInfo('edit-form', $options);
 | 
			
		||||
        $this->drupalPostForm($url, array(), $action . $this->getFormSubmitSuffix($entity, $langcode), $options);
 | 
			
		||||
      }
 | 
			
		||||
      $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
      $storage->resetCache([$this->entityId]);
 | 
			
		||||
      $entity = $storage->load($this->entityId);
 | 
			
		||||
      foreach ($this->langcodes as $langcode) {
 | 
			
		||||
        // The node is created as unpublished thus we switch to the published
 | 
			
		||||
        // status first.
 | 
			
		||||
| 
						 | 
				
			
			@ -179,7 +187,10 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestAuthoringInfo() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
    $values = array();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -204,7 +215,8 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
      $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode), $options);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
      $translation = $entity->getTranslation($langcode);
 | 
			
		||||
      $metadata = $this->manager->getTranslationMetadata($translation);
 | 
			
		||||
| 
						 | 
				
			
			@ -424,7 +436,10 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationEdit() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
    $type_name = node_get_type_label($entity);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -87,7 +87,10 @@ class CsrfTest extends RESTTestBase {
 | 
			
		|||
    $this->curlExec($curl_options);
 | 
			
		||||
    $this->assertResponse(403);
 | 
			
		||||
    // Ensure that the entity was not created.
 | 
			
		||||
    $this->assertFalse(entity_load_multiple($this->testEntityType, NULL, TRUE), 'No entity has been created in the database.');
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->testEntityType);
 | 
			
		||||
    $storage->resetCache();
 | 
			
		||||
    $this->assertFalse($storage->loadMultiple(), 'No entity has been created in the database.');
 | 
			
		||||
 | 
			
		||||
    // Create an entity with the CSRF token.
 | 
			
		||||
    $token = $this->drupalGet('rest/session/token');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,7 +44,10 @@ class DeleteTest extends RESTTestBase {
 | 
			
		|||
      $response = $this->httpRequest($entity->urlInfo(), 'DELETE');
 | 
			
		||||
      // Clear the static cache with entity_load(), otherwise we won't see the
 | 
			
		||||
      // update.
 | 
			
		||||
      $entity = entity_load($entity_type, $entity->id(), TRUE);
 | 
			
		||||
      $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
        ->getStorage($entity_type);
 | 
			
		||||
      $storage->resetCache([$entity->id()]);
 | 
			
		||||
      $entity = $storage->load($entity->id());
 | 
			
		||||
      $this->assertFalse($entity, $entity_type . ' entity is not in the DB anymore.');
 | 
			
		||||
      $this->assertResponse('204', 'HTTP response code is correct.');
 | 
			
		||||
      $this->assertEqual($response, '', 'Response body is empty.');
 | 
			
		||||
| 
						 | 
				
			
			@ -61,7 +64,9 @@ class DeleteTest extends RESTTestBase {
 | 
			
		|||
      $entity->save();
 | 
			
		||||
      $this->httpRequest($entity->urlInfo(), 'DELETE');
 | 
			
		||||
      $this->assertResponse(403);
 | 
			
		||||
      $this->assertNotIdentical(FALSE, entity_load($entity_type, $entity->id(), TRUE), 'The ' . $entity_type . ' entity is still in the database.');
 | 
			
		||||
      $storage->resetCache([$entity->id()]);
 | 
			
		||||
      $this->assertNotIdentical(FALSE, $storage->load($entity->id()),
 | 
			
		||||
        'The ' . $entity_type . ' entity is still in the database.');
 | 
			
		||||
    }
 | 
			
		||||
    // Try to delete a resource which is not REST API enabled.
 | 
			
		||||
    $this->enableService(FALSE);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -446,7 +446,8 @@ abstract class RESTTestBase extends WebTestBase {
 | 
			
		|||
  protected function loadEntityFromLocationHeader($location_url) {
 | 
			
		||||
    $url_parts = explode('/', $location_url);
 | 
			
		||||
    $id = end($url_parts);
 | 
			
		||||
    return entity_load($this->testEntityType, $id);
 | 
			
		||||
    return $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->testEntityType)->load($id);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -90,7 +90,10 @@ class UpdateTest extends RESTTestBase {
 | 
			
		|||
    $this->assertEqual($request, $response);
 | 
			
		||||
 | 
			
		||||
    // Re-load updated entity from the database.
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id(), TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type);
 | 
			
		||||
    $storage->resetCache([$entity->id()]);
 | 
			
		||||
    $entity = $storage->load($entity->id());
 | 
			
		||||
    $this->assertEqual($entity->field_test_text->value, $patch_entity->field_test_text->value, 'Field was successfully updated.');
 | 
			
		||||
 | 
			
		||||
    // Make sure that the field does not get deleted if it is not present in the
 | 
			
		||||
| 
						 | 
				
			
			@ -101,7 +104,8 @@ class UpdateTest extends RESTTestBase {
 | 
			
		|||
    $this->httpRequest($entity->urlInfo(), 'PATCH', $serialized, $this->defaultMimeType);
 | 
			
		||||
    $this->assertResponse(200);
 | 
			
		||||
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id(), TRUE);
 | 
			
		||||
    $storage->resetCache([$entity->id()]);
 | 
			
		||||
    $entity = $storage->load($entity->id());
 | 
			
		||||
    $this->assertNotNull($entity->field_test_text->value . 'Test field has not been deleted.');
 | 
			
		||||
 | 
			
		||||
    // Try to empty a field.
 | 
			
		||||
| 
						 | 
				
			
			@ -113,7 +117,8 @@ class UpdateTest extends RESTTestBase {
 | 
			
		|||
    $this->assertResponse(200);
 | 
			
		||||
 | 
			
		||||
    // Re-load updated entity from the database.
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id(), TRUE);
 | 
			
		||||
    $storage->resetCache([$entity->id()]);
 | 
			
		||||
    $entity = $storage->load($entity->id(), TRUE);
 | 
			
		||||
    $this->assertNull($entity->field_test_text->value, 'Test field has been cleared.');
 | 
			
		||||
 | 
			
		||||
    // Enable access protection for the text field.
 | 
			
		||||
| 
						 | 
				
			
			@ -127,7 +132,8 @@ class UpdateTest extends RESTTestBase {
 | 
			
		|||
    $this->assertResponse(403);
 | 
			
		||||
 | 
			
		||||
    // Re-load the entity from the database.
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id(), TRUE);
 | 
			
		||||
    $storage->resetCache([$entity->id()]);
 | 
			
		||||
    $entity = $storage->load($entity->id());
 | 
			
		||||
    $this->assertEqual($entity->field_test_text->value, 'no edit access value', 'Text field was not deleted.');
 | 
			
		||||
 | 
			
		||||
    // Try to update an access protected field.
 | 
			
		||||
| 
						 | 
				
			
			@ -138,7 +144,8 @@ class UpdateTest extends RESTTestBase {
 | 
			
		|||
    $this->assertResponse(403);
 | 
			
		||||
 | 
			
		||||
    // Re-load the entity from the database.
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id(), TRUE);
 | 
			
		||||
    $storage->resetCache([$entity->id()]);
 | 
			
		||||
    $entity = $storage->load($entity->id());
 | 
			
		||||
    $this->assertEqual($entity->field_test_text->value, 'no edit access value', 'Text field was not updated.');
 | 
			
		||||
 | 
			
		||||
    // Try to update the field with a text format this user has no access to.
 | 
			
		||||
| 
						 | 
				
			
			@ -154,7 +161,8 @@ class UpdateTest extends RESTTestBase {
 | 
			
		|||
    $this->assertResponse(422);
 | 
			
		||||
 | 
			
		||||
    // Re-load the entity from the database.
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id(), TRUE);
 | 
			
		||||
    $storage->resetCache([$entity->id()]);
 | 
			
		||||
    $entity = $storage->load($entity->id());
 | 
			
		||||
    $this->assertEqual($entity->field_test_text->format, 'plain_text', 'Text format was not updated.');
 | 
			
		||||
 | 
			
		||||
    // Restore the valid test value.
 | 
			
		||||
| 
						 | 
				
			
			@ -168,7 +176,8 @@ class UpdateTest extends RESTTestBase {
 | 
			
		|||
    // Try to update a non-existing entity with ID 9999.
 | 
			
		||||
    $this->httpRequest($entity_type . '/9999', 'PATCH', $serialized, $this->defaultMimeType);
 | 
			
		||||
    $this->assertResponse(404);
 | 
			
		||||
    $loaded_entity = entity_load($entity_type, 9999, TRUE);
 | 
			
		||||
    $storage->resetCache([9999]);
 | 
			
		||||
    $loaded_entity = $storage->load(9999);
 | 
			
		||||
    $this->assertFalse($loaded_entity, 'Entity 9999 was not created.');
 | 
			
		||||
 | 
			
		||||
    // Try to send invalid data to trigger the entity validation constraints.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -65,7 +65,10 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
  protected function doTestBasicTranslation() {
 | 
			
		||||
    parent::doTestBasicTranslation();
 | 
			
		||||
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
      if ($entity->hasTranslation($langcode)) {
 | 
			
		||||
        $language = new Language(array('id' => $langcode));
 | 
			
		||||
| 
						 | 
				
			
			@ -84,7 +87,10 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationEdit() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
| 
						 | 
				
			
			@ -107,7 +113,10 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * Tests the basic translation workflow.
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationChanged() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
 | 
			
		||||
    $this->assertFalse(
 | 
			
		||||
      $entity instanceof EntityChangedInterface,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -515,7 +515,9 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
 | 
			
		|||
      // cache miss for both the referencing entity, and the listing of
 | 
			
		||||
      // referencing entities, but not for any other routes.
 | 
			
		||||
      $this->pass("Test modification of referenced entity's bundle entity.", 'Debug');
 | 
			
		||||
      $bundle_entity = entity_load($bundle_entity_type_id, $this->entity->bundle());
 | 
			
		||||
      $bundle_entity = $this->container->get('entity_type.manager')
 | 
			
		||||
        ->getStorage($bundle_entity_type_id)
 | 
			
		||||
        ->load($this->entity->bundle());
 | 
			
		||||
      $bundle_entity->save();
 | 
			
		||||
      $this->verifyPageCache($referencing_entity_url, 'MISS');
 | 
			
		||||
      $this->verifyPageCache($listing_url, 'MISS');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -83,7 +83,8 @@ class EntityRevisionsTest extends WebTestBase {
 | 
			
		|||
      $legacy_name = $entity->name->value;
 | 
			
		||||
      $legacy_text = $entity->field_test_text->value;
 | 
			
		||||
 | 
			
		||||
      $entity = entity_load($entity_type, $entity->id->value);
 | 
			
		||||
      $entity = $this->container->get('entity_type.manager')
 | 
			
		||||
        ->getStorage($entity_type)->load($entity->id->value);
 | 
			
		||||
      $entity->setNewRevision(TRUE);
 | 
			
		||||
      $names[] = $entity->name->value = $this->randomMachineName(32);
 | 
			
		||||
      $texts[] = $entity->field_test_text->value = $this->randomMachineName(32);
 | 
			
		||||
| 
						 | 
				
			
			@ -112,7 +113,9 @@ class EntityRevisionsTest extends WebTestBase {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    // Confirm the correct revision text appears in the edit form.
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id->value);
 | 
			
		||||
    $entity = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type)
 | 
			
		||||
      ->load($entity->id->value);
 | 
			
		||||
    $this->drupalGet($entity_type . '/manage/' . $entity->id->value . '/edit');
 | 
			
		||||
    $this->assertFieldById('edit-name-0-value', $entity->name->value, format_string('%entity_type: Name matches in UI.', array('%entity_type' => $entity_type)));
 | 
			
		||||
    $this->assertFieldById('edit-field-test-text-0-value', $entity->field_test_text->value, format_string('%entity_type: Text matches in UI.', array('%entity_type' => $entity_type)));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -80,7 +80,9 @@ abstract class EntityWithUriCacheTagsTestBase extends EntityCacheTagsTestBase {
 | 
			
		|||
      // Verify that after modifying the corresponding bundle entity, there is a
 | 
			
		||||
      // cache miss.
 | 
			
		||||
      $this->pass("Test modification of entity's bundle entity.", 'Debug');
 | 
			
		||||
      $bundle_entity = entity_load($bundle_entity_type_id, $this->entity->bundle());
 | 
			
		||||
      $bundle_entity = $this->container->get('entity_type.manager')
 | 
			
		||||
        ->getStorage($bundle_entity_type_id)
 | 
			
		||||
        ->load($this->entity->bundle());
 | 
			
		||||
      $bundle_entity->save();
 | 
			
		||||
      $this->verifyPageCache($entity_url, 'MISS');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -139,7 +139,10 @@ class TermTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationEdit() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,16 +59,16 @@ class TextWithSummaryItemTest extends FieldKernelTestBase {
 | 
			
		|||
    $this->createField($entity_type);
 | 
			
		||||
 | 
			
		||||
    // Create an entity with a summary and no text format.
 | 
			
		||||
    $entity = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type)
 | 
			
		||||
      ->create();
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type);
 | 
			
		||||
    $entity = $storage->create();
 | 
			
		||||
    $entity->summary_field->value = $value = $this->randomMachineName();
 | 
			
		||||
    $entity->summary_field->summary = $summary = $this->randomMachineName();
 | 
			
		||||
    $entity->summary_field->format = NULL;
 | 
			
		||||
    $entity->name->value = $this->randomMachineName();
 | 
			
		||||
    $entity->save();
 | 
			
		||||
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id());
 | 
			
		||||
    $entity = $storage->load($entity->id());
 | 
			
		||||
    $this->assertTrue($entity->summary_field instanceof FieldItemListInterface, 'Field implements interface.');
 | 
			
		||||
    $this->assertTrue($entity->summary_field[0] instanceof FieldItemInterface, 'Field item implements interface.');
 | 
			
		||||
    $this->assertEqual($entity->summary_field->value, $value);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -53,7 +53,10 @@ class UserTranslationUITest extends ContentTranslationUITestBase {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  protected function doTestTranslationEdit() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $storage->resetCache([$this->entityId]);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $languages = $this->container->get('language_manager')->getLanguages();
 | 
			
		||||
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -50,8 +50,10 @@ class ConfigEntityStaticCacheTest extends KernelTestBase {
 | 
			
		|||
   * Tests that the static cache is working.
 | 
			
		||||
   */
 | 
			
		||||
  public function testCacheHit() {
 | 
			
		||||
    $entity_1 = entity_load($this->entityTypeId, $this->entityId);
 | 
			
		||||
    $entity_2 = entity_load($this->entityTypeId, $this->entityId);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $entity_1 = $storage->load($this->entityId);
 | 
			
		||||
    $entity_2 = $storage->load($this->entityId);
 | 
			
		||||
    // config_entity_static_cache_test_config_test_load() sets _loadStamp to a
 | 
			
		||||
    // random string. If they match, it means $entity_2 was retrieved from the
 | 
			
		||||
    // static cache rather than going through a separate load sequence.
 | 
			
		||||
| 
						 | 
				
			
			@ -62,19 +64,21 @@ class ConfigEntityStaticCacheTest extends KernelTestBase {
 | 
			
		|||
   * Tests that the static cache is reset on entity save and delete.
 | 
			
		||||
   */
 | 
			
		||||
  public function testReset() {
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($this->entityTypeId);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
 | 
			
		||||
    // Ensure loading after a save retrieves the updated entity rather than an
 | 
			
		||||
    // obsolete cached one.
 | 
			
		||||
    $entity->label = 'New label';
 | 
			
		||||
    $entity->save();
 | 
			
		||||
    $entity = entity_load($this->entityTypeId, $this->entityId);
 | 
			
		||||
    $entity = $storage->load($this->entityId);
 | 
			
		||||
    $this->assertIdentical($entity->label, 'New label');
 | 
			
		||||
 | 
			
		||||
    // Ensure loading after a delete retrieves NULL rather than an obsolete
 | 
			
		||||
    // cached one.
 | 
			
		||||
    $entity->delete();
 | 
			
		||||
    $this->assertNull(entity_load($this->entityTypeId, $this->entityId));
 | 
			
		||||
    $this->assertNull($storage->load($this->entityId));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,11 +27,10 @@ class ConfigEntityStorageTest extends KernelTestBase {
 | 
			
		|||
    $entity_type = 'config_test';
 | 
			
		||||
    $id = 'test_1';
 | 
			
		||||
    // Load the original configuration entity.
 | 
			
		||||
    $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type)
 | 
			
		||||
      ->create(array('id' => $id))
 | 
			
		||||
      ->save();
 | 
			
		||||
    $entity = entity_load($entity_type, $id);
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type);
 | 
			
		||||
    $storage->create(['id' => $id])->save();
 | 
			
		||||
    $entity = $storage->load($id);
 | 
			
		||||
 | 
			
		||||
    $original_properties = $entity->toArray();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -60,32 +60,36 @@ class EntityApiTest extends EntityKernelTestBase {
 | 
			
		|||
      ->create(array('name' => 'test', 'user_id' => NULL));
 | 
			
		||||
    $entity->save();
 | 
			
		||||
 | 
			
		||||
    $entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test')));
 | 
			
		||||
    /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type);
 | 
			
		||||
 | 
			
		||||
    $entities = array_values($storage->loadByProperties(['name' => 'test']));
 | 
			
		||||
    $this->assertEqual($entities[0]->name->value, 'test', format_string('%entity_type: Created and loaded entity', array('%entity_type' => $entity_type)));
 | 
			
		||||
    $this->assertEqual($entities[1]->name->value, 'test', format_string('%entity_type: Created and loaded entity', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    // Test loading a single entity.
 | 
			
		||||
    $loaded_entity = entity_load($entity_type, $entity->id());
 | 
			
		||||
    $loaded_entity = $storage->load($entity->id());
 | 
			
		||||
    $this->assertEqual($loaded_entity->id(), $entity->id(), format_string('%entity_type: Loaded a single entity by id.', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    // Test deleting an entity.
 | 
			
		||||
    $entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test2')));
 | 
			
		||||
    $entities = array_values($storage->loadByProperties(['name' => 'test2']));
 | 
			
		||||
    $entities[0]->delete();
 | 
			
		||||
    $entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test2')));
 | 
			
		||||
    $entities = array_values($storage->loadByProperties(['name' => 'test2']));
 | 
			
		||||
    $this->assertEqual($entities, array(), format_string('%entity_type: Entity deleted.', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    // Test updating an entity.
 | 
			
		||||
    $entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test')));
 | 
			
		||||
    $entities = array_values($storage->loadByProperties(['name' => 'test']));
 | 
			
		||||
    $entities[0]->name->value = 'test3';
 | 
			
		||||
    $entities[0]->save();
 | 
			
		||||
    $entity = entity_load($entity_type, $entities[0]->id());
 | 
			
		||||
    $entity = $storage->load($entities[0]->id());
 | 
			
		||||
    $this->assertEqual($entity->name->value, 'test3', format_string('%entity_type: Entity updated.', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    // Try deleting multiple test entities by deleting all.
 | 
			
		||||
    $ids = array_keys(entity_load_multiple($entity_type));
 | 
			
		||||
    $ids = array_keys($storage->loadMultiple());
 | 
			
		||||
    entity_delete_multiple($entity_type, $ids);
 | 
			
		||||
 | 
			
		||||
    $all = entity_load_multiple($entity_type);
 | 
			
		||||
    $all = $storage->loadMultiple();
 | 
			
		||||
    $this->assertTrue(empty($all), format_string('%entity_type: Deleted all entities.', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    // Verify that all data got deleted.
 | 
			
		||||
| 
						 | 
				
			
			@ -110,7 +114,7 @@ class EntityApiTest extends EntityKernelTestBase {
 | 
			
		|||
    $controller->delete($entities);
 | 
			
		||||
 | 
			
		||||
    // Verify that entities got deleted.
 | 
			
		||||
    $all = entity_load_multiple($entity_type);
 | 
			
		||||
    $all = $storage->loadMultiple();
 | 
			
		||||
    $this->assertTrue(empty($all), format_string('%entity_type: Deleted all entities.', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    // Verify that all data got deleted from the tables.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -377,7 +377,9 @@ class EntityFieldTest extends EntityKernelTestBase {
 | 
			
		|||
    $entity->save();
 | 
			
		||||
    $this->assertTrue((bool) $entity->id(), format_string('%entity_type: Entity has received an id.', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id());
 | 
			
		||||
    $entity = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type)
 | 
			
		||||
      ->load($entity->id());
 | 
			
		||||
    $this->assertTrue((bool) $entity->id(), format_string('%entity_type: Entity loaded.', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    // Access the name field.
 | 
			
		||||
| 
						 | 
				
			
			@ -744,7 +746,9 @@ class EntityFieldTest extends EntityKernelTestBase {
 | 
			
		|||
 | 
			
		||||
    // Save and load entity and make sure it still works.
 | 
			
		||||
    $entity->save();
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id());
 | 
			
		||||
    $entity = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type)
 | 
			
		||||
      ->load($entity->id());
 | 
			
		||||
    $this->assertEqual($entity->field_test_text->processed, $target, format_string('%entity_type: Text is processed with the default filter.', array('%entity_type' => $entity_type)));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -164,11 +164,11 @@ class EntityTranslationTest extends EntityLanguageTestBase {
 | 
			
		|||
 | 
			
		||||
    // Create a language neutral entity and check that properties are stored
 | 
			
		||||
    // as language neutral.
 | 
			
		||||
    $entity = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type)
 | 
			
		||||
      ->create(array('name' => $name, 'user_id' => $uid, $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED));
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type);
 | 
			
		||||
    $entity = $storage->create(['name' => $name, 'user_id' => $uid, $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
 | 
			
		||||
    $entity->save();
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id());
 | 
			
		||||
    $entity = $storage->load($entity->id());
 | 
			
		||||
    $default_langcode = $entity->language()->getId();
 | 
			
		||||
    $this->assertEqual($default_langcode, LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity created as language neutral.', array('%entity_type' => $entity_type)));
 | 
			
		||||
    $field = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get('name');
 | 
			
		||||
| 
						 | 
				
			
			@ -192,7 +192,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
 | 
			
		|||
      ->getStorage($entity_type)
 | 
			
		||||
      ->create(array('name' => $name, 'user_id' => $uid, $langcode_key => $langcode));
 | 
			
		||||
    $entity->save();
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id());
 | 
			
		||||
    $entity = $storage->load($entity->id());
 | 
			
		||||
    $default_langcode = $entity->language()->getId();
 | 
			
		||||
    $this->assertEqual($default_langcode, $langcode, format_string('%entity_type: Entity created as language specific.', array('%entity_type' => $entity_type)));
 | 
			
		||||
    $field = $entity->getTranslation($langcode)->get('name');
 | 
			
		||||
| 
						 | 
				
			
			@ -224,7 +224,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
 | 
			
		|||
    $entity->save();
 | 
			
		||||
 | 
			
		||||
    // Check that property translation were correctly stored.
 | 
			
		||||
    $entity = entity_load($entity_type, $entity->id());
 | 
			
		||||
    $entity = $storage->load($entity->id());
 | 
			
		||||
    foreach ($this->langcodes as $langcode) {
 | 
			
		||||
      $args = array(
 | 
			
		||||
        '%entity_type' => $entity_type,
 | 
			
		||||
| 
						 | 
				
			
			@ -242,33 +242,34 @@ class EntityTranslationTest extends EntityLanguageTestBase {
 | 
			
		|||
    // Create an additional entity with only the uid set. The uid for the
 | 
			
		||||
    // original language is the same of one used for a translation.
 | 
			
		||||
    $langcode = $this->langcodes[1];
 | 
			
		||||
    $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type)
 | 
			
		||||
      ->create(array(
 | 
			
		||||
    /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type);
 | 
			
		||||
    $storage->create([
 | 
			
		||||
        'user_id' => $properties[$langcode]['user_id'],
 | 
			
		||||
        'name' => 'some name',
 | 
			
		||||
        $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED,
 | 
			
		||||
      ))
 | 
			
		||||
      ])
 | 
			
		||||
      ->save();
 | 
			
		||||
 | 
			
		||||
    $entities = entity_load_multiple($entity_type);
 | 
			
		||||
    $entities = $storage->loadMultiple();
 | 
			
		||||
    $this->assertEqual(count($entities), 3, format_string('%entity_type: Three entities were created.', array('%entity_type' => $entity_type)));
 | 
			
		||||
    $entities = entity_load_multiple($entity_type, array($translated_id));
 | 
			
		||||
    $entities = $storage->loadMultiple([$translated_id]);
 | 
			
		||||
    $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by id.', array('%entity_type' => $entity_type)));
 | 
			
		||||
    $entities = entity_load_multiple_by_properties($entity_type, array('name' => $name));
 | 
			
		||||
    $entities = $storage->loadByProperties(['name' => $name]);
 | 
			
		||||
    $this->assertEqual(count($entities), 2, format_string('%entity_type: Two entities correctly loaded by name.', array('%entity_type' => $entity_type)));
 | 
			
		||||
    // @todo The default language condition should go away in favor of an
 | 
			
		||||
    // explicit parameter.
 | 
			
		||||
    $entities = entity_load_multiple_by_properties($entity_type, array('name' => $properties[$langcode]['name'][0], $default_langcode_key => 0));
 | 
			
		||||
    $entities = $storage->loadByProperties(['name' => $properties[$langcode]['name'][0], $default_langcode_key => 0]);
 | 
			
		||||
    $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by name translation.', array('%entity_type' => $entity_type)));
 | 
			
		||||
    $entities = entity_load_multiple_by_properties($entity_type, array($langcode_key => $default_langcode, 'name' => $name));
 | 
			
		||||
    $entities = $storage->loadByProperties([$langcode_key => $default_langcode, 'name' => $name]);
 | 
			
		||||
    $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by name and language.', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    $entities = entity_load_multiple_by_properties($entity_type, array($langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0]));
 | 
			
		||||
    $entities = $storage->loadByProperties([$langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0]]);
 | 
			
		||||
    $this->assertEqual(count($entities), 0, format_string('%entity_type: No entity loaded by name translation specifying the translation language.', array('%entity_type' => $entity_type)));
 | 
			
		||||
    $entities = entity_load_multiple_by_properties($entity_type, array($langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0], $default_langcode_key => 0));
 | 
			
		||||
    $entities = $storage->loadByProperties([$langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0], $default_langcode_key => 0]);
 | 
			
		||||
    $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity loaded by name translation and language specifying to look for translations.', array('%entity_type' => $entity_type)));
 | 
			
		||||
    $entities = entity_load_multiple_by_properties($entity_type, array('user_id' => $properties[$langcode]['user_id'][0], $default_langcode_key => NULL));
 | 
			
		||||
    $entities = $storage->loadByProperties(['user_id' => $properties[$langcode]['user_id'][0], $default_langcode_key => NULL]);
 | 
			
		||||
    $this->assertEqual(count($entities), 2, format_string('%entity_type: Two entities loaded by uid without caring about property translatability.', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    // Test property conditions and orders with multiple languages in the same
 | 
			
		||||
| 
						 | 
				
			
			@ -284,7 +285,8 @@ class EntityTranslationTest extends EntityLanguageTestBase {
 | 
			
		|||
    $this->assertEqual(count($result), 1, format_string('%entity_type: One entity loaded by name and uid using different language meta conditions.', array('%entity_type' => $entity_type)));
 | 
			
		||||
 | 
			
		||||
    // Test mixed property and field conditions.
 | 
			
		||||
    $entity = entity_load($entity_type, reset($result), TRUE);
 | 
			
		||||
    $storage->resetCache($result);
 | 
			
		||||
    $entity = $storage->load(reset($result));
 | 
			
		||||
    $field_value = $this->randomString();
 | 
			
		||||
    $entity->getTranslation($langcode)->set($this->fieldName, array(array('value' => $field_value)));
 | 
			
		||||
    $entity->save();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -65,7 +65,11 @@ class EntityUUIDTest extends EntityKernelTestBase {
 | 
			
		|||
    $this->assertIdentical($entity->uuid(), $uuid);
 | 
			
		||||
 | 
			
		||||
    // Verify that the UUID is retained upon loading.
 | 
			
		||||
    $entity_loaded = entity_load($entity_type, $entity->id(), TRUE);
 | 
			
		||||
    /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
 | 
			
		||||
    $storage = $this->container->get('entity_type.manager')
 | 
			
		||||
      ->getStorage($entity_type);
 | 
			
		||||
    $storage->resetCache([$entity->id()]);
 | 
			
		||||
    $entity_loaded = $storage->load($entity->id());
 | 
			
		||||
    $this->assertIdentical($entity_loaded->uuid(), $uuid);
 | 
			
		||||
 | 
			
		||||
    // Verify that \Drupal::entityManager()->loadEntityByUuid() loads the same entity.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue