You are here

protected function QueryTest::smartQueryTest in Apigee Edge 8

Test for "smart" queries which are trying to reduce API calls.

1 call to QueryTest::smartQueryTest()
QueryTest::testQueries in tests/src/Functional/QueryTest.php
Tests developer and developer app entity queries.

File

tests/src/Functional/QueryTest.php, line 166

Class

QueryTest
Developer and developer app entity query test.

Namespace

Drupal\Tests\apigee_edge\Functional

Code

protected function smartQueryTest() {

  // Make sure that all developer has an app.
  foreach ($this->edgeDevelopers as $developer) {
    $app = DeveloperApp::create([
      'name' => $this
        ->randomMachineName(),
      'status' => DeveloperApp::STATUS_APPROVED,
      'developerId' => $developer
        ->getDeveloperId(),
    ]);
    $app
      ->save();
  }

  // When primary id(s) of entities is set to something empty we should
  // get back an empty result.
  $result = $this->developerStorage
    ->getQuery()
    ->condition('email', NULL)
    ->count()
    ->execute();
  $this
    ->assertEquals(0, $result);
  $result = $this->developerStorage
    ->getQuery()
    ->condition('developerId', NULL)
    ->count()
    ->execute();
  $this
    ->assertEquals(0, $result);
  $developer = reset($this->edgeDevelopers);
  $result = $this->developerAppStorage
    ->getQuery()
    ->condition('developerId', $developer
    ->getDeveloperId())
    ->count()
    ->execute();
  $this
    ->assertEquals(1, $result);

  // If developer id - which can be used to filter apps directly on Apigee
  // Edge by calling the proper API endpoint - is set to something empty
  // we should get back an empty result.
  $result = $this->developerAppStorage
    ->getQuery()
    ->condition('developerId', NULL)
    ->count()
    ->execute();
  $this
    ->assertEquals(0, $result);
  $result = $this->developerAppStorage
    ->getQuery()
    ->condition('email', $developer
    ->getEmail())
    ->count()
    ->execute();
  $this
    ->assertEquals(1, $result);

  // If developer email - which can be used to filter apps directly on Apigee
  // Edge by calling the proper API endpoint - is set to something empty
  // we should get back an empty result.
  $result = $this->developerAppStorage
    ->getQuery()
    ->condition('email', NULL)
    ->count()
    ->execute();
  $this
    ->assertEquals(0, $result);

  // If app name is set to something empty then query should not fail and
  // we should get back an empty list even if the developer has apps.
  $result = $this->developerAppStorage
    ->getQuery()
    ->condition('email', $developer
    ->getEmail())
    ->condition('name', NULL)
    ->count()
    ->execute();
  $this
    ->assertEquals(0, $result);
}