2014-03-19 09:15:54 +00:00
< ? php
/**
* Generated by PHPUnit_SkeletonGenerator 1.2 . 1 on 2014 - 03 - 13 at 15 : 55 : 59.
*/
2014-03-22 14:42:59 +00:00
class m_variablesTest extends AlterncTest
2014-03-19 09:15:54 +00:00
{
/**
* @ var m_variables
*/
protected $object ;
2014-03-22 14:42:59 +00:00
/**
* @ return PHPUnit_Extensions_Database_DataSet_IDataSet
*/
public function getDataSet ()
{
return parent :: loadDataSet ( " variables.yml " );
}
2014-03-19 09:15:54 +00:00
/**
* Sets up the fixture , for example , opens a network connection .
* This method is called before a test is executed .
*/
protected function setUp ()
{
2014-03-22 14:42:59 +00:00
parent :: setUp ();
2014-03-19 09:15:54 +00:00
$this -> object = new m_variables ;
}
/**
* Tears down the fixture , for example , closes a network connection .
* This method is called after a test is executed .
*/
protected function tearDown ()
{
2014-03-22 14:42:59 +00:00
parent :: tearDown ();
2014-03-19 09:15:54 +00:00
}
/**
* @ covers m_variables :: variable_init
2014-03-22 14:42:59 +00:00
* @ depends testGet_impersonated
2014-03-19 09:15:54 +00:00
*/
2014-03-22 14:42:59 +00:00
public function testVariable_init ( $variables )
2014-03-19 09:15:54 +00:00
{
2014-03-22 14:42:59 +00:00
$this -> object -> variable_init ();
global $conf ;
$this -> assertTrue ( is_array ( $conf ));
2014-03-19 09:15:54 +00:00
}
/**
* @ covers m_variables :: get_impersonated
*/
public function testGet_impersonated ()
{
2014-03-22 14:42:59 +00:00
$variables = $this -> object -> get_impersonated ();
return $variables ;
2014-03-19 09:15:54 +00:00
}
/**
* @ covers m_variables :: variable_init_maybe
*/
public function testVariable_init_maybe ()
{
2014-03-22 14:42:59 +00:00
$this -> object -> variable_init_maybe ();
2014-03-28 14:36:10 +00:00
$this -> assertTrue ( ( is_array ( $this -> object -> cache_conf ) && ! empty ( $this -> object -> cache_conf )) );
2014-03-19 09:15:54 +00:00
}
/**
* @ covers m_variables :: variable_get
*/
public function testVariable_get ()
{
2014-03-22 14:42:59 +00:00
$result = $this -> object -> variable_get ( " phpunit " );
$this -> assertStringMatchesFormat ( " phpunit " , $result );
2014-03-28 14:28:25 +00:00
/*
// Check old way
$this -> object -> variable_get ( 'phpunit1' , 'toto' , 'plop' );
$result = $this -> object -> variable_get ( 'phpunit1' );
$this -> assertSame ( " toto " , $result );
// New way
$this -> object -> variable_get ( 'phpunit2' , 'here' , 'comment' , array ( 'desc' => 'Want a string' , 'type' => 'string' ));
$result = $this -> object -> variable_get ( 'phpunit2' );
$this -> assertSame ( " here " , $result );
$this -> object -> variable_get ( 'phpunit3' , array ( " ns1 " => 'ns1.tld' , " ip " => " 1.2.3.4 " ), 'comment' , array ( " ns1 " => array ( 'desc' => 'ns name' , 'type' => 'string' ), " ip " => array ( " desc " => " here an ip " , " type " => " ip " )));
$result = $this -> object -> variable_get ( 'phpunit2' );
$this -> assertSame ( array ( 'ns1' => " ns1.tld " , " ip " => " 1.2.3.4 " ), $result );
*/
2014-03-19 09:15:54 +00:00
}
/**
* @ covers m_variables :: variable_update_or_create
2014-03-22 14:42:59 +00:00
* @ expectedException \Exception
*/
public function testVariable_create_exception ()
{
// Insert key with already existing key : success
$result = $this -> object -> variable_update_or_create ( " phpunit " , " phpunit-fail " , " DEFAULT " , 0 );
}
/**
* @ covers m_variables :: variable_update_or_create
2014-03-19 09:15:54 +00:00
*/
2014-03-22 14:42:59 +00:00
public function testVariable_create ()
2014-03-19 09:15:54 +00:00
{
2014-03-22 14:42:59 +00:00
// Insert key with new key : success
$result = $this -> object -> variable_update_or_create ( " phpunit-success " , " phpunit " , " DEFAULT " , 0 );
$this -> assertTrue ( $result );
$this -> assertEquals ( 2 , $this -> getConnection () -> getRowCount ( 'variable' ));
}
/**
* @ covers m_variables :: variable_update_or_create
*/
public function testVariable_update ()
{
$result = $this -> object -> variable_update_or_create ( " phpunit " , " phpunit-updated " , " DEFAULT " , 0 , 999 );
$this -> assertTrue ( $result );
$this -> assertEquals ( 1 , $this -> getConnection () -> getRowCount ( 'variable' ));
$expectedTable = $this -> loadDataSet ( " variables-updated.yml " ) -> getTable ( " variable " );
$currentTable = $this -> getConnection () -> createQueryTable ( 'variable' , 'SELECT * FROM variable' );
$this -> assertTablesEqual ( $expectedTable , $currentTable );
2014-03-19 09:15:54 +00:00
}
/**
* @ covers m_variables :: del
*/
public function testDel ()
{
2014-03-22 14:42:59 +00:00
$result = $this -> object -> del ( 999 );
$this -> assertTrue ( $result );
$this -> assertEquals ( 0 , $this -> getConnection () -> getRowCount ( 'variable' ));
2014-03-19 09:15:54 +00:00
}
/**
* @ covers m_variables :: display_valueraw_html
*/
public function testDisplay_valueraw_html ()
{
2014-03-22 14:42:59 +00:00
// Empty string
$empty_result = $this -> object -> display_valueraw_html ( null , " phpunit " , FALSE );
$this -> assertStringMatchesFormat ( " <em> " . _ ( " Empty " ) . " </em> " , $empty_result );
// Empty array
$empty_array_result = $this -> object -> display_valueraw_html ( array (), " phpunit " , FALSE );
$this -> assertStringMatchesFormat ( " <em> " . _ ( " Empty array " ) . " </em> " , $empty_array_result );
// String
$value_result = $this -> object -> display_valueraw_html ( " value " , " phpunit " , FALSE );
$this -> assertStringMatchesFormat ( $value_result , $value_result );
// String
$array_result = $this -> object -> display_valueraw_html ( array ( " value " , " value " ), " phpunit " , FALSE );
$this -> assertStringMatchesFormat ( " <ul>%s</ul> " , $array_result );
2014-03-19 09:15:54 +00:00
}
/**
* @ covers m_variables :: display_value_html
2014-03-22 14:42:59 +00:00
* @ depends testVariables_list
2014-03-19 09:15:54 +00:00
*/
2014-03-22 14:42:59 +00:00
public function testDisplay_value_html ( $variables )
2014-03-19 09:15:54 +00:00
{
2014-03-22 14:42:59 +00:00
$valid_result = $this -> object -> display_value_html ( $variables , " DEFAULT " , 0 , " phpunit " , FALSE );
$this -> assertStringMatchesFormat ( " phpunit " , $valid_result );
$invalid_result = $this -> object -> display_value_html ( $variables , " DEFAULT " , 0 , " phpunit-absent " , FALSE );
$this -> assertStringMatchesFormat ( " <em> " . _ ( " None defined " ) . " </em> " , $invalid_result );
2014-03-19 09:15:54 +00:00
}
/**
* @ covers m_variables :: variables_list_name
* @ todo Implement testVariables_list_name () .
*/
public function testVariables_list_name ()
{
2014-03-22 14:42:59 +00:00
$variables = $this -> object -> variables_list_name ();
$this -> assertTrue ( is_array ( $variables ));
return $variables ;
2014-03-19 09:15:54 +00:00
}
/**
* @ covers m_variables :: variables_list
* @ todo Implement testVariables_list () .
*/
public function testVariables_list ()
{
2014-03-22 14:42:59 +00:00
$variables = $this -> object -> variables_list ();
$this -> assertTrue ( is_array ( $variables ));
return $variables ;
2014-03-19 09:15:54 +00:00
}
}