Alternc  3.2
Alternc logiel libre pour l'h├ębergement
 All Data Structures Namespaces Files Functions Variables Pages
m_variablesTest.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-13 at 15:55:59.
4  */
6 {
7  /**
8  * @var m_variables
9  */
10  protected $object;
11 
12  /**
13  * @return PHPUnit_Extensions_Database_DataSet_IDataSet
14  */
15  public function getDataSet()
16  {
17  return parent::loadDataSet("variables.yml");
18  }
19 
20  /**
21  * Sets up the fixture, for example, opens a network connection.
22  * This method is called before a test is executed.
23  */
24  protected function setUp()
25  {
26  parent::setUp();
27  $this->object = new m_variables;
28  }
29 
30  /**
31  * Tears down the fixture, for example, closes a network connection.
32  * This method is called after a test is executed.
33  */
34  protected function tearDown()
35  {
37  }
38 
39  /**
40  * @covers m_variables::variable_init
41  * @depends testGet_impersonated
42  */
43  public function testVariable_init($variables)
44  {
45  $this->object->variable_init();
46  global $conf;
47  $this->assertTrue(is_array($conf));
48  }
49 
50  /**
51  * @covers m_variables::get_impersonated
52  */
53  public function testGet_impersonated()
54  {
55  $variables = $this->object->get_impersonated();
56  return $variables;
57  }
58 
59  /**
60  * @covers m_variables::variable_init_maybe
61  */
62  public function testVariable_init_maybe()
63  {
64  $this->object->variable_init_maybe();
65  global $conf;
66  $this->assertTrue(is_array($conf));
67  }
68 
69  /**
70  * @covers m_variables::variable_get
71  */
72  public function testVariable_get()
73  {
74  $result = $this->object->variable_get("phpunit");
75  $this->assertStringMatchesFormat("phpunit",$result);
76  }
77 
78  /**
79  * @covers m_variables::variable_update_or_create
80  * @expectedException \Exception
81  */
83  {
84  // Insert key with already existing key : success
85  $result = $this->object->variable_update_or_create("phpunit","phpunit-fail","DEFAULT",0);
86  }
87 
88  /**
89  * @covers m_variables::variable_update_or_create
90  */
91  public function testVariable_create()
92  {
93  // Insert key with new key : success
94  $result = $this->object->variable_update_or_create("phpunit-success","phpunit","DEFAULT",0);
95  $this->assertTrue($result);
96  $this->assertEquals(2, $this->getConnection()->getRowCount('variable'));
97 
98  }
99 
100  /**
101  * @covers m_variables::variable_update_or_create
102  */
103  public function testVariable_update()
104  {
105  $result = $this->object->variable_update_or_create("phpunit","phpunit-updated","DEFAULT",0,999);
106  $this->assertTrue($result);
107  $this->assertEquals(1, $this->getConnection()->getRowCount('variable'));
108  $expectedTable = $this->loadDataSet("variables-updated.yml")->getTable("variable");
109  $currentTable = $this->getConnection()->createQueryTable('variable', 'SELECT * FROM variable');
110  $this->assertTablesEqual($expectedTable, $currentTable);
111 
112  }
113 
114  /**
115  * @covers m_variables::del
116  */
117  public function testDel()
118  {
119  $result = $this->object->del(999);
120  $this->assertTrue($result);
121  $this->assertEquals(0, $this->getConnection()->getRowCount('variable'));
122  }
123 
124  /**
125  * @covers m_variables::display_valueraw_html
126  */
127  public function testDisplay_valueraw_html()
128  {
129  // Empty string
130  $empty_result = $this->object->display_valueraw_html(null, "phpunit",FALSE);
131  $this->assertStringMatchesFormat("<em>"._("Empty")."</em>",$empty_result);
132  // Empty array
133  $empty_array_result = $this->object->display_valueraw_html(array(), "phpunit",FALSE);
134  $this->assertStringMatchesFormat("<em>"._("Empty array")."</em>",$empty_array_result);
135  // String
136  $value_result = $this->object->display_valueraw_html("value", "phpunit",FALSE);
137  $this->assertStringMatchesFormat($value_result,$value_result);
138  // String
139  $array_result = $this->object->display_valueraw_html(array("value","value"), "phpunit",FALSE);
140  $this->assertStringMatchesFormat("<ul>%s</ul>",$array_result);
141 
142  }
143 
144  /**
145  * @covers m_variables::display_value_html
146  * @depends testVariables_list
147  */
149  {
150  $valid_result = $this->object->display_value_html($variables, "DEFAULT", 0, "phpunit",FALSE);
151  $this->assertStringMatchesFormat("phpunit",$valid_result);
152 
153  $invalid_result = $this->object->display_value_html($variables, "DEFAULT", 0, "phpunit-absent",FALSE);
154  $this->assertStringMatchesFormat("<em>"._("None defined")."</em>",$invalid_result);
155 
156  }
157 
158  /**
159  * @covers m_variables::variables_list_name
160  * @todo Implement testVariables_list_name().
161  */
162  public function testVariables_list_name()
163  {
164  $variables = $this->object->variables_list_name();
165  $this->assertTrue(is_array($variables));
166  return $variables;
167  }
168 
169  /**
170  * @covers m_variables::variables_list
171  * @todo Implement testVariables_list().
172  */
173  public function testVariables_list()
174  {
175  $variables = $this->object->variables_list();
176  $this->assertTrue(is_array($variables));
177  return $variables;
178  }
179 }