Révision b4adf10d
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/modules/field/tests/field.test | ||
---|---|---|
484 | 484 |
$this->assertEqual($entity->{$this->field_name}[$langcode], $values, 'Insert: missing field results in default value saved'); |
485 | 485 |
} |
486 | 486 |
|
487 |
/** |
|
488 |
* Test field_has_data(). |
|
489 |
*/ |
|
490 |
function testFieldHasData() { |
|
491 |
$entity_type = 'test_entity'; |
|
492 |
$langcode = LANGUAGE_NONE; |
|
493 |
|
|
494 |
$field_name = 'field_1'; |
|
495 |
$field = array('field_name' => $field_name, 'type' => 'test_field'); |
|
496 |
$field = field_create_field($field); |
|
497 |
|
|
498 |
$this->assertFalse(field_has_data($field), "No data should be detected."); |
|
499 |
|
|
500 |
$instance = array( |
|
501 |
'field_name' => $field_name, |
|
502 |
'entity_type' => 'test_entity', |
|
503 |
'bundle' => 'test_bundle' |
|
504 |
); |
|
505 |
$instance = field_create_instance($instance); |
|
506 |
$table = _field_sql_storage_tablename($field); |
|
507 |
$revision_table = _field_sql_storage_revision_tablename($field); |
|
508 |
|
|
509 |
$columns = array('entity_type', 'entity_id', 'revision_id', 'delta', 'language', $field_name . '_value'); |
|
510 |
|
|
511 |
$eid = 0; |
|
512 |
|
|
513 |
// Insert values into the field revision table. |
|
514 |
$query = db_insert($revision_table)->fields($columns); |
|
515 |
$query->values(array($entity_type, $eid, 0, 0, $langcode, 1)); |
|
516 |
$query->execute(); |
|
517 |
|
|
518 |
$this->assertTrue(field_has_data($field), "Revision data only should be detected."); |
|
519 |
|
|
520 |
$field_name = 'field_2'; |
|
521 |
$field = array('field_name' => $field_name, 'type' => 'test_field'); |
|
522 |
$field = field_create_field($field); |
|
523 |
|
|
524 |
$this->assertFalse(field_has_data($field), "No data should be detected."); |
|
525 |
|
|
526 |
$instance = array( |
|
527 |
'field_name' => $field_name, |
|
528 |
'entity_type' => 'test_entity', |
|
529 |
'bundle' => 'test_bundle' |
|
530 |
); |
|
531 |
$instance = field_create_instance($instance); |
|
532 |
$table = _field_sql_storage_tablename($field); |
|
533 |
$revision_table = _field_sql_storage_revision_tablename($field); |
|
534 |
|
|
535 |
$columns = array('entity_type', 'entity_id', 'revision_id', 'delta', 'language', $field_name . '_value'); |
|
536 |
|
|
537 |
$eid = 1; |
|
538 |
|
|
539 |
// Insert values into the field table. |
|
540 |
$query = db_insert($table)->fields($columns); |
|
541 |
$query->values(array($entity_type, $eid, 0, 0, $langcode, 1)); |
|
542 |
$query->execute(); |
|
543 |
|
|
544 |
$this->assertTrue(field_has_data($field), "Values only in field table should be detected."); |
|
545 |
} |
|
546 |
|
|
487 | 547 |
/** |
488 | 548 |
* Test field_attach_delete(). |
489 | 549 |
*/ |
Formats disponibles : Unified diff
Udpate to 7.33