Projet

Général

Profil

Paste
Télécharger (1,86 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / simpletest / tests / entity_crud.test @ db2d93dd

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for the Entity CRUD API.
6
 */
7

    
8
/**
9
 * Tests the entity_load() function.
10
 */
11
class EntityLoadTestCase extends DrupalWebTestCase {
12
  protected $profile = 'testing';
13

    
14
  public static function getInfo() {
15
    return array(
16
      'name' => 'Entity loading',
17
      'description' => 'Tests the entity_load() function.',
18
      'group' => 'Entity API',
19
    );
20
  }
21

    
22
  /**
23
   * Tests the functionality for loading entities matching certain conditions.
24
   */
25
  public function testEntityLoadConditions() {
26
    // Create a few nodes. One of them is given an edge-case title of "Array",
27
    // because loading entities by an array of conditions is subject to PHP
28
    // array-to-string conversion issues and we want to test those.
29
    $node_1 = $this->drupalCreateNode(array('title' => 'Array'));
30
    $node_2 = $this->drupalCreateNode(array('title' => 'Node 2'));
31
    $node_3 = $this->drupalCreateNode(array('title' => 'Node 3'));
32

    
33
    // Load all entities so that they are statically cached.
34
    $all_nodes = entity_load('node', FALSE);
35

    
36
    // Check that the first node can be loaded by title.
37
    $nodes_loaded = entity_load('node', FALSE, array('title' => 'Array'));
38
    $this->assertEqual(array_keys($nodes_loaded), array($node_1->nid));
39

    
40
    // Check that the second and third nodes can be loaded by title using an
41
    // array of conditions, and that the first node is not loaded from the
42
    // cache along with them.
43
    $nodes_loaded = entity_load('node', FALSE, array('title' => array('Node 2', 'Node 3')));
44
    ksort($nodes_loaded);
45
    $this->assertEqual(array_keys($nodes_loaded), array($node_2->nid, $node_3->nid));
46
    $this->assertIdentical($nodes_loaded[$node_2->nid], $all_nodes[$node_2->nid], 'Loaded node 2 is identical to cached node.');
47
    $this->assertIdentical($nodes_loaded[$node_3->nid], $all_nodes[$node_3->nid], 'Loaded node 3 is identical to cached node.');
48
  }
49
}