diff --git a/unit-test/README b/unit-test/README new file mode 100644 index 000000000..ff98d8a26 --- /dev/null +++ b/unit-test/README @@ -0,0 +1,13 @@ +Ce répertoire sert aux tests unitaires avec PHPUNIT, il faut d'abord changer dans le bootstrap.php pour que le path soit correct. +Il faut configurer Netbeans pour pouvoir l'utiliser : +1 . Activer PHPUNIT, +2 . dans GLOBAL PATH (propriété du projet) ajouter le fichier phpunit.phar +3. Donner unit-test comme répertoire de test + +Ensuite copier bootstrap.php.example vers bootstrap.php et modifier les variables (le dossier à utiliser, include_path ...) + +Testing commande en ligne +========================= +Génération + php /phpunit-skelgen.phar --bootstrap bootstrap.php --test -- Intervat ../include/class_transform_intervat.php + php /phpunit.phar --tap --colors --bootstrap ../bootstrap.php class_acc_accountTest.php \ No newline at end of file diff --git a/unit-test/bootstrap.php.example b/unit-test/bootstrap.php.example new file mode 100644 index 000000000..62936a036 --- /dev/null +++ b/unit-test/bootstrap.php.example @@ -0,0 +1,154 @@ +object=new Acc_Account($g_connection,400); + $this->object->load(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + } + + /** + * @covers Acc_Account::get_parameter + * @todo Implement testGet_parameter(). + * @backupGlobals enabled + */ + public function testGet_parameter() + { + $value=$this->object->get_parameter("value"); + $this->assertEquals($value,'400'); + + } + + /** + * @covers Acc_Account::set_parameter + * @todo Implement testSet_parameter(). + * @backupGlobals enabled + */ + public function testSet_parameter() + { + $this->object->set_parameter("value",500); + $value=$this->object->get_parameter("value"); + $this->assertEquals($value,500); + } + + /** + * @covers Acc_Account::get_lib + * @todo Implement testGet_lib(). + */ + public function testGet_lib() + { + $value=$this->object->get_lib(); + $this->assertEquals($value,'Clients'); + } + + /** + * @covers Acc_Account::check + * @todo Implement testCheck(). + */ + public function testCheck() + { + $value=$this->object->check('pcm_val'); + $this->assertTrue($value); + $value=$this->object->check('pcm_lib'); + $this->assertTrue($value); + $value=$this->object->check('pcm_val_parent'); + $this->assertTrue($value); + $value=$this->object->check('pcm_type','CHA'); + $this->assertTrue($value); + $this->setExpectedException("Exception"); + $value=$this->object->check('unknown'); + + } + + /** + * @covers Acc_Account::load + * @todo Implement testLoad(). + */ + public function testLoad() + { + $this->object->load(); + } + + /** + * @covers Acc_Account::form + * @todo Implement testForm(). + */ + public function testForm() + { + $_REQUEST['gDossier']=36; + $this->object->form(); + } + + /** + * @covers Acc_Account::count + * @todo Implement testCount(). + */ + public function testCount() + { + + $this->assertEquals($this->object->count('550'),1); + $this->assertEquals($this->object->count('500'),0); + } + + /** + * @covers Acc_Account::test_me + * @todo Implement testTest_me(). + */ + public function testTest_me() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Acc_Account::update + * @todo Implement testUpdate(). + */ + public function testUpdate() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + +} diff --git a/unit-test/include/class_acc_account_ledgerTest.php b/unit-test/include/class_acc_account_ledgerTest.php new file mode 100644 index 000000000..e49e39ebe --- /dev/null +++ b/unit-test/include/class_acc_account_ledgerTest.php @@ -0,0 +1,299 @@ +object=new Acc_Account_Ledger($g_connection, 400); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + } + + /** + * @covers Acc_Account_Ledger::get_row + * @todo Implement testGet_row(). + */ + public function testGet_row() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Acc_Account_Ledger::get_row_date + * @todo Implement testGet_row_date(). + */ + public function testGet_row_date() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + function dataGet_Name() + { + return array( + array('10','Capital '), + array('01','Poste inconnu') + ); + } + /** + * @covers Acc_Account_Ledger::get_name + * @todo Implement testGet_name(). + * @dataProvider dataGet_Name + */ + public function testGet_name($id,$result) + { + $this->object->id=$id; + $this->assertEquals($this->object->get_name(),$result); + } + + /** + * @covers Acc_Account_Ledger::do_exist + * @todo Implement testDo_exist(). + * @dataProvider dataDo_exist + */ + public function testDo_exist($p_value, $result) + { + $this->object->id=$p_value; + $this->assertEquals($this->object->do_exist(), $result); + } + + function dataDo_exist() + { + return array( + array('400', 1), + array('400A', 0), + array('550', 1), + array('60BXX', 0) + ); + } + + /** + * @covers Acc_Account_Ledger::load + * @todo Implement testLoad(). + */ + public function testLoad() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Acc_Account_Ledger::get + * @todo Implement testGet(). + */ + public function testGet() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Acc_Account_Ledger::get_solde + * @todo Implement testGet_solde(). + */ + public function testGet_solde() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Acc_Account_Ledger::get_solde_detail + * @todo Implement testGet_solde_detail(). + */ + public function testGet_solde_detail() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Acc_Account_Ledger::isTVA + * @todo Implement testIsTVA(). + */ + public function testIsTVA() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Acc_Account_Ledger::HtmlTable + * @todo Implement testHtmlTable(). + */ + public function testHtmlTable() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + public function dataGet_amount_side() + { + return array ( + array(0,"="), + array(1000,D), + array(-1000,C), + ); + } + /** + * @covers Acc_Account_Ledger::get_amount_side + * @todo Implement testGet_amount_side(). + * @dataProvider dataGet_amount_side + */ + public function testGet_amount_side($amount,$result) + { + $this->assertEquals($this->object->get_amount_side($amount),$result); + } + + /** + * @covers Acc_Account_Ledger::HtmlTableHeader + * @todo Implement testHtmlTableHeader(). + */ + public function testHtmlTableHeader() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Acc_Account_Ledger::belong_ledger + * @todo Implement testBelong_ledger(). + * @dataProvider DataBelong_ledger + */ + public function testBelong_ledger($p_jrn, $result) + { + $this->assertEquals($this->object->belong_ledger($p_jrn), $result); + } + + function DataBelong_ledger() + { + return array( + array(0, -1), + array(1, -1), + array(3, -1), + array(2, 0), + array(4, 0) + ); + } + public function dataGet_account_ledger() + { + return array( + array(0,array()), + array(1,array('5*','')), + array(2,array('4*')), + array(3,array('6*')) + + ); + } + /** + * @covers Acc_Account_Ledger::get_account_ledger + * @todo Implement testGet_account_ledger(). + * @dataProvider dataGet_account_ledger + */ + public function testGet_account_ledger($p_jrn,$result) + { + echo "ledger $p_jrn"; + $this->assertEquals($this->object->get_account_ledger($p_jrn),$result); + printf ("\n"); + } + + /** + * @covers Acc_Account_Ledger::build_sql_account + * @todo Implement testBuild_sql_account(). + * @dataProvider DataBuild_Sql_account + */ + public function testBuild_sql_account($p_jrn, $result) + { + print "\n--------------------\n"; + $value=$this->object->build_sql_account($p_jrn); + printf(" ledger %s [%s]", $p_jrn, $value); + $this->assertEquals(trim($value), $result); + } + + public function DataBuild_Sql_account() + { + return array( + array(0, ""), + array(1, "pcm_val::text like '5%'"), + array(2, "pcm_val::text like '4%'"), + array(3, "pcm_val::text like '6%'"), + array(4, "") + ); + } + + function dataFind_Card() + { + return array( + array('6191', '22'), + array('6192', '23'), + array('4400004', '25') + ); + } + + /** + * @covers Acc_Account_Ledger::find_card + * @todo Implement testFind_card(). + * @dataProvider dataFind_Card() + */ + public function testFind_card($p_value, $p_card) + { + $this->object->id=$p_value; + $result=$this->object->find_card(); + $this->assertEquals($p_card, $result[0]['f_id']); + } + + /** + * @covers Acc_Account_Ledger::test_me + * @todo Implement testTest_me(). + */ + public function testTest_me() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + +}