Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Entity / EntityQueryRelationshipTest.php
index 0bb5b16c34a62dd513da72e854b0814cb9cd379a..0c86ba8a707b309767cc3c336874e408df7b4b90 100644 (file)
@@ -3,11 +3,10 @@
 namespace Drupal\KernelTests\Core\Entity;
 
 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
-use Drupal\Component\Utility\Unicode;
 use Drupal\entity_test\Entity\EntityTest;
-use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
 use Drupal\taxonomy\Entity\Vocabulary;
 use Drupal\taxonomy\Entity\Term;
+use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
 
 /**
  * Tests the Entity Query relationship API.
@@ -25,11 +24,6 @@ class EntityQueryRelationshipTest extends EntityKernelTestBase {
    */
   public static $modules = ['taxonomy'];
 
-  /**
-   * @var \Drupal\Core\Entity\Query\QueryFactory
-   */
-  protected $factory;
-
   /**
    * Term entities.
    *
@@ -73,7 +67,7 @@ class EntityQueryRelationshipTest extends EntityKernelTestBase {
     // We want an entity reference field. It needs a vocabulary, terms, a field
     // storage and a field. First, create the vocabulary.
     $vocabulary = Vocabulary::create([
-      'vid' => Unicode::strtolower($this->randomMachineName()),
+      'vid' => mb_strtolower($this->randomMachineName()),
     ]);
     $vocabulary->save();
 
@@ -110,88 +104,88 @@ class EntityQueryRelationshipTest extends EntityKernelTestBase {
       $entity->save();
       $this->entities[] = $entity;
     }
-    $this->factory = \Drupal::service('entity.query');
   }
 
   /**
    * Tests querying.
    */
   public function testQuery() {
+    $storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
     // This returns the 0th entity as that's the only one pointing to the 0th
     // account.
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->condition("user_id.entity.name", $this->accounts[0]->getUsername())
       ->execute();
     $this->assertResults([0]);
     // This returns the 1st and 2nd entity as those point to the 1st account.
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->condition("user_id.entity.name", $this->accounts[0]->getUsername(), '<>')
       ->execute();
     $this->assertResults([1, 2]);
     // This returns all three entities because all of them point to an
     // account.
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->exists("user_id.entity.name")
       ->execute();
     $this->assertResults([0, 1, 2]);
     // This returns no entities because all of them point to an account.
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->notExists("user_id.entity.name")
       ->execute();
     $this->assertEqual(count($this->queryResults), 0);
     // This returns the 0th entity as that's only one pointing to the 0th
     // term (test without specifying the field column).
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->condition("$this->fieldName.entity.name", $this->terms[0]->name->value)
       ->execute();
     $this->assertResults([0]);
     // This returns the 0th entity as that's only one pointing to the 0th
     // term (test with specifying the column name).
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->condition("$this->fieldName.target_id.entity.name", $this->terms[0]->name->value)
       ->execute();
     $this->assertResults([0]);
     // This returns the 1st and 2nd entity as those point to the 1st term.
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->condition("$this->fieldName.entity.name", $this->terms[0]->name->value, '<>')
       ->execute();
     $this->assertResults([1, 2]);
     // This returns the 0th entity as that's only one pointing to the 0th
     // account.
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->condition("user_id.entity:user.name", $this->accounts[0]->getUsername())
       ->execute();
     $this->assertResults([0]);
     // This returns the 1st and 2nd entity as those point to the 1st account.
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->condition("user_id.entity:user.name", $this->accounts[0]->getUsername(), '<>')
       ->execute();
     $this->assertResults([1, 2]);
     // This returns all three entities because all of them point to an
     // account.
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->exists("user_id.entity:user.name")
       ->execute();
     $this->assertResults([0, 1, 2]);
     // This returns no entities because all of them point to an account.
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->notExists("user_id.entity:user.name")
       ->execute();
     $this->assertEqual(count($this->queryResults), 0);
     // This returns the 0th entity as that's only one pointing to the 0th
     // term (test without specifying the field column).
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->condition("$this->fieldName.entity:taxonomy_term.name", $this->terms[0]->name->value)
       ->execute();
     $this->assertResults([0]);
     // This returns the 0th entity as that's only one pointing to the 0th
     // term (test with specifying the column name).
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->condition("$this->fieldName.target_id.entity:taxonomy_term.name", $this->terms[0]->name->value)
       ->execute();
     $this->assertResults([0]);
     // This returns the 1st and 2nd entity as those point to the 1st term.
-    $this->queryResults = $this->factory->get('entity_test')
+    $this->queryResults = $storage->getQuery()
       ->condition("$this->fieldName.entity:taxonomy_term.name", $this->terms[0]->name->value, '<>')
       ->execute();
     $this->assertResults([1, 2]);
@@ -202,8 +196,10 @@ class EntityQueryRelationshipTest extends EntityKernelTestBase {
    */
   public function testInvalidSpecifier() {
     $this->setExpectedException(PluginNotFoundException::class);
-    $this->factory
-      ->get('taxonomy_term')
+    $this->container
+      ->get('entity_type.manager')
+      ->getStorage('taxonomy_term')
+      ->getQuery()
       ->condition('langcode.language.foo', 'bar')
       ->execute();
   }