Alternc  latest
Alternc logiel libre pour l'hébergement
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  $list = array(
18  "testVariable_getNewWayArray" => "variables-empty.yml",
19  "testVariable_getNewWayString" => "variables-empty.yml",
20  "testVariable_getOldWay" => "variables-empty.yml",
21  "default" => "variables.yml"
22  );
23  if (isset($list[$this->getName()])) {
24  $dataset_file = $list[$this->getName()];
25  } else {
26  $dataset_file = "variables.yml";
27  }
28  return parent::loadDataSet($dataset_file);
29 
30  }
31 
32  /**
33  * Sets up the fixture, for example, opens a network connection.
34  * This method is called before a test is executed.
35  */
36  protected function setUp()
37  {
38  parent::setUp();
39  $this->object = new m_variables;
40  }
41 
42  /**
43  * Tears down the fixture, for example, closes a network connection.
44  * This method is called after a test is executed.
45  */
46  protected function tearDown()
47  {
48  parent::tearDown();
49  }
50 
51  /**
52  * @covers m_variables::variable_init
53  * @depends testGet_impersonated
54  */
55  public function testVariable_init($variables)
56  {
57  $this->object->variable_init();
58  global $conf;
59  $this->assertTrue(is_array($conf));
60  }
61 
62  /**
63  * @covers m_variables::get_impersonated
64  */
65  public function testGet_impersonated()
66  {
67  $variables = $this->object->get_impersonated();
68  return $variables;
69  }
70 
71  /**
72  * @covers m_variables::variable_init_maybe
73  */
74  public function testVariable_init_maybe()
75  {
76  $this->object->variable_init_maybe();
77  $this->assertTrue( (is_array($this->object->cache_conf) && !empty($this->object->cache_conf)) );
78  }
79 
80  /**
81  * @covers m_variables::variable_get
82  */
83  public function testVariable_get()
84  {
85  $result = $this->object->variable_get("phpunit");
86  $this->assertStringMatchesFormat("phpunit",$result);
87  }
88 
89  /**
90  * @covers m_variables::variable_get
91  */
92  public function testVariable_getOldWay()
93  {
94 
95  $this->object->variable_get('phpunit', 'phpunit-default','phpunit-comment');
96  $result = $this->object->variable_get('phpunit');
97  $this->assertSame("phpunit-default",$result);
98 
99  }
100 
101  /**
102  * @covers m_variables::variable_get
103  */
105  {
106 
107  // New way
108  $this->object->variable_get('phpunit', 'phpunit-default','comment', array('desc'=>'Want a string','type'=>'string'));
109  $result = $this->object->variable_get('phpunit');
110  $this->assertSame("phpunit-default",$result);
111  }
112 
113  /**
114  * @covers m_variables::variable_get
115  */
116  public function testVariable_getNewWayArray()
117  {
118  $phpunitArray = array("ns1"=>'ns1.tld',"ip"=>"1.2.3.4");
119  $this->object->variable_get('phpunit', $phpunitArray,'phpunit-comment', array("ns1"=>array('desc'=>'ns name','type'=>'string'),"ip"=>array("desc"=>"here an ip", "type"=>"ip")));
120  $result = $this->object->variable_get('phpunit');
121  $this->assertSame($phpunitArray,$result);
122  }
123 
124  /**
125  * @covers m_variables::variable_update_or_create
126  * @expectedException \Exception
127  */
129  {
130  // Insert key with already existing key : success
131  $result = $this->object->variable_update_or_create("phpunit","phpunit-fail","DEFAULT",0);
132  }
133 
134  /**
135  * @covers m_variables::variable_update_or_create
136  */
137  public function testVariable_create()
138  {
139  // Insert key with new key : success
140  $result = $this->object->variable_update_or_create("phpunit-success","phpunit","DEFAULT",0);
141  $this->assertTrue($result);
142  $this->assertEquals(2, $this->getConnection()->getRowCount('variable'));
143 
144  }
145 
146  /**
147  * @covers m_variables::variable_update_or_create
148  */
149  public function testVariable_update()
150  {
151  $result = $this->object->variable_update_or_create("phpunit","phpunit-updated","DEFAULT",0,999);
152  $this->assertTrue($result);
153  $this->assertEquals(1, $this->getConnection()->getRowCount('variable'));
154  $expectedTable = $this->loadDataSet("variables-updated.yml")->getTable("variable");
155  $currentTable = $this->getConnection()->createQueryTable('variable', 'SELECT * FROM variable');
156  $this->assertTablesEqual($expectedTable, $currentTable);
157 
158  }
159 
160  /**
161  * @covers m_variables::del
162  */
163  public function testDel()
164  {
165  $result = $this->object->del(999);
166  $this->assertTrue($result);
167  $this->assertEquals(0, $this->getConnection()->getRowCount('variable'));
168  }
169 
170  /**
171  * @covers m_variables::display_valueraw_html
172  */
173  public function testDisplay_valueraw_html()
174  {
175  // Empty string
176  $empty_result = $this->object->display_valueraw_html(null, "phpunit",FALSE);
177  $this->assertStringMatchesFormat("<em>"._("Empty")."</em>",$empty_result);
178  // Empty array
179  $empty_array_result = $this->object->display_valueraw_html(array(), "phpunit",FALSE);
180  $this->assertStringMatchesFormat("<em>"._("Empty array")."</em>",$empty_array_result);
181  // String
182  $value_result = $this->object->display_valueraw_html("value", "phpunit",FALSE);
183  $this->assertStringMatchesFormat($value_result,$value_result);
184  // String
185  $array_result = $this->object->display_valueraw_html(array("value","value"), "phpunit",FALSE);
186  $this->assertStringMatchesFormat("<ul>%s</ul>",$array_result);
187 
188  }
189 
190  /**
191  * @covers m_variables::display_value_html
192  * @depends testVariables_list
193  */
195  {
196  $valid_result = $this->object->display_value_html($variables, "DEFAULT", 0, "phpunit",FALSE);
197  $this->assertStringMatchesFormat("phpunit",$valid_result);
198 
199  $invalid_result = $this->object->display_value_html($variables, "DEFAULT", 0, "phpunit-absent",FALSE);
200  $this->assertStringMatchesFormat("<em>"._("None defined")."</em>",$invalid_result);
201 
202  }
203 
204  /**
205  * @covers m_variables::variables_list_name
206  * @todo Implement testVariables_list_name().
207  */
208  public function testVariables_list_name()
209  {
210  $variables = $this->object->variables_list_name();
211  $this->assertTrue(is_array($variables));
212  return $variables;
213  }
214 
215  /**
216  * @covers m_variables::variables_list
217  * @todo Implement testVariables_list().
218  */
219  public function testVariables_list()
220  {
221  $variables = $this->object->variables_list();
222  $this->assertTrue(is_array($variables));
223  return $variables;
224  }
225 }
testVariable_getNewWayString()
m_variables::variable_get
testVariable_get()
m_variables::variable_get
testVariable_create()
m_variables::variable_update_or_create
tearDown()
Tears down the fixture, for example, closes a network connection.
testVariable_init($variables)
m_variables::variable_init testGet_impersonated
loadDataSet($fileList)
Definition: AlterncTest.php:24
testVariables_list()
m_variables::variables_list
$variables
Definition: bootstrap.php:146
testVariable_getNewWayArray()
m_variables::variable_get
testDel()
m_variables::del
testVariable_getOldWay()
m_variables::variable_get
testVariable_init_maybe()
m_variables::variable_init_maybe
testVariables_list_name()
m_variables::variables_list_name
if(! $admin->enabled) $conf
Manages global variables of AlternC.
This is the abstract class for all tests.
Definition: AlterncTest.php:6
testDisplay_valueraw_html()
m_variables::display_valueraw_html
setUp()
Sets up the fixture, for example, opens a network connection.
testVariable_update()
m_variables::variable_update_or_create
testGet_impersonated()
m_variables::get_impersonated
$list
Show a list of all found log files for an account and allow to see / tail / download them...
Definition: logs_list.php:30
testVariable_create_exception()
m_variables::variable_update_or_create
testDisplay_value_html( $variables)
m_variables::display_value_html testVariables_list
Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-13 at 15:55:59.