Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / tests / math_expression_stack.test @ 6e3ce7c2

1
<?php
2

    
3
/**
4
 * Tests the simple MathExpressionStack class.
5
 */
6
class CtoolsMathExpressionStackTestCase extends DrupalWebTestCase {
7

    
8
  /**
9
   * {@inheritdoc}
10
   */
11
  public static function getInfo() {
12
    return array(
13
      'name' => 'Math expressions stack',
14
      'description' => 'Test the stack class of the math expression library.',
15
      'group' => 'ctools',
16
      'dependencies' => array('ctools'),
17
    );
18
  }
19

    
20
  /**
21
   * {@inheritdoc}
22
   */
23
  public function setUp(array $modules = array()) {
24
    $modules[] = 'ctools';
25
    $modules[] = 'ctools_plugin_test';
26
    parent::setUp($modules);
27
  }
28

    
29
  /**
30
   * Test the math expression stack system.
31
   */
32
  public function testStack() {
33
    $stack = new ctools_math_expr_stack();
34

    
35
    // Test the empty stack.
36
    $this->assertNull($stack->last());
37
    $this->assertNull($stack->pop());
38

    
39
    // Add an element and see whether it's the right element.
40
    $value = $this->randomName();
41
    $stack->push($value);
42
    $this->assertIdentical($value, $stack->last());
43
    $this->assertIdentical($value, $stack->pop());
44
    $this->assertNull($stack->pop());
45

    
46
    // Add multiple elements and see whether they are returned in the right
47
    // order.
48
    $values = array($this->randomName(), $this->randomName(), $this->randomName());
49
    foreach ($values as $value) {
50
      $stack->push($value);
51
    }
52

    
53
    // Test the different elements at different positions with the last()
54
    // method.
55
    $count = count($values);
56
    foreach ($values as $key => $value) {
57
      $this->assertEqual($value, $stack->last($count - $key));
58
    }
59

    
60
    // Pass in a non-valid number to last.
61
    $non_valid_number = rand(10, 20);
62
    $this->assertNull($stack->last($non_valid_number));
63

    
64
    // Test the order of the poping.
65
    $values = array_reverse($values);
66
    foreach ($values as $key => $value) {
67
      $this->assertEqual($stack->last(), $value);
68
      $this->assertEqual($stack->pop(), $value);
69
    }
70
    $this->assertNull($stack->pop());
71
  }
72

    
73
}