Projet

Général

Profil

Révision b4adf10d

Ajouté par Assos Assos il y a plus de 9 ans

Udpate to 7.33

Voir les différences:

drupal7/modules/field/modules/field_sql_storage/field_sql_storage.test
438 438
    $this->assertEqual($foreign_key['table'], $foreign_key_name, 'Foreign key table name preserved in the schema');
439 439
    $this->assertEqual($foreign_key['columns'][$foreign_key_column], 'id', 'Foreign key column name preserved in the schema');
440 440
  }
441

  
442
  /**
443
   * Test handling multiple conditions on one column of a field.
444
   *
445
   * Tests both the result and the complexity of the query.
446
   */
447
  function testFieldSqlStorageMultipleConditionsSameColumn() {
448
    $entity = field_test_create_stub_entity(NULL, NULL);
449
    $entity->{$this->field_name}[LANGUAGE_NONE][0] = array('value' => 1);
450
    field_test_entity_save($entity);
451

  
452
    $entity = field_test_create_stub_entity(NULL, NULL);
453
    $entity->{$this->field_name}[LANGUAGE_NONE][0] = array('value' => 2);
454
    field_test_entity_save($entity);
455

  
456
    $entity = field_test_create_stub_entity(NULL, NULL);
457
    $entity->{$this->field_name}[LANGUAGE_NONE][0] = array('value' => 3);
458
    field_test_entity_save($entity);
459

  
460
    $query = new EntityFieldQuery();
461
    // This tag causes field_test_query_store_global_test_query_alter() to be
462
    // invoked so that the query can be tested.
463
    $query->addTag('store_global_test_query');
464
    $query->entityCondition('entity_type', 'test_entity');
465
    $query->entityCondition('bundle', 'test_bundle');
466
    $query->fieldCondition($this->field_name, 'value', 1, '<>', 0, LANGUAGE_NONE);
467
    $query->fieldCondition($this->field_name, 'value', 2, '<>', 0, LANGUAGE_NONE);
468
    $result = field_sql_storage_field_storage_query($query);
469

  
470
    // Test the results.
471
    $this->assertEqual(1, count($result), format_string('One result should be returned, got @count', array('@count' => count($result))));
472

  
473
    // Test the complexity of the query.
474
    $query = $GLOBALS['test_query'];
475
    $this->assertNotNull($query, 'Precondition: the query should be available');
476
    $tables = $query->getTables();
477
    $this->assertEqual(1, count($tables), 'The query contains just one table.');
478

  
479
    // Clean up.
480
    unset($GLOBALS['test_query']);
481
  }
482

  
483
  /**
484
   * Test handling multiple conditions on multiple columns of one field.
485
   *
486
   * Tests both the result and the complexity of the query.
487
   */
488
  function testFieldSqlStorageMultipleConditionsDifferentColumns() {
489
    // Create the multi-column shape field
490
    $field_name = strtolower($this->randomName());
491
    $field = array('field_name' => $field_name, 'type' => 'shape', 'cardinality' => 4);
492
    $field = field_create_field($field);
493
    $instance = array(
494
      'field_name' => $field_name,
495
      'entity_type' => 'test_entity',
496
      'bundle' => 'test_bundle'
497
    );
498
    $instance = field_create_instance($instance);
499

  
500
    $entity = field_test_create_stub_entity(NULL, NULL);
501
    $entity->{$field_name}[LANGUAGE_NONE][0] = array('shape' => 'A', 'color' => 'X');
502
    field_test_entity_save($entity);
503

  
504
    $entity = field_test_create_stub_entity(NULL, NULL);
505
    $entity->{$field_name}[LANGUAGE_NONE][0] = array('shape' => 'B', 'color' => 'X');
506
    field_test_entity_save($entity);
507

  
508
    $entity = field_test_create_stub_entity(NULL, NULL);
509
    $entity->{$field_name}[LANGUAGE_NONE][0] = array('shape' => 'A', 'color' => 'Y');
510
    field_test_entity_save($entity);
511

  
512
    $query = new EntityFieldQuery();
513
    // This tag causes field_test_query_store_global_test_query_alter() to be
514
    // invoked so that the query can be tested.
515
    $query->addTag('store_global_test_query');
516
    $query->entityCondition('entity_type', 'test_entity');
517
    $query->entityCondition('bundle', 'test_bundle');
518
    $query->fieldCondition($field_name, 'shape', 'B', '=', 'something', LANGUAGE_NONE);
519
    $query->fieldCondition($field_name, 'color', 'X', '=', 'something', LANGUAGE_NONE);
520
    $result = field_sql_storage_field_storage_query($query);
521

  
522
    // Test the results.
523
    $this->assertEqual(1, count($result), format_string('One result should be returned, got @count', array('@count' => count($result))));
524

  
525
    // Test the complexity of the query.
526
    $query = $GLOBALS['test_query'];
527
    $this->assertNotNull($query, 'Precondition: the query should be available');
528
    $tables = $query->getTables();
529
    $this->assertEqual(1, count($tables), 'The query contains just one table.');
530

  
531
    // Clean up.
532
    unset($GLOBALS['test_query']);
533
  }
534

  
535
  /**
536
   * Test handling multiple conditions on multiple columns of one field for multiple languages.
537
   *
538
   * Tests both the result and the complexity of the query.
539
   */
540
  function testFieldSqlStorageMultipleConditionsDifferentColumnsMultipleLanguages() {
541
    field_test_entity_info_translatable('test_entity', TRUE);
542

  
543
    // Create the multi-column shape field
544
    $field_name = strtolower($this->randomName());
545
    $field = array('field_name' => $field_name, 'type' => 'shape', 'cardinality' => 4, 'translatable' => TRUE);
546
    $field = field_create_field($field);
547
    $instance = array(
548
      'field_name' => $field_name,
549
      'entity_type' => 'test_entity',
550
      'bundle' => 'test_bundle',
551
      'settings' => array(
552
        // Prevent warning from field_test_field_load().
553
        'test_hook_field_load' => FALSE,
554
      ),
555
    );
556
    $instance = field_create_instance($instance);
557

  
558
    $entity = field_test_create_stub_entity(NULL, NULL);
559
    $entity->{$field_name}[LANGUAGE_NONE][0] = array('shape' => 'A', 'color' => 'X');
560
    $entity->{$field_name}['en'][0] = array('shape' => 'B', 'color' => 'Y');
561
    field_test_entity_save($entity);
562
    $entity = field_test_entity_test_load($entity->ftid);
563

  
564
    $query = new EntityFieldQuery();
565
    // This tag causes field_test_query_store_global_test_query_alter() to be
566
    // invoked so that the query can be tested.
567
    $query->addTag('store_global_test_query');
568
    $query->entityCondition('entity_type', 'test_entity');
569
    $query->entityCondition('bundle', 'test_bundle');
570
    $query->fieldCondition($field_name, 'color', 'X', '=', NULL, LANGUAGE_NONE);
571
    $query->fieldCondition($field_name, 'shape', 'B', '=', NULL, 'en');
572
    $result = field_sql_storage_field_storage_query($query);
573

  
574
    // Test the results.
575
    $this->assertEqual(1, count($result), format_string('One result should be returned, got @count', array('@count' => count($result))));
576

  
577
    // Test the complexity of the query.
578
    $query = $GLOBALS['test_query'];
579
    $this->assertNotNull($query, 'Precondition: the query should be available');
580
    $tables = $query->getTables();
581
    $this->assertEqual(2, count($tables), 'The query contains two tables.');
582

  
583
    // Clean up.
584
    unset($GLOBALS['test_query']);
585
  }
441 586
}

Formats disponibles : Unified diff