assertResults example

$entity->enforceIsNew();
    $entity->save();
  }

  /** * Tests basic functionality. */
  public function testConfigEntityQuery() {
    // Run a test without any condition.     $this->queryResults = $this->entityStorage->getQuery()
      ->execute();
    $this->assertResults(['1', '2', '3', '4', '5', '6', '7']);
    // No conditions, OR.     $this->queryResults = $this->entityStorage->getQuery('OR')
      ->execute();
    $this->assertResults(['1', '2', '3', '4', '5', '6', '7']);

    // Filter by ID with equality.     $this->queryResults = $this->entityStorage->getQuery()
      ->condition('id', '3')
      ->execute();
    $this->assertResults(['3']);

    
/** * Tests aggregation support. */
  public function testAggregation() {
    // Apply a simple groupby.     $this->queryResult = $this->entityStorage->getAggregateQuery()
      ->accessCheck(FALSE)
      ->groupBy('user_id')
      ->execute();

    $this->assertResults([
      ['user_id' => 1],
      ['user_id' => 2],
      ['user_id' => 3],
    ]);

    $function_expected = [];
    $function_expected['count'] = [['id_count' => 6]];
    $function_expected['min'] = [['id_min' => 1]];
    $function_expected['max'] = [['id_max' => 6]];
    $function_expected['sum'] = [['id_sum' => 21]];
    $function_expected['avg'] = [['id_avg' => (21.0 / 6.0)]];

    
/** * 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 = $storage->getQuery()
      ->accessCheck(FALSE)
      ->condition("user_id.entity.name", $this->accounts[0]->getAccountName())
      ->execute();
    $this->assertResults([0]);
    // This returns the 1st and 2nd entity as those point to the 1st account.     $this->queryResults = $storage->getQuery()
      ->accessCheck(FALSE)
      ->condition("user_id.entity.name", $this->accounts[0]->getAccountName(), '<>')
      ->execute();
    $this->assertResults([1, 2]);
    // This returns all three entities because all of them point to an     // account.     $this->queryResults = $storage->getQuery()
      ->accessCheck(FALSE)
      ->exists("user_id.entity.name")
      

    $this->createEntityReferenceField('entity_test', 'test_bundle', 'test_field', $this->randomString(), 'node', 'views', $handler_settings);
    $field_config = FieldConfig::loadByName('entity_test', 'test_bundle', 'test_field');
    $this->selectionHandler = $this->container->get('plugin.manager.entity_reference_selection')->getSelectionHandler($field_config);
  }

  /** * Tests the selection handler. */
  public function testSelectionHandler() {
    // Tests the selection handler.     $this->assertResults($this->selectionHandler->getReferenceableEntities());

    // Add a relationship to the view.     $view = Views::getView('test_entity_reference');
    $view->setDisplay();
    $view->displayHandlers->get('default')->setOption('relationships', [
      'test_relationship' => [
        'id' => 'uid',
        'table' => 'node_field_data',
        'field' => 'uid',
      ],
    ]);

    
Home | Imprint | This part of the site doesn't use cookies.