ImportTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file test/phpunit/ImportTest.php
  20. * \ingroup test
  21. * \brief PHPUnit test
  22. * \remarks To run this script as CLI: phpunit filename.php
  23. */
  24. global $conf,$user,$langs,$db;
  25. //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
  26. //require_once 'PHPUnit/Autoload.php';
  27. require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
  28. if (! defined('NOREQUIREUSER')) {
  29. define('NOREQUIREUSER', '1');
  30. }
  31. if (! defined('NOREQUIREDB')) {
  32. define('NOREQUIREDB', '1');
  33. }
  34. if (! defined('NOREQUIRESOC')) {
  35. define('NOREQUIRESOC', '1');
  36. }
  37. if (! defined('NOREQUIRETRAN')) {
  38. define('NOREQUIRETRAN', '1');
  39. }
  40. if (! defined('NOCSRFCHECK')) {
  41. define('NOCSRFCHECK', '1');
  42. }
  43. if (! defined('NOTOKENRENEWAL')) {
  44. define('NOTOKENRENEWAL', '1');
  45. }
  46. if (! defined('NOREQUIREMENU')) {
  47. define('NOREQUIREMENU', '1'); // If there is no menu to show
  48. }
  49. if (! defined('NOREQUIREHTML')) {
  50. define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
  51. }
  52. if (! defined('NOREQUIREAJAX')) {
  53. define('NOREQUIREAJAX', '1');
  54. }
  55. if (! defined("NOLOGIN")) {
  56. define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
  57. }
  58. /**
  59. * Class for PHPUnit tests
  60. *
  61. * @backupGlobals disabled
  62. * @backupStaticAttributes enabled
  63. * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
  64. */
  65. class ImportTest extends PHPUnit\Framework\TestCase
  66. {
  67. protected $savconf;
  68. protected $savuser;
  69. protected $savlangs;
  70. protected $savdb;
  71. /**
  72. * Constructor
  73. * We save global variables into local variables
  74. *
  75. * @return ImportTest
  76. */
  77. public function __construct()
  78. {
  79. parent::__construct();
  80. //$this->sharedFixture
  81. global $conf,$user,$langs,$db;
  82. $this->savconf=$conf;
  83. $this->savuser=$user;
  84. $this->savlangs=$langs;
  85. $this->savdb=$db;
  86. print __METHOD__." db->type=".$db->type." user->id=".$user->id;
  87. //print " - db ".$db->db;
  88. print "\n";
  89. }
  90. /**
  91. * setUpBeforeClass
  92. *
  93. * @return void
  94. */
  95. public static function setUpBeforeClass()
  96. {
  97. global $conf,$user,$langs,$db;
  98. //$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
  99. print __METHOD__."\n";
  100. }
  101. /**
  102. * tearDownAfterClass
  103. *
  104. * @return void
  105. */
  106. public static function tearDownAfterClass()
  107. {
  108. global $conf,$user,$langs,$db;
  109. //$db->rollback();
  110. print __METHOD__."\n";
  111. }
  112. /**
  113. * Init phpunit tests
  114. *
  115. * @return void
  116. */
  117. protected function setUp()
  118. {
  119. global $conf,$user,$langs,$db;
  120. $conf=$this->savconf;
  121. $user=$this->savuser;
  122. $langs=$this->savlangs;
  123. $db=$this->savdb;
  124. print __METHOD__."\n";
  125. }
  126. /**
  127. * End phpunit tests
  128. *
  129. * @return void
  130. */
  131. protected function tearDown()
  132. {
  133. print __METHOD__."\n";
  134. }
  135. /**
  136. * testImportSample1
  137. *
  138. * @return boolean
  139. */
  140. public function testImportSample1()
  141. {
  142. $file=dirname(__FILE__).'/Example_import_company_1.csv';
  143. // TODO
  144. // Run import on file and check the record with field "auto" are filled
  145. // according to option
  146. $this->assertEquals(0, 0);
  147. // TODO Export and compare the file exported with the $file imported.
  148. return true;
  149. }
  150. }