@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | |
32 | 32 | if (empty($user->id)) |
33 | 33 | { |
34 | - print "Load permissions for admin user nb 1\n"; |
|
35 | - $user->fetch(1); |
|
36 | - $user->getrights(); |
|
34 | + print "Load permissions for admin user nb 1\n"; |
|
35 | + $user->fetch(1); |
|
36 | + $user->getrights(); |
|
37 | 37 | } |
38 | 38 | $conf->global->MAIN_DISABLE_ALL_MAILS=1; |
39 | 39 | |
@@ -47,75 +47,75 @@ discard block |
||
47 | 47 | */ |
48 | 48 | class FormAdminTest extends PHPUnit_Framework_TestCase |
49 | 49 | { |
50 | - protected $savconf; |
|
51 | - protected $savuser; |
|
52 | - protected $savlangs; |
|
53 | - protected $savdb; |
|
54 | - |
|
55 | - /** |
|
56 | - * Constructor |
|
57 | - * We save global variables into local variables |
|
58 | - * |
|
59 | - * @return FactureTest |
|
60 | - */ |
|
61 | - function __construct() |
|
62 | - { |
|
63 | - parent::__construct(); |
|
64 | - |
|
65 | - //$this->sharedFixture |
|
66 | - global $conf,$user,$langs,$db; |
|
67 | - $this->savconf=$conf; |
|
68 | - $this->savuser=$user; |
|
69 | - $this->savlangs=$langs; |
|
70 | - $this->savdb=$db; |
|
71 | - |
|
72 | - print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
|
73 | - //print " - db ".$db->db; |
|
74 | - print "\n"; |
|
75 | - } |
|
76 | - |
|
77 | - // Static methods |
|
78 | - public static function setUpBeforeClass() |
|
50 | + protected $savconf; |
|
51 | + protected $savuser; |
|
52 | + protected $savlangs; |
|
53 | + protected $savdb; |
|
54 | + |
|
55 | + /** |
|
56 | + * Constructor |
|
57 | + * We save global variables into local variables |
|
58 | + * |
|
59 | + * @return FactureTest |
|
60 | + */ |
|
61 | + function __construct() |
|
62 | + { |
|
63 | + parent::__construct(); |
|
64 | + |
|
65 | + //$this->sharedFixture |
|
66 | + global $conf,$user,$langs,$db; |
|
67 | + $this->savconf=$conf; |
|
68 | + $this->savuser=$user; |
|
69 | + $this->savlangs=$langs; |
|
70 | + $this->savdb=$db; |
|
71 | + |
|
72 | + print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
|
73 | + //print " - db ".$db->db; |
|
74 | + print "\n"; |
|
75 | + } |
|
76 | + |
|
77 | + // Static methods |
|
78 | + public static function setUpBeforeClass() |
|
79 | 79 | { |
80 | - global $conf,$user,$langs,$db; |
|
81 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
80 | + global $conf,$user,$langs,$db; |
|
81 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
82 | 82 | |
83 | - print __METHOD__."\n"; |
|
83 | + print __METHOD__."\n"; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | // tear down after class |
87 | 87 | public static function tearDownAfterClass() |
88 | 88 | { |
89 | - global $conf,$user,$langs,$db; |
|
90 | - $db->rollback(); |
|
89 | + global $conf,$user,$langs,$db; |
|
90 | + $db->rollback(); |
|
91 | 91 | |
92 | - print __METHOD__."\n"; |
|
92 | + print __METHOD__."\n"; |
|
93 | 93 | } |
94 | 94 | |
95 | - /** |
|
96 | - * Init phpunit tests |
|
97 | - * |
|
98 | - * @return void |
|
99 | - */ |
|
95 | + /** |
|
96 | + * Init phpunit tests |
|
97 | + * |
|
98 | + * @return void |
|
99 | + */ |
|
100 | 100 | protected function setUp() |
101 | 101 | { |
102 | - global $conf,$user,$langs,$db; |
|
103 | - $conf=$this->savconf; |
|
104 | - $user=$this->savuser; |
|
105 | - $langs=$this->savlangs; |
|
106 | - $db=$this->savdb; |
|
102 | + global $conf,$user,$langs,$db; |
|
103 | + $conf=$this->savconf; |
|
104 | + $user=$this->savuser; |
|
105 | + $langs=$this->savlangs; |
|
106 | + $db=$this->savdb; |
|
107 | 107 | |
108 | - print __METHOD__."\n"; |
|
108 | + print __METHOD__."\n"; |
|
109 | 109 | } |
110 | 110 | |
111 | - /** |
|
112 | - * End phpunit tests |
|
113 | - * |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - protected function tearDown() |
|
111 | + /** |
|
112 | + * End phpunit tests |
|
113 | + * |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + protected function tearDown() |
|
117 | 117 | { |
118 | - print __METHOD__."\n"; |
|
118 | + print __METHOD__."\n"; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -125,17 +125,17 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function testSelectPaperFormat() |
127 | 127 | { |
128 | - global $conf,$user,$langs,$db; |
|
129 | - $conf=$this->savconf; |
|
130 | - $user=$this->savuser; |
|
131 | - $langs=$this->savlangs; |
|
132 | - $db=$this->savdb; |
|
133 | - |
|
134 | - $localobject=new FormAdmin($this->savdb); |
|
135 | - $result=$localobject->select_paper_format('','paperformat_id','A4'); |
|
136 | - |
|
137 | - $this->assertEquals($result, '<select class="flat" id="paperformat_id" name="paperformat_id"><option value="EUA4">Format A4 - 210x297 mm</option></select>'); |
|
138 | - print __METHOD__." result=".$result."\n"; |
|
139 | - return $result; |
|
128 | + global $conf,$user,$langs,$db; |
|
129 | + $conf=$this->savconf; |
|
130 | + $user=$this->savuser; |
|
131 | + $langs=$this->savlangs; |
|
132 | + $db=$this->savdb; |
|
133 | + |
|
134 | + $localobject=new FormAdmin($this->savdb); |
|
135 | + $result=$localobject->select_paper_format('','paperformat_id','A4'); |
|
136 | + |
|
137 | + $this->assertEquals($result, '<select class="flat" id="paperformat_id" name="paperformat_id"><option value="EUA4">Format A4 - 210x297 mm</option></select>'); |
|
138 | + print __METHOD__." result=".$result."\n"; |
|
139 | + return $result; |
|
140 | 140 | } |
141 | 141 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
24 | 24 | */ |
25 | 25 | |
26 | -global $conf,$user,$langs,$db; |
|
26 | +global $conf, $user, $langs, $db; |
|
27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $user->fetch(1); |
36 | 36 | $user->getrights(); |
37 | 37 | } |
38 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
38 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
39 | 39 | |
40 | 40 | |
41 | 41 | /** |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | parent::__construct(); |
64 | 64 | |
65 | 65 | //$this->sharedFixture |
66 | - global $conf,$user,$langs,$db; |
|
67 | - $this->savconf=$conf; |
|
68 | - $this->savuser=$user; |
|
69 | - $this->savlangs=$langs; |
|
70 | - $this->savdb=$db; |
|
66 | + global $conf, $user, $langs, $db; |
|
67 | + $this->savconf = $conf; |
|
68 | + $this->savuser = $user; |
|
69 | + $this->savlangs = $langs; |
|
70 | + $this->savdb = $db; |
|
71 | 71 | |
72 | 72 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
73 | 73 | //print " - db ".$db->db; |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | // Static methods |
78 | 78 | public static function setUpBeforeClass() |
79 | 79 | { |
80 | - global $conf,$user,$langs,$db; |
|
81 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
80 | + global $conf, $user, $langs, $db; |
|
81 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
82 | 82 | |
83 | 83 | print __METHOD__."\n"; |
84 | 84 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | // tear down after class |
87 | 87 | public static function tearDownAfterClass() |
88 | 88 | { |
89 | - global $conf,$user,$langs,$db; |
|
89 | + global $conf, $user, $langs, $db; |
|
90 | 90 | $db->rollback(); |
91 | 91 | |
92 | 92 | print __METHOD__."\n"; |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | */ |
100 | 100 | protected function setUp() |
101 | 101 | { |
102 | - global $conf,$user,$langs,$db; |
|
103 | - $conf=$this->savconf; |
|
104 | - $user=$this->savuser; |
|
105 | - $langs=$this->savlangs; |
|
106 | - $db=$this->savdb; |
|
102 | + global $conf, $user, $langs, $db; |
|
103 | + $conf = $this->savconf; |
|
104 | + $user = $this->savuser; |
|
105 | + $langs = $this->savlangs; |
|
106 | + $db = $this->savdb; |
|
107 | 107 | |
108 | 108 | print __METHOD__."\n"; |
109 | 109 | } |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function testSelectPaperFormat() |
127 | 127 | { |
128 | - global $conf,$user,$langs,$db; |
|
129 | - $conf=$this->savconf; |
|
130 | - $user=$this->savuser; |
|
131 | - $langs=$this->savlangs; |
|
132 | - $db=$this->savdb; |
|
133 | - |
|
134 | - $localobject=new FormAdmin($this->savdb); |
|
135 | - $result=$localobject->select_paper_format('','paperformat_id','A4'); |
|
128 | + global $conf, $user, $langs, $db; |
|
129 | + $conf = $this->savconf; |
|
130 | + $user = $this->savuser; |
|
131 | + $langs = $this->savlangs; |
|
132 | + $db = $this->savdb; |
|
133 | + |
|
134 | + $localobject = new FormAdmin($this->savdb); |
|
135 | + $result = $localobject->select_paper_format('', 'paperformat_id', 'A4'); |
|
136 | 136 | |
137 | 137 | $this->assertEquals($result, '<select class="flat" id="paperformat_id" name="paperformat_id"><option value="EUA4">Format A4 - 210x297 mm</option></select>'); |
138 | 138 | print __METHOD__." result=".$result."\n"; |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | |
33 | 33 | if (empty($user->id)) |
34 | 34 | { |
35 | - print "Load permissions for admin user nb 1\n"; |
|
36 | - $user->fetch(1); |
|
37 | - $user->getrights(); |
|
35 | + print "Load permissions for admin user nb 1\n"; |
|
36 | + $user->fetch(1); |
|
37 | + $user->getrights(); |
|
38 | 38 | } |
39 | 39 | $conf->global->MAIN_DISABLE_ALL_MAILS=1; |
40 | 40 | |
@@ -48,75 +48,75 @@ discard block |
||
48 | 48 | */ |
49 | 49 | class ProjectTest extends PHPUnit_Framework_TestCase |
50 | 50 | { |
51 | - protected $savconf; |
|
52 | - protected $savuser; |
|
53 | - protected $savlangs; |
|
54 | - protected $savdb; |
|
55 | - |
|
56 | - /** |
|
57 | - * Constructor |
|
58 | - * We save global variables into local variables |
|
59 | - * |
|
60 | - * @return ProjectTest |
|
61 | - */ |
|
62 | - function __construct() |
|
63 | - { |
|
64 | - parent::__construct(); |
|
65 | - |
|
66 | - //$this->sharedFixture |
|
67 | - global $conf,$user,$langs,$db; |
|
68 | - $this->savconf=$conf; |
|
69 | - $this->savuser=$user; |
|
70 | - $this->savlangs=$langs; |
|
71 | - $this->savdb=$db; |
|
72 | - |
|
73 | - print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
|
74 | - //print " - db ".$db->db; |
|
75 | - print "\n"; |
|
76 | - } |
|
77 | - |
|
78 | - // Static methods |
|
79 | - public static function setUpBeforeClass() |
|
51 | + protected $savconf; |
|
52 | + protected $savuser; |
|
53 | + protected $savlangs; |
|
54 | + protected $savdb; |
|
55 | + |
|
56 | + /** |
|
57 | + * Constructor |
|
58 | + * We save global variables into local variables |
|
59 | + * |
|
60 | + * @return ProjectTest |
|
61 | + */ |
|
62 | + function __construct() |
|
80 | 63 | { |
81 | - global $conf,$user,$langs,$db; |
|
82 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
64 | + parent::__construct(); |
|
83 | 65 | |
84 | - print __METHOD__."\n"; |
|
66 | + //$this->sharedFixture |
|
67 | + global $conf,$user,$langs,$db; |
|
68 | + $this->savconf=$conf; |
|
69 | + $this->savuser=$user; |
|
70 | + $this->savlangs=$langs; |
|
71 | + $this->savdb=$db; |
|
72 | + |
|
73 | + print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
|
74 | + //print " - db ".$db->db; |
|
75 | + print "\n"; |
|
76 | + } |
|
77 | + |
|
78 | + // Static methods |
|
79 | + public static function setUpBeforeClass() |
|
80 | + { |
|
81 | + global $conf,$user,$langs,$db; |
|
82 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
83 | + |
|
84 | + print __METHOD__."\n"; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | // tear down after class |
88 | 88 | public static function tearDownAfterClass() |
89 | 89 | { |
90 | - global $conf,$user,$langs,$db; |
|
91 | - $db->rollback(); |
|
90 | + global $conf,$user,$langs,$db; |
|
91 | + $db->rollback(); |
|
92 | 92 | |
93 | - print __METHOD__."\n"; |
|
93 | + print __METHOD__."\n"; |
|
94 | 94 | } |
95 | 95 | |
96 | - /** |
|
97 | - * Init phpunit tests |
|
98 | - * |
|
99 | - * @return void |
|
100 | - */ |
|
96 | + /** |
|
97 | + * Init phpunit tests |
|
98 | + * |
|
99 | + * @return void |
|
100 | + */ |
|
101 | 101 | protected function setUp() |
102 | 102 | { |
103 | - global $conf,$user,$langs,$db; |
|
104 | - $conf=$this->savconf; |
|
105 | - $user=$this->savuser; |
|
106 | - $langs=$this->savlangs; |
|
107 | - $db=$this->savdb; |
|
108 | - |
|
109 | - print __METHOD__."\n"; |
|
110 | - //print $db->getVersion()."\n"; |
|
103 | + global $conf,$user,$langs,$db; |
|
104 | + $conf=$this->savconf; |
|
105 | + $user=$this->savuser; |
|
106 | + $langs=$this->savlangs; |
|
107 | + $db=$this->savdb; |
|
108 | + |
|
109 | + print __METHOD__."\n"; |
|
110 | + //print $db->getVersion()."\n"; |
|
111 | 111 | } |
112 | - /** |
|
113 | - * End phpunit tests |
|
114 | - * |
|
115 | - * @return void |
|
116 | - */ |
|
112 | + /** |
|
113 | + * End phpunit tests |
|
114 | + * |
|
115 | + * @return void |
|
116 | + */ |
|
117 | 117 | protected function tearDown() |
118 | 118 | { |
119 | - print __METHOD__."\n"; |
|
119 | + print __METHOD__."\n"; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function testProjectCreate() |
128 | 128 | { |
129 | - global $conf,$user,$langs,$db; |
|
130 | - $conf=$this->savconf; |
|
131 | - $user=$this->savuser; |
|
132 | - $langs=$this->savlangs; |
|
133 | - $db=$this->savdb; |
|
134 | - |
|
135 | - $localobject=new Project($this->savdb); |
|
136 | - $localobject->initAsSpecimen(); |
|
137 | - $result=$localobject->create($user); |
|
138 | - |
|
139 | - $this->assertLessThan($result, 0); |
|
140 | - print __METHOD__." result=".$result."\n"; |
|
141 | - return $result; |
|
129 | + global $conf,$user,$langs,$db; |
|
130 | + $conf=$this->savconf; |
|
131 | + $user=$this->savuser; |
|
132 | + $langs=$this->savlangs; |
|
133 | + $db=$this->savdb; |
|
134 | + |
|
135 | + $localobject=new Project($this->savdb); |
|
136 | + $localobject->initAsSpecimen(); |
|
137 | + $result=$localobject->create($user); |
|
138 | + |
|
139 | + $this->assertLessThan($result, 0); |
|
140 | + print __METHOD__." result=".$result."\n"; |
|
141 | + return $result; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -152,18 +152,18 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function testProjectFetch($id) |
154 | 154 | { |
155 | - global $conf,$user,$langs,$db; |
|
156 | - $conf=$this->savconf; |
|
157 | - $user=$this->savuser; |
|
158 | - $langs=$this->savlangs; |
|
159 | - $db=$this->savdb; |
|
160 | - |
|
161 | - $localobject=new Project($this->savdb); |
|
162 | - $result=$localobject->fetch($id); |
|
163 | - |
|
164 | - $this->assertLessThan($result, 0); |
|
165 | - print __METHOD__." id=".$id." result=".$result."\n"; |
|
166 | - return $localobject; |
|
155 | + global $conf,$user,$langs,$db; |
|
156 | + $conf=$this->savconf; |
|
157 | + $user=$this->savuser; |
|
158 | + $langs=$this->savlangs; |
|
159 | + $db=$this->savdb; |
|
160 | + |
|
161 | + $localobject=new Project($this->savdb); |
|
162 | + $result=$localobject->fetch($id); |
|
163 | + |
|
164 | + $this->assertLessThan($result, 0); |
|
165 | + print __METHOD__." id=".$id." result=".$result."\n"; |
|
166 | + return $localobject; |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -177,20 +177,20 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function testProjectValid($localobject) |
179 | 179 | { |
180 | - global $conf,$user,$langs,$db; |
|
181 | - $conf=$this->savconf; |
|
182 | - $user=$this->savuser; |
|
183 | - $langs=$this->savlangs; |
|
184 | - $db=$this->savdb; |
|
180 | + global $conf,$user,$langs,$db; |
|
181 | + $conf=$this->savconf; |
|
182 | + $user=$this->savuser; |
|
183 | + $langs=$this->savlangs; |
|
184 | + $db=$this->savdb; |
|
185 | 185 | |
186 | - $result=$localobject->setValid($user); |
|
186 | + $result=$localobject->setValid($user); |
|
187 | 187 | |
188 | - print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
|
189 | - $this->assertLessThan($result, 0); |
|
190 | - return $localobject; |
|
188 | + print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
|
189 | + $this->assertLessThan($result, 0); |
|
190 | + return $localobject; |
|
191 | 191 | } |
192 | 192 | |
193 | - /** |
|
193 | + /** |
|
194 | 194 | * testProjectClose |
195 | 195 | * |
196 | 196 | * @param Project $localobject Project |
@@ -209,8 +209,8 @@ discard block |
||
209 | 209 | |
210 | 210 | $result=$localobject->setClose($user); |
211 | 211 | |
212 | - print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
|
213 | - $this->assertLessThan($result, 0); |
|
212 | + print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
|
213 | + $this->assertLessThan($result, 0); |
|
214 | 214 | return $localobject->id; |
215 | 215 | } |
216 | 216 | |
@@ -225,18 +225,18 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public function testProjectDelete($id) |
227 | 227 | { |
228 | - global $conf,$user,$langs,$db; |
|
229 | - $conf=$this->savconf; |
|
230 | - $user=$this->savuser; |
|
231 | - $langs=$this->savlangs; |
|
232 | - $db=$this->savdb; |
|
233 | - |
|
234 | - $localobject=new Project($this->savdb); |
|
235 | - $result=$localobject->fetch($id); |
|
236 | - $result=$localobject->delete($user); |
|
237 | - |
|
238 | - print __METHOD__." id=".$id." result=".$result."\n"; |
|
239 | - $this->assertLessThan($result, 0); |
|
240 | - return $result; |
|
228 | + global $conf,$user,$langs,$db; |
|
229 | + $conf=$this->savconf; |
|
230 | + $user=$this->savuser; |
|
231 | + $langs=$this->savlangs; |
|
232 | + $db=$this->savdb; |
|
233 | + |
|
234 | + $localobject=new Project($this->savdb); |
|
235 | + $result=$localobject->fetch($id); |
|
236 | + $result=$localobject->delete($user); |
|
237 | + |
|
238 | + print __METHOD__." id=".$id." result=".$result."\n"; |
|
239 | + $this->assertLessThan($result, 0); |
|
240 | + return $result; |
|
241 | 241 | } |
242 | 242 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
24 | 24 | */ |
25 | 25 | |
26 | -global $conf,$user,$langs,$db; |
|
26 | +global $conf, $user, $langs, $db; |
|
27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $user->fetch(1); |
37 | 37 | $user->getrights(); |
38 | 38 | } |
39 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
39 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
40 | 40 | |
41 | 41 | |
42 | 42 | /** |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | parent::__construct(); |
65 | 65 | |
66 | 66 | //$this->sharedFixture |
67 | - global $conf,$user,$langs,$db; |
|
68 | - $this->savconf=$conf; |
|
69 | - $this->savuser=$user; |
|
70 | - $this->savlangs=$langs; |
|
71 | - $this->savdb=$db; |
|
67 | + global $conf, $user, $langs, $db; |
|
68 | + $this->savconf = $conf; |
|
69 | + $this->savuser = $user; |
|
70 | + $this->savlangs = $langs; |
|
71 | + $this->savdb = $db; |
|
72 | 72 | |
73 | 73 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
74 | 74 | //print " - db ".$db->db; |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | // Static methods |
79 | 79 | public static function setUpBeforeClass() |
80 | 80 | { |
81 | - global $conf,$user,$langs,$db; |
|
82 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
81 | + global $conf, $user, $langs, $db; |
|
82 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
83 | 83 | |
84 | 84 | print __METHOD__."\n"; |
85 | 85 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | // tear down after class |
88 | 88 | public static function tearDownAfterClass() |
89 | 89 | { |
90 | - global $conf,$user,$langs,$db; |
|
90 | + global $conf, $user, $langs, $db; |
|
91 | 91 | $db->rollback(); |
92 | 92 | |
93 | 93 | print __METHOD__."\n"; |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function setUp() |
102 | 102 | { |
103 | - global $conf,$user,$langs,$db; |
|
104 | - $conf=$this->savconf; |
|
105 | - $user=$this->savuser; |
|
106 | - $langs=$this->savlangs; |
|
107 | - $db=$this->savdb; |
|
103 | + global $conf, $user, $langs, $db; |
|
104 | + $conf = $this->savconf; |
|
105 | + $user = $this->savuser; |
|
106 | + $langs = $this->savlangs; |
|
107 | + $db = $this->savdb; |
|
108 | 108 | |
109 | 109 | print __METHOD__."\n"; |
110 | 110 | //print $db->getVersion()."\n"; |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function testProjectCreate() |
128 | 128 | { |
129 | - global $conf,$user,$langs,$db; |
|
130 | - $conf=$this->savconf; |
|
131 | - $user=$this->savuser; |
|
132 | - $langs=$this->savlangs; |
|
133 | - $db=$this->savdb; |
|
129 | + global $conf, $user, $langs, $db; |
|
130 | + $conf = $this->savconf; |
|
131 | + $user = $this->savuser; |
|
132 | + $langs = $this->savlangs; |
|
133 | + $db = $this->savdb; |
|
134 | 134 | |
135 | - $localobject=new Project($this->savdb); |
|
135 | + $localobject = new Project($this->savdb); |
|
136 | 136 | $localobject->initAsSpecimen(); |
137 | - $result=$localobject->create($user); |
|
137 | + $result = $localobject->create($user); |
|
138 | 138 | |
139 | 139 | $this->assertLessThan($result, 0); |
140 | 140 | print __METHOD__." result=".$result."\n"; |
@@ -152,14 +152,14 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function testProjectFetch($id) |
154 | 154 | { |
155 | - global $conf,$user,$langs,$db; |
|
156 | - $conf=$this->savconf; |
|
157 | - $user=$this->savuser; |
|
158 | - $langs=$this->savlangs; |
|
159 | - $db=$this->savdb; |
|
155 | + global $conf, $user, $langs, $db; |
|
156 | + $conf = $this->savconf; |
|
157 | + $user = $this->savuser; |
|
158 | + $langs = $this->savlangs; |
|
159 | + $db = $this->savdb; |
|
160 | 160 | |
161 | - $localobject=new Project($this->savdb); |
|
162 | - $result=$localobject->fetch($id); |
|
161 | + $localobject = new Project($this->savdb); |
|
162 | + $result = $localobject->fetch($id); |
|
163 | 163 | |
164 | 164 | $this->assertLessThan($result, 0); |
165 | 165 | print __METHOD__." id=".$id." result=".$result."\n"; |
@@ -177,13 +177,13 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function testProjectValid($localobject) |
179 | 179 | { |
180 | - global $conf,$user,$langs,$db; |
|
181 | - $conf=$this->savconf; |
|
182 | - $user=$this->savuser; |
|
183 | - $langs=$this->savlangs; |
|
184 | - $db=$this->savdb; |
|
180 | + global $conf, $user, $langs, $db; |
|
181 | + $conf = $this->savconf; |
|
182 | + $user = $this->savuser; |
|
183 | + $langs = $this->savlangs; |
|
184 | + $db = $this->savdb; |
|
185 | 185 | |
186 | - $result=$localobject->setValid($user); |
|
186 | + $result = $localobject->setValid($user); |
|
187 | 187 | |
188 | 188 | print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
189 | 189 | $this->assertLessThan($result, 0); |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function testProjectOther($localobject) |
203 | 203 | { |
204 | - global $conf,$user,$langs,$db; |
|
205 | - $conf=$this->savconf; |
|
206 | - $user=$this->savuser; |
|
207 | - $langs=$this->savlangs; |
|
208 | - $db=$this->savdb; |
|
204 | + global $conf, $user, $langs, $db; |
|
205 | + $conf = $this->savconf; |
|
206 | + $user = $this->savuser; |
|
207 | + $langs = $this->savlangs; |
|
208 | + $db = $this->savdb; |
|
209 | 209 | |
210 | - $result=$localobject->setClose($user); |
|
210 | + $result = $localobject->setClose($user); |
|
211 | 211 | |
212 | 212 | print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
213 | 213 | $this->assertLessThan($result, 0); |
@@ -225,15 +225,15 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public function testProjectDelete($id) |
227 | 227 | { |
228 | - global $conf,$user,$langs,$db; |
|
229 | - $conf=$this->savconf; |
|
230 | - $user=$this->savuser; |
|
231 | - $langs=$this->savlangs; |
|
232 | - $db=$this->savdb; |
|
233 | - |
|
234 | - $localobject=new Project($this->savdb); |
|
235 | - $result=$localobject->fetch($id); |
|
236 | - $result=$localobject->delete($user); |
|
228 | + global $conf, $user, $langs, $db; |
|
229 | + $conf = $this->savconf; |
|
230 | + $user = $this->savuser; |
|
231 | + $langs = $this->savlangs; |
|
232 | + $db = $this->savdb; |
|
233 | + |
|
234 | + $localobject = new Project($this->savdb); |
|
235 | + $result = $localobject->fetch($id); |
|
236 | + $result = $localobject->delete($user); |
|
237 | 237 | |
238 | 238 | print __METHOD__." id=".$id." result=".$result."\n"; |
239 | 239 | $this->assertLessThan($result, 0); |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | */ |
64 | 64 | function __construct() |
65 | 65 | { |
66 | - parent::__construct(); |
|
66 | + parent::__construct(); |
|
67 | 67 | |
68 | - //$this->sharedFixture |
|
68 | + //$this->sharedFixture |
|
69 | 69 | global $conf,$user,$langs,$db; |
70 | 70 | $this->savconf=$conf; |
71 | 71 | $this->savuser=$user; |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | print __METHOD__."\n"; |
96 | 96 | } |
97 | 97 | |
98 | - /** |
|
99 | - * Init phpunit tests |
|
100 | - * |
|
101 | - * @return void |
|
102 | - */ |
|
98 | + /** |
|
99 | + * Init phpunit tests |
|
100 | + * |
|
101 | + * @return void |
|
102 | + */ |
|
103 | 103 | protected function setUp() |
104 | 104 | { |
105 | 105 | global $conf,$user,$langs,$db; |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | |
111 | 111 | print __METHOD__."\n"; |
112 | 112 | } |
113 | - /** |
|
114 | - * End phpunit tests |
|
115 | - * |
|
116 | - * @return void |
|
117 | - */ |
|
113 | + /** |
|
114 | + * End phpunit tests |
|
115 | + * |
|
116 | + * @return void |
|
117 | + */ |
|
118 | 118 | protected function tearDown() |
119 | 119 | { |
120 | 120 | print __METHOD__."\n"; |
@@ -149,62 +149,62 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function testIsValidUrl() |
151 | 151 | { |
152 | - //Simple check |
|
153 | - $result = isValidUrl('http://google.com'); |
|
154 | - $this->assertEquals(1, $result); |
|
152 | + //Simple check |
|
153 | + $result = isValidUrl('http://google.com'); |
|
154 | + $this->assertEquals(1, $result); |
|
155 | 155 | |
156 | - $result = isValidUrl('goo=gle'); // This is good, it might be an alias of hostname |
|
157 | - $this->assertEquals(1, $result); |
|
156 | + $result = isValidUrl('goo=gle'); // This is good, it might be an alias of hostname |
|
157 | + $this->assertEquals(1, $result); |
|
158 | 158 | |
159 | - //With scheme check |
|
160 | - $result = isValidUrl('http://www.google.com', 1); |
|
161 | - $this->assertEquals(1, $result); |
|
159 | + //With scheme check |
|
160 | + $result = isValidUrl('http://www.google.com', 1); |
|
161 | + $this->assertEquals(1, $result); |
|
162 | 162 | |
163 | - $result = isValidUrl('ftp://www.google.com', 1); |
|
164 | - $this->assertEquals(0, $result); |
|
163 | + $result = isValidUrl('ftp://www.google.com', 1); |
|
164 | + $this->assertEquals(0, $result); |
|
165 | 165 | |
166 | - //With password check invalid. This test should be ko but currently it is not |
|
167 | - //$result = isValidUrl('http://user:password@http://www.google.com', 1, 1); |
|
168 | - //$this->assertEquals(0, $result); |
|
166 | + //With password check invalid. This test should be ko but currently it is not |
|
167 | + //$result = isValidUrl('http://user:password@http://www.google.com', 1, 1); |
|
168 | + //$this->assertEquals(0, $result); |
|
169 | 169 | |
170 | - //With password check valid |
|
171 | - $result = isValidUrl('http://user:[email protected]', 1, 1); |
|
172 | - $this->assertEquals(1, $result); |
|
170 | + //With password check valid |
|
171 | + $result = isValidUrl('http://user:[email protected]', 1, 1); |
|
172 | + $this->assertEquals(1, $result); |
|
173 | 173 | |
174 | - $result = isValidUrl('http://www.google.com', 1, 1); |
|
175 | - $this->assertEquals(0, $result); |
|
174 | + $result = isValidUrl('http://www.google.com', 1, 1); |
|
175 | + $this->assertEquals(0, $result); |
|
176 | 176 | |
177 | - //With port check |
|
178 | - $result = isValidUrl('http://google.com:8080', 0, 0, 1); |
|
179 | - $this->assertEquals(1, $result); |
|
177 | + //With port check |
|
178 | + $result = isValidUrl('http://google.com:8080', 0, 0, 1); |
|
179 | + $this->assertEquals(1, $result); |
|
180 | 180 | |
181 | - $result = isValidUrl('http://google.com', 0, 0, 1); |
|
182 | - $this->assertEquals(0, $result); |
|
181 | + $result = isValidUrl('http://google.com', 0, 0, 1); |
|
182 | + $this->assertEquals(0, $result); |
|
183 | 183 | |
184 | - //With path check |
|
185 | - $result = isValidUrl('http://google.com/search', 0, 0, 0, 1); |
|
186 | - $this->assertEquals(1, $result); |
|
184 | + //With path check |
|
185 | + $result = isValidUrl('http://google.com/search', 0, 0, 0, 1); |
|
186 | + $this->assertEquals(1, $result); |
|
187 | 187 | |
188 | - $result = isValidUrl('http://google.com', 0, 0, 0, 0); |
|
189 | - $this->assertEquals(1, $result); |
|
188 | + $result = isValidUrl('http://google.com', 0, 0, 0, 0); |
|
189 | + $this->assertEquals(1, $result); |
|
190 | 190 | |
191 | - //With query check |
|
192 | - $result = isValidUrl('http://google.com/search?test=test', 0, 0, 0, 0, 1); |
|
193 | - $this->assertEquals(1, $result); |
|
191 | + //With query check |
|
192 | + $result = isValidUrl('http://google.com/search?test=test', 0, 0, 0, 0, 1); |
|
193 | + $this->assertEquals(1, $result); |
|
194 | 194 | |
195 | - //With query check |
|
196 | - $result = isValidUrl('http://google.com?test=test', 0, 0, 0, 0, 1); |
|
197 | - $this->assertEquals(1, $result); |
|
195 | + //With query check |
|
196 | + $result = isValidUrl('http://google.com?test=test', 0, 0, 0, 0, 1); |
|
197 | + $this->assertEquals(1, $result); |
|
198 | 198 | |
199 | - $result = isValidUrl('http://google.com', 0, 0, 0, 0, 1); |
|
200 | - $this->assertEquals(0, $result); |
|
199 | + $result = isValidUrl('http://google.com', 0, 0, 0, 0, 1); |
|
200 | + $this->assertEquals(0, $result); |
|
201 | 201 | |
202 | - //With anchor check |
|
203 | - $result = isValidUrl('http://google.com/search#done', 0, 0, 0, 0, 0, 1); |
|
204 | - $this->assertEquals(1, $result); |
|
202 | + //With anchor check |
|
203 | + $result = isValidUrl('http://google.com/search#done', 0, 0, 0, 0, 0, 1); |
|
204 | + $this->assertEquals(1, $result); |
|
205 | 205 | |
206 | - $result = isValidUrl('http://google.com/search', 0, 0, 0, 0, 0, 1); |
|
207 | - $this->assertEquals(0, $result); |
|
206 | + $result = isValidUrl('http://google.com/search', 0, 0, 0, 0, 0, 1); |
|
207 | + $this->assertEquals(0, $result); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -214,33 +214,33 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function testIsIP() |
216 | 216 | { |
217 | - // Not valid |
|
218 | - $ip='a299.299.299.299'; |
|
219 | - $result=is_ip($ip); |
|
217 | + // Not valid |
|
218 | + $ip='a299.299.299.299'; |
|
219 | + $result=is_ip($ip); |
|
220 | 220 | print __METHOD__." for ".$ip." result=".$result."\n"; |
221 | - $this->assertEquals(0,$result,$ip); |
|
221 | + $this->assertEquals(0,$result,$ip); |
|
222 | 222 | |
223 | - // Reserved IP range (not checked by is_ip function) |
|
224 | - $ip='169.254.0.0'; |
|
225 | - $result=is_ip($ip); |
|
223 | + // Reserved IP range (not checked by is_ip function) |
|
224 | + $ip='169.254.0.0'; |
|
225 | + $result=is_ip($ip); |
|
226 | 226 | print __METHOD__." for ".$ip." result=".$result."\n"; |
227 | - //$this->assertEquals(2,$result,$ip); // Assertion disabled because returned value differs between PHP patch version |
|
227 | + //$this->assertEquals(2,$result,$ip); // Assertion disabled because returned value differs between PHP patch version |
|
228 | 228 | |
229 | - $ip='1.2.3.4'; |
|
230 | - $result=is_ip($ip); |
|
229 | + $ip='1.2.3.4'; |
|
230 | + $result=is_ip($ip); |
|
231 | 231 | print __METHOD__." for ".$ip." result=".$result."\n"; |
232 | - $this->assertEquals(1,$result,$ip); |
|
232 | + $this->assertEquals(1,$result,$ip); |
|
233 | 233 | |
234 | - // Private IP ranges |
|
235 | - $ip='10.0.0.0'; |
|
236 | - $result=is_ip($ip); |
|
234 | + // Private IP ranges |
|
235 | + $ip='10.0.0.0'; |
|
236 | + $result=is_ip($ip); |
|
237 | 237 | print __METHOD__." for ".$ip." result=".$result."\n"; |
238 | - $this->assertEquals(2,$result,$ip); |
|
238 | + $this->assertEquals(2,$result,$ip); |
|
239 | 239 | |
240 | - $ip='172.16.0.0'; |
|
241 | - $result=is_ip($ip); |
|
240 | + $ip='172.16.0.0'; |
|
241 | + $result=is_ip($ip); |
|
242 | 242 | print __METHOD__." for ".$ip." result=".$result."\n"; |
243 | - $this->assertEquals(2,$result,$ip); |
|
243 | + $this->assertEquals(2,$result,$ip); |
|
244 | 244 | |
245 | 245 | $ip='192.168.0.0'; |
246 | 246 | $result=is_ip($ip); |
@@ -23,22 +23,22 @@ discard block |
||
23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
24 | 24 | */ |
25 | 25 | |
26 | -global $conf,$user,$langs,$db; |
|
26 | +global $conf, $user, $langs, $db; |
|
27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/core/lib/functions2.lib.php'; |
31 | 31 | |
32 | -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); |
|
33 | -if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); |
|
34 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
35 | -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); |
|
36 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); |
|
37 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); |
|
38 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show |
|
39 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php |
|
40 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
41 | -if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) |
|
32 | +if (!defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); |
|
33 | +if (!defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); |
|
34 | +if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); |
|
35 | +if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); |
|
36 | +if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); |
|
37 | +if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); |
|
38 | +if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show |
|
39 | +if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php |
|
40 | +if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); |
|
41 | +if (!defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
42 | 42 | |
43 | 43 | |
44 | 44 | /** |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | parent::__construct(); |
67 | 67 | |
68 | 68 | //$this->sharedFixture |
69 | - global $conf,$user,$langs,$db; |
|
70 | - $this->savconf=$conf; |
|
71 | - $this->savuser=$user; |
|
72 | - $this->savlangs=$langs; |
|
73 | - $this->savdb=$db; |
|
69 | + global $conf, $user, $langs, $db; |
|
70 | + $this->savconf = $conf; |
|
71 | + $this->savuser = $user; |
|
72 | + $this->savlangs = $langs; |
|
73 | + $this->savdb = $db; |
|
74 | 74 | |
75 | 75 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
76 | 76 | //print " - db ".$db->db; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | // Static methods |
81 | 81 | public static function setUpBeforeClass() |
82 | 82 | { |
83 | - global $conf,$user,$langs,$db; |
|
83 | + global $conf, $user, $langs, $db; |
|
84 | 84 | //$db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
85 | 85 | |
86 | 86 | print __METHOD__."\n"; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | // tear down after class |
90 | 90 | public static function tearDownAfterClass() |
91 | 91 | { |
92 | - global $conf,$user,$langs,$db; |
|
92 | + global $conf, $user, $langs, $db; |
|
93 | 93 | //$db->rollback(); |
94 | 94 | |
95 | 95 | print __METHOD__."\n"; |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function setUp() |
104 | 104 | { |
105 | - global $conf,$user,$langs,$db; |
|
106 | - $conf=$this->savconf; |
|
107 | - $user=$this->savuser; |
|
108 | - $langs=$this->savlangs; |
|
109 | - $db=$this->savdb; |
|
105 | + global $conf, $user, $langs, $db; |
|
106 | + $conf = $this->savconf; |
|
107 | + $user = $this->savuser; |
|
108 | + $langs = $this->savlangs; |
|
109 | + $db = $this->savdb; |
|
110 | 110 | |
111 | 111 | print __METHOD__."\n"; |
112 | 112 | } |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function testJsUnEscape() |
130 | 130 | { |
131 | - $result=jsUnEscape('%u03BD%u03B5%u03BF'); |
|
131 | + $result = jsUnEscape('%u03BD%u03B5%u03BF'); |
|
132 | 132 | print __METHOD__." result=".$result."\n"; |
133 | - $this->assertEquals('νεο',$result); |
|
133 | + $this->assertEquals('νεο', $result); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $result = isValidUrl('http://google.com'); |
154 | 154 | $this->assertEquals(1, $result); |
155 | 155 | |
156 | - $result = isValidUrl('goo=gle'); // This is good, it might be an alias of hostname |
|
156 | + $result = isValidUrl('goo=gle'); // This is good, it might be an alias of hostname |
|
157 | 157 | $this->assertEquals(1, $result); |
158 | 158 | |
159 | 159 | //With scheme check |
@@ -215,36 +215,36 @@ discard block |
||
215 | 215 | public function testIsIP() |
216 | 216 | { |
217 | 217 | // Not valid |
218 | - $ip='a299.299.299.299'; |
|
219 | - $result=is_ip($ip); |
|
218 | + $ip = 'a299.299.299.299'; |
|
219 | + $result = is_ip($ip); |
|
220 | 220 | print __METHOD__." for ".$ip." result=".$result."\n"; |
221 | - $this->assertEquals(0,$result,$ip); |
|
221 | + $this->assertEquals(0, $result, $ip); |
|
222 | 222 | |
223 | 223 | // Reserved IP range (not checked by is_ip function) |
224 | - $ip='169.254.0.0'; |
|
225 | - $result=is_ip($ip); |
|
224 | + $ip = '169.254.0.0'; |
|
225 | + $result = is_ip($ip); |
|
226 | 226 | print __METHOD__." for ".$ip." result=".$result."\n"; |
227 | 227 | //$this->assertEquals(2,$result,$ip); // Assertion disabled because returned value differs between PHP patch version |
228 | 228 | |
229 | - $ip='1.2.3.4'; |
|
230 | - $result=is_ip($ip); |
|
229 | + $ip = '1.2.3.4'; |
|
230 | + $result = is_ip($ip); |
|
231 | 231 | print __METHOD__." for ".$ip." result=".$result."\n"; |
232 | - $this->assertEquals(1,$result,$ip); |
|
232 | + $this->assertEquals(1, $result, $ip); |
|
233 | 233 | |
234 | 234 | // Private IP ranges |
235 | - $ip='10.0.0.0'; |
|
236 | - $result=is_ip($ip); |
|
235 | + $ip = '10.0.0.0'; |
|
236 | + $result = is_ip($ip); |
|
237 | 237 | print __METHOD__." for ".$ip." result=".$result."\n"; |
238 | - $this->assertEquals(2,$result,$ip); |
|
238 | + $this->assertEquals(2, $result, $ip); |
|
239 | 239 | |
240 | - $ip='172.16.0.0'; |
|
241 | - $result=is_ip($ip); |
|
240 | + $ip = '172.16.0.0'; |
|
241 | + $result = is_ip($ip); |
|
242 | 242 | print __METHOD__." for ".$ip." result=".$result."\n"; |
243 | - $this->assertEquals(2,$result,$ip); |
|
243 | + $this->assertEquals(2, $result, $ip); |
|
244 | 244 | |
245 | - $ip='192.168.0.0'; |
|
246 | - $result=is_ip($ip); |
|
245 | + $ip = '192.168.0.0'; |
|
246 | + $result = is_ip($ip); |
|
247 | 247 | print __METHOD__." for ".$ip." result=".$result."\n"; |
248 | - $this->assertEquals(2,$result,$ip); |
|
248 | + $this->assertEquals(2, $result, $ip); |
|
249 | 249 | } |
250 | 250 | } |
@@ -29,16 +29,39 @@ |
||
29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/core/lib/functions2.lib.php'; |
31 | 31 | |
32 | -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); |
|
33 | -if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); |
|
34 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
35 | -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); |
|
36 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); |
|
37 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); |
|
38 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show |
|
39 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php |
|
40 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
41 | -if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) |
|
32 | +if (! defined('NOREQUIREUSER')) { |
|
33 | + define('NOREQUIREUSER','1'); |
|
34 | +} |
|
35 | +if (! defined('NOREQUIREDB')) { |
|
36 | + define('NOREQUIREDB','1'); |
|
37 | +} |
|
38 | +if (! defined('NOREQUIRESOC')) { |
|
39 | + define('NOREQUIRESOC','1'); |
|
40 | +} |
|
41 | +if (! defined('NOREQUIRETRAN')) { |
|
42 | + define('NOREQUIRETRAN','1'); |
|
43 | +} |
|
44 | +if (! defined('NOCSRFCHECK')) { |
|
45 | + define('NOCSRFCHECK','1'); |
|
46 | +} |
|
47 | +if (! defined('NOTOKENRENEWAL')) { |
|
48 | + define('NOTOKENRENEWAL','1'); |
|
49 | +} |
|
50 | +if (! defined('NOREQUIREMENU')) { |
|
51 | + define('NOREQUIREMENU','1'); |
|
52 | +} |
|
53 | +// If there is no menu to show |
|
54 | +if (! defined('NOREQUIREHTML')) { |
|
55 | + define('NOREQUIREHTML','1'); |
|
56 | +} |
|
57 | +// If we don't need to load the html.form.class.php |
|
58 | +if (! defined('NOREQUIREAJAX')) { |
|
59 | + define('NOREQUIREAJAX','1'); |
|
60 | +} |
|
61 | +if (! defined("NOLOGIN")) { |
|
62 | + define("NOLOGIN",'1'); |
|
63 | +} |
|
64 | +// If this page is public (can be called outside logged session) |
|
42 | 65 | |
43 | 66 | |
44 | 67 | /** |
@@ -61,9 +61,9 @@ |
||
61 | 61 | */ |
62 | 62 | function __construct() |
63 | 63 | { |
64 | - parent::__construct(); |
|
64 | + parent::__construct(); |
|
65 | 65 | |
66 | - //$this->sharedFixture |
|
66 | + //$this->sharedFixture |
|
67 | 67 | global $conf,$user,$langs,$db; |
68 | 68 | $this->savconf=$conf; |
69 | 69 | $this->savuser=$user; |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
24 | 24 | */ |
25 | 25 | |
26 | -global $conf,$user,$langs,$db; |
|
26 | +global $conf, $user, $langs, $db; |
|
27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $user->fetch(1); |
36 | 36 | $user->getrights(); |
37 | 37 | } |
38 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
38 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
39 | 39 | |
40 | 40 | |
41 | 41 | |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | parent::__construct(); |
65 | 65 | |
66 | 66 | //$this->sharedFixture |
67 | - global $conf,$user,$langs,$db; |
|
68 | - $this->savconf=$conf; |
|
69 | - $this->savuser=$user; |
|
70 | - $this->savlangs=$langs; |
|
71 | - $this->savdb=$db; |
|
67 | + global $conf, $user, $langs, $db; |
|
68 | + $this->savconf = $conf; |
|
69 | + $this->savuser = $user; |
|
70 | + $this->savlangs = $langs; |
|
71 | + $this->savdb = $db; |
|
72 | 72 | |
73 | 73 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
74 | 74 | //print " - db ".$db->db; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | // Static methods |
79 | 79 | public static function setUpBeforeClass() |
80 | 80 | { |
81 | - global $conf,$user,$langs,$db; |
|
81 | + global $conf, $user, $langs, $db; |
|
82 | 82 | $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
83 | 83 | |
84 | 84 | print __METHOD__."\n"; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | // tear down after class |
88 | 88 | public static function tearDownAfterClass() |
89 | 89 | { |
90 | - global $conf,$user,$langs,$db; |
|
90 | + global $conf, $user, $langs, $db; |
|
91 | 91 | $db->rollback(); |
92 | 92 | |
93 | 93 | print __METHOD__."\n"; |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function setUp() |
102 | 102 | { |
103 | - global $conf,$user,$langs,$db; |
|
104 | - $conf=$this->savconf; |
|
105 | - $user=$this->savuser; |
|
106 | - $langs=$this->savlangs; |
|
107 | - $db=$this->savdb; |
|
103 | + global $conf, $user, $langs, $db; |
|
104 | + $conf = $this->savconf; |
|
105 | + $user = $this->savuser; |
|
106 | + $langs = $this->savlangs; |
|
107 | + $db = $this->savdb; |
|
108 | 108 | |
109 | 109 | print __METHOD__."\n"; |
110 | 110 | //print $db->getVersion()."\n"; |
@@ -126,67 +126,67 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function testCommandeFournisseurCreate() |
128 | 128 | { |
129 | - global $conf,$user,$langs,$db; |
|
130 | - $conf=$this->savconf; |
|
131 | - $user=$this->savuser; |
|
132 | - $langs=$this->savlangs; |
|
133 | - $db=$this->savdb; |
|
129 | + global $conf, $user, $langs, $db; |
|
130 | + $conf = $this->savconf; |
|
131 | + $user = $this->savuser; |
|
132 | + $langs = $this->savlangs; |
|
133 | + $db = $this->savdb; |
|
134 | 134 | |
135 | 135 | // Set supplier and product to use |
136 | - $socid=1; |
|
137 | - $societe=new Societe($db); |
|
136 | + $socid = 1; |
|
137 | + $societe = new Societe($db); |
|
138 | 138 | $societe->fetch($socid); |
139 | - $product=new ProductFournisseur($db); |
|
140 | - $product->fetch(0,'PIDRESS'); |
|
139 | + $product = new ProductFournisseur($db); |
|
140 | + $product->fetch(0, 'PIDRESS'); |
|
141 | 141 | if ($product->id <= 0) { print "\n".__METHOD__." A product with ref PIDRESS must exists into database"; die(); } |
142 | 142 | |
143 | - $quantity=10; |
|
144 | - $ref_fourn='SUPPLIER_REF_PHPUNIT'; |
|
145 | - $tva_tx=19.6; |
|
143 | + $quantity = 10; |
|
144 | + $ref_fourn = 'SUPPLIER_REF_PHPUNIT'; |
|
145 | + $tva_tx = 19.6; |
|
146 | 146 | |
147 | 147 | // Delete existing supplier prices |
148 | 148 | // TODO |
149 | 149 | |
150 | 150 | // Create 1 supplier price with min qty = 10; |
151 | - $result=$product->add_fournisseur($user, $societe->id, $ref_fourn, $quantity); // This insert record with no value for price. Values are update later with update_buyprice |
|
151 | + $result = $product->add_fournisseur($user, $societe->id, $ref_fourn, $quantity); // This insert record with no value for price. Values are update later with update_buyprice |
|
152 | 152 | $this->assertGreaterThanOrEqual(1, $result); |
153 | - $result=$product->update_buyprice($quantity, 20, $user, 'HT', $societe, '', $ref_fourn, $tva_tx, 0, 0); |
|
153 | + $result = $product->update_buyprice($quantity, 20, $user, 'HT', $societe, '', $ref_fourn, $tva_tx, 0, 0); |
|
154 | 154 | $this->assertGreaterThanOrEqual(0, $result); |
155 | 155 | |
156 | 156 | // Create supplier order with a too low quantity and option SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY is on |
157 | 157 | $conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY = 1; |
158 | 158 | |
159 | - $localobject=new CommandeFournisseur($db); |
|
159 | + $localobject = new CommandeFournisseur($db); |
|
160 | 160 | $localobject->initAsSpecimen(); |
161 | - $localobject->lines=array(); // Overwrite lines of order |
|
162 | - $line=new CommandeFournisseurLigne($db); |
|
163 | - $line->desc=$langs->trans("Description")." specimen line with qty too low"; |
|
164 | - $line->qty=1; // So lower than $quantity |
|
165 | - $line->subprice=100; |
|
166 | - $line->fk_product=$product->id; |
|
167 | - $line->ref_fourn=$ref_fourn; |
|
168 | - $localobject->lines[]=$line; |
|
169 | - |
|
170 | - $result=$localobject->create($user); |
|
161 | + $localobject->lines = array(); // Overwrite lines of order |
|
162 | + $line = new CommandeFournisseurLigne($db); |
|
163 | + $line->desc = $langs->trans("Description")." specimen line with qty too low"; |
|
164 | + $line->qty = 1; // So lower than $quantity |
|
165 | + $line->subprice = 100; |
|
166 | + $line->fk_product = $product->id; |
|
167 | + $line->ref_fourn = $ref_fourn; |
|
168 | + $localobject->lines[] = $line; |
|
169 | + |
|
170 | + $result = $localobject->create($user); |
|
171 | 171 | print __METHOD__." result=".$result."\n"; |
172 | - $this->assertEquals(-1, $result, 'Creation of too low quantity'); // must be -1 because quantity is lower than minimum of supplier price |
|
172 | + $this->assertEquals(-1, $result, 'Creation of too low quantity'); // must be -1 because quantity is lower than minimum of supplier price |
|
173 | 173 | |
174 | - $sql="DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur where ref=''"; |
|
174 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur where ref=''"; |
|
175 | 175 | $db->query($sql); |
176 | 176 | |
177 | 177 | // Create supplier order |
178 | - $localobject2=new CommandeFournisseur($db); |
|
179 | - $localobject2->initAsSpecimen(); // This create 5 lines of first product found for socid 1 |
|
180 | - $localobject2->lines=array(); // Overwrite lines of order |
|
181 | - $line=new CommandeFournisseurLigne($db); |
|
182 | - $line->desc=$langs->trans("Description")." specimen line ok"; |
|
183 | - $line->qty=10; // So enough quantity |
|
184 | - $line->subprice=100; |
|
185 | - $line->fk_product=$product->id; |
|
186 | - $line->ref_fourn=$ref_fourn; |
|
187 | - $localobject2->lines[]=$line; |
|
188 | - |
|
189 | - $result=$localobject2->create($user); |
|
178 | + $localobject2 = new CommandeFournisseur($db); |
|
179 | + $localobject2->initAsSpecimen(); // This create 5 lines of first product found for socid 1 |
|
180 | + $localobject2->lines = array(); // Overwrite lines of order |
|
181 | + $line = new CommandeFournisseurLigne($db); |
|
182 | + $line->desc = $langs->trans("Description")." specimen line ok"; |
|
183 | + $line->qty = 10; // So enough quantity |
|
184 | + $line->subprice = 100; |
|
185 | + $line->fk_product = $product->id; |
|
186 | + $line->ref_fourn = $ref_fourn; |
|
187 | + $localobject2->lines[] = $line; |
|
188 | + |
|
189 | + $result = $localobject2->create($user); |
|
190 | 190 | print __METHOD__." result=".$result."\n"; |
191 | 191 | $this->assertGreaterThan(0, $result); |
192 | 192 | |
@@ -194,37 +194,37 @@ discard block |
||
194 | 194 | // Create supplier order with a too low quantity but option SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY is off |
195 | 195 | $conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY = 0; |
196 | 196 | |
197 | - $localobject3=new CommandeFournisseur($db); |
|
197 | + $localobject3 = new CommandeFournisseur($db); |
|
198 | 198 | $localobject3->initAsSpecimen(); |
199 | - $localobject3->lines=array(); // Overwrite lines of order |
|
200 | - $line=new CommandeFournisseurLigne($db); |
|
201 | - $line->desc=$langs->trans("Description")." specimen line with qty too low"; |
|
202 | - $line->qty=1; // So lower than $quantity |
|
203 | - $line->subprice=100; |
|
204 | - $line->fk_product=$product->id; |
|
205 | - $line->ref_fourn=$ref_fourn; |
|
206 | - $localobject3->lines[]=$line; |
|
207 | - |
|
208 | - $result=$localobject3->create($user); |
|
199 | + $localobject3->lines = array(); // Overwrite lines of order |
|
200 | + $line = new CommandeFournisseurLigne($db); |
|
201 | + $line->desc = $langs->trans("Description")." specimen line with qty too low"; |
|
202 | + $line->qty = 1; // So lower than $quantity |
|
203 | + $line->subprice = 100; |
|
204 | + $line->fk_product = $product->id; |
|
205 | + $line->ref_fourn = $ref_fourn; |
|
206 | + $localobject3->lines[] = $line; |
|
207 | + |
|
208 | + $result = $localobject3->create($user); |
|
209 | 209 | print __METHOD__." result=".$result."\n"; |
210 | - $this->assertGreaterThan(0, $result, 'Creation of too low quantity should be ok'); // must be id of line because there is no test on minimum quantity |
|
210 | + $this->assertGreaterThan(0, $result, 'Creation of too low quantity should be ok'); // must be id of line because there is no test on minimum quantity |
|
211 | 211 | |
212 | - $sql="DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur where ref=''"; |
|
212 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur where ref=''"; |
|
213 | 213 | $db->query($sql); |
214 | 214 | |
215 | 215 | // Create supplier order |
216 | - $localobject4=new CommandeFournisseur($db); |
|
217 | - $localobject4->initAsSpecimen(); // This create 5 lines of first product found for socid 1 |
|
218 | - $localobject4->lines=array(); // Overwrite lines of order |
|
219 | - $line=new CommandeFournisseurLigne($db); |
|
220 | - $line->desc=$langs->trans("Description")." specimen line ok"; |
|
221 | - $line->qty=10; // So enough quantity |
|
222 | - $line->subprice=100; |
|
223 | - $line->fk_product=$product->id; |
|
224 | - $line->ref_fourn=$ref_fourn; |
|
225 | - $localobject4->lines[]=$line; |
|
226 | - |
|
227 | - $result=$localobject4->create($user); |
|
216 | + $localobject4 = new CommandeFournisseur($db); |
|
217 | + $localobject4->initAsSpecimen(); // This create 5 lines of first product found for socid 1 |
|
218 | + $localobject4->lines = array(); // Overwrite lines of order |
|
219 | + $line = new CommandeFournisseurLigne($db); |
|
220 | + $line->desc = $langs->trans("Description")." specimen line ok"; |
|
221 | + $line->qty = 10; // So enough quantity |
|
222 | + $line->subprice = 100; |
|
223 | + $line->fk_product = $product->id; |
|
224 | + $line->ref_fourn = $ref_fourn; |
|
225 | + $localobject4->lines[] = $line; |
|
226 | + |
|
227 | + $result = $localobject4->create($user); |
|
228 | 228 | print __METHOD__." result=".$result."\n"; |
229 | 229 | $this->assertGreaterThan(0, $result); |
230 | 230 | |
@@ -244,14 +244,14 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function testCommandeFournisseurFetch($id) |
246 | 246 | { |
247 | - global $conf,$user,$langs,$db; |
|
248 | - $conf=$this->savconf; |
|
249 | - $user=$this->savuser; |
|
250 | - $langs=$this->savlangs; |
|
251 | - $db=$this->savdb; |
|
247 | + global $conf, $user, $langs, $db; |
|
248 | + $conf = $this->savconf; |
|
249 | + $user = $this->savuser; |
|
250 | + $langs = $this->savlangs; |
|
251 | + $db = $this->savdb; |
|
252 | 252 | |
253 | - $localobject=new CommandeFournisseur($this->savdb); |
|
254 | - $result=$localobject->fetch($id); |
|
253 | + $localobject = new CommandeFournisseur($this->savdb); |
|
254 | + $result = $localobject->fetch($id); |
|
255 | 255 | |
256 | 256 | print __METHOD__." id=".$id." result=".$result."\n"; |
257 | 257 | $this->assertLessThan($result, 0, 'Failed to fetch supplier order with id '.$id); |
@@ -269,13 +269,13 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function testCommandeFournisseurValid($localobject) |
271 | 271 | { |
272 | - global $conf,$user,$langs,$db; |
|
273 | - $conf=$this->savconf; |
|
274 | - $user=$this->savuser; |
|
275 | - $langs=$this->savlangs; |
|
276 | - $db=$this->savdb; |
|
272 | + global $conf, $user, $langs, $db; |
|
273 | + $conf = $this->savconf; |
|
274 | + $user = $this->savuser; |
|
275 | + $langs = $this->savlangs; |
|
276 | + $db = $this->savdb; |
|
277 | 277 | |
278 | - $result=$localobject->valid($user); |
|
278 | + $result = $localobject->valid($user); |
|
279 | 279 | |
280 | 280 | print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
281 | 281 | $this->assertLessThan($result, 0); |
@@ -293,13 +293,13 @@ discard block |
||
293 | 293 | */ |
294 | 294 | public function testCommandeFournisseurApprove($localobject) |
295 | 295 | { |
296 | - global $conf,$user,$langs,$db; |
|
297 | - $conf=$this->savconf; |
|
298 | - $user=$this->savuser; |
|
299 | - $langs=$this->savlangs; |
|
300 | - $db=$this->savdb; |
|
296 | + global $conf, $user, $langs, $db; |
|
297 | + $conf = $this->savconf; |
|
298 | + $user = $this->savuser; |
|
299 | + $langs = $this->savlangs; |
|
300 | + $db = $this->savdb; |
|
301 | 301 | |
302 | - $result=$localobject->approve($user); |
|
302 | + $result = $localobject->approve($user); |
|
303 | 303 | |
304 | 304 | print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
305 | 305 | $this->assertLessThan($result, 0); |
@@ -317,13 +317,13 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function testCommandeFournisseurCancel($localobject) |
319 | 319 | { |
320 | - global $conf,$user,$langs,$db; |
|
321 | - $conf=$this->savconf; |
|
322 | - $user=$this->savuser; |
|
323 | - $langs=$this->savlangs; |
|
324 | - $db=$this->savdb; |
|
320 | + global $conf, $user, $langs, $db; |
|
321 | + $conf = $this->savconf; |
|
322 | + $user = $this->savuser; |
|
323 | + $langs = $this->savlangs; |
|
324 | + $db = $this->savdb; |
|
325 | 325 | |
326 | - $result=$localobject->cancel($user); |
|
326 | + $result = $localobject->cancel($user); |
|
327 | 327 | |
328 | 328 | print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
329 | 329 | $this->assertLessThan($result, 0); |
@@ -341,11 +341,11 @@ discard block |
||
341 | 341 | */ |
342 | 342 | public function testCommandeFournisseurOther($localobject) |
343 | 343 | { |
344 | - global $conf,$user,$langs,$db; |
|
345 | - $conf=$this->savconf; |
|
346 | - $user=$this->savuser; |
|
347 | - $langs=$this->savlangs; |
|
348 | - $db=$this->savdb; |
|
344 | + global $conf, $user, $langs, $db; |
|
345 | + $conf = $this->savconf; |
|
346 | + $user = $this->savuser; |
|
347 | + $langs = $this->savlangs; |
|
348 | + $db = $this->savdb; |
|
349 | 349 | |
350 | 350 | /*$result=$localobject->setstatus(0); |
351 | 351 | print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
@@ -371,15 +371,15 @@ discard block |
||
371 | 371 | */ |
372 | 372 | public function testCommandeFournisseurDelete($id) |
373 | 373 | { |
374 | - global $conf,$user,$langs,$db; |
|
375 | - $conf=$this->savconf; |
|
376 | - $user=$this->savuser; |
|
377 | - $langs=$this->savlangs; |
|
378 | - $db=$this->savdb; |
|
379 | - |
|
380 | - $localobject=new CommandeFournisseur($this->savdb); |
|
381 | - $result=$localobject->fetch($id); |
|
382 | - $result=$localobject->delete($user); |
|
374 | + global $conf, $user, $langs, $db; |
|
375 | + $conf = $this->savconf; |
|
376 | + $user = $this->savuser; |
|
377 | + $langs = $this->savlangs; |
|
378 | + $db = $this->savdb; |
|
379 | + |
|
380 | + $localobject = new CommandeFournisseur($this->savdb); |
|
381 | + $result = $localobject->fetch($id); |
|
382 | + $result = $localobject->delete($user); |
|
383 | 383 | |
384 | 384 | print __METHOD__." id=".$id." result=".$result."\n"; |
385 | 385 | $this->assertLessThan($result, 0); |
@@ -59,75 +59,75 @@ discard block |
||
59 | 59 | */ |
60 | 60 | class SecurityTest extends PHPUnit_Framework_TestCase |
61 | 61 | { |
62 | - protected $savconf; |
|
63 | - protected $savuser; |
|
64 | - protected $savlangs; |
|
65 | - protected $savdb; |
|
66 | - |
|
67 | - /** |
|
68 | - * Constructor |
|
69 | - * We save global variables into local variables |
|
70 | - * |
|
71 | - * @return SecurityTest |
|
72 | - */ |
|
73 | - function __construct() |
|
74 | - { |
|
75 | - parent::__construct(); |
|
76 | - |
|
77 | - //$this->sharedFixture |
|
78 | - global $conf,$user,$langs,$db; |
|
79 | - $this->savconf=$conf; |
|
80 | - $this->savuser=$user; |
|
81 | - $this->savlangs=$langs; |
|
82 | - $this->savdb=$db; |
|
83 | - |
|
84 | - print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
|
85 | - //print " - db ".$db->db; |
|
86 | - print "\n"; |
|
87 | - } |
|
88 | - |
|
89 | - // Static methods |
|
90 | - public static function setUpBeforeClass() |
|
62 | + protected $savconf; |
|
63 | + protected $savuser; |
|
64 | + protected $savlangs; |
|
65 | + protected $savdb; |
|
66 | + |
|
67 | + /** |
|
68 | + * Constructor |
|
69 | + * We save global variables into local variables |
|
70 | + * |
|
71 | + * @return SecurityTest |
|
72 | + */ |
|
73 | + function __construct() |
|
91 | 74 | { |
92 | - global $conf,$user,$langs,$db; |
|
93 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
75 | + parent::__construct(); |
|
76 | + |
|
77 | + //$this->sharedFixture |
|
78 | + global $conf,$user,$langs,$db; |
|
79 | + $this->savconf=$conf; |
|
80 | + $this->savuser=$user; |
|
81 | + $this->savlangs=$langs; |
|
82 | + $this->savdb=$db; |
|
83 | + |
|
84 | + print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
|
85 | + //print " - db ".$db->db; |
|
86 | + print "\n"; |
|
87 | + } |
|
88 | + |
|
89 | + // Static methods |
|
90 | + public static function setUpBeforeClass() |
|
91 | + { |
|
92 | + global $conf,$user,$langs,$db; |
|
93 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
94 | 94 | |
95 | - print __METHOD__."\n"; |
|
95 | + print __METHOD__."\n"; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // tear down after class |
99 | 99 | public static function tearDownAfterClass() |
100 | 100 | { |
101 | - global $conf,$user,$langs,$db; |
|
102 | - $db->rollback(); |
|
101 | + global $conf,$user,$langs,$db; |
|
102 | + $db->rollback(); |
|
103 | 103 | |
104 | - print __METHOD__."\n"; |
|
104 | + print __METHOD__."\n"; |
|
105 | 105 | } |
106 | 106 | |
107 | - /** |
|
108 | - * Init phpunit tests |
|
109 | - * |
|
110 | - * @return void |
|
111 | - */ |
|
107 | + /** |
|
108 | + * Init phpunit tests |
|
109 | + * |
|
110 | + * @return void |
|
111 | + */ |
|
112 | 112 | protected function setUp() |
113 | 113 | { |
114 | - global $conf,$user,$langs,$db; |
|
115 | - $conf=$this->savconf; |
|
116 | - $user=$this->savuser; |
|
117 | - $langs=$this->savlangs; |
|
118 | - $db=$this->savdb; |
|
114 | + global $conf,$user,$langs,$db; |
|
115 | + $conf=$this->savconf; |
|
116 | + $user=$this->savuser; |
|
117 | + $langs=$this->savlangs; |
|
118 | + $db=$this->savdb; |
|
119 | 119 | |
120 | - print __METHOD__."\n"; |
|
120 | + print __METHOD__."\n"; |
|
121 | 121 | } |
122 | 122 | |
123 | - /** |
|
124 | - * End phpunit tests |
|
125 | - * |
|
126 | - * @return void |
|
127 | - */ |
|
123 | + /** |
|
124 | + * End phpunit tests |
|
125 | + * |
|
126 | + * @return void |
|
127 | + */ |
|
128 | 128 | protected function tearDown() |
129 | 129 | { |
130 | - print __METHOD__."\n"; |
|
130 | + print __METHOD__."\n"; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,16 +137,16 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function testGETPOST() |
139 | 139 | { |
140 | - global $conf,$user,$langs,$db; |
|
141 | - $conf=$this->savconf; |
|
142 | - $user=$this->savuser; |
|
143 | - $langs=$this->savlangs; |
|
144 | - $db=$this->savdb; |
|
140 | + global $conf,$user,$langs,$db; |
|
141 | + $conf=$this->savconf; |
|
142 | + $user=$this->savuser; |
|
143 | + $langs=$this->savlangs; |
|
144 | + $db=$this->savdb; |
|
145 | 145 | |
146 | 146 | $_COOKIE["id"]=111; |
147 | - $_GET["param1"]="222"; |
|
147 | + $_GET["param1"]="222"; |
|
148 | 148 | $_POST["param1"]="333"; |
149 | - $_GET["param2"]='a/b#e(pr)qq-rr\cc'; |
|
149 | + $_GET["param2"]='a/b#e(pr)qq-rr\cc'; |
|
150 | 150 | $_GET["param3"]='"a/b#e(pr)qq-rr\cc'; // Same than param2 + " |
151 | 151 | $_GET["param4"]='../dir'; |
152 | 152 | $_GET["param5"]="a_1-b"; |
@@ -288,16 +288,16 @@ discard block |
||
288 | 288 | */ |
289 | 289 | public function testRestrictedArea() |
290 | 290 | { |
291 | - global $conf,$user,$langs,$db; |
|
292 | - $conf=$this->savconf; |
|
293 | - $user=$this->savuser; |
|
294 | - $langs=$this->savlangs; |
|
295 | - $db=$this->savdb; |
|
291 | + global $conf,$user,$langs,$db; |
|
292 | + $conf=$this->savconf; |
|
293 | + $user=$this->savuser; |
|
294 | + $langs=$this->savlangs; |
|
295 | + $db=$this->savdb; |
|
296 | 296 | |
297 | - //$dummyuser=new User($db); |
|
298 | - //$result=restrictedArea($dummyuser,'societe'); |
|
297 | + //$dummyuser=new User($db); |
|
298 | + //$result=restrictedArea($dummyuser,'societe'); |
|
299 | 299 | |
300 | - $result=restrictedArea($user,'societe'); |
|
301 | - $this->assertEquals(1,$result); |
|
300 | + $result=restrictedArea($user,'societe'); |
|
301 | + $this->assertEquals(1,$result); |
|
302 | 302 | } |
303 | 303 | } |
@@ -23,23 +23,23 @@ discard block |
||
23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
24 | 24 | */ |
25 | 25 | |
26 | -global $conf,$user,$langs,$db; |
|
26 | +global $conf, $user, $langs, $db; |
|
27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php'; |
31 | 31 | require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php'; |
32 | 32 | |
33 | -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); |
|
34 | -if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); |
|
35 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
36 | -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); |
|
37 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); |
|
38 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); |
|
39 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show |
|
40 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php |
|
41 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
42 | -if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) |
|
33 | +if (!defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); |
|
34 | +if (!defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); |
|
35 | +if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); |
|
36 | +if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); |
|
37 | +if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); |
|
38 | +if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); |
|
39 | +if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show |
|
40 | +if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php |
|
41 | +if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); |
|
42 | +if (!defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
43 | 43 | |
44 | 44 | if (empty($user->id)) |
45 | 45 | { |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $user->fetch(1); |
48 | 48 | $user->getrights(); |
49 | 49 | } |
50 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
50 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
51 | 51 | |
52 | 52 | |
53 | 53 | /** |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | parent::__construct(); |
76 | 76 | |
77 | 77 | //$this->sharedFixture |
78 | - global $conf,$user,$langs,$db; |
|
79 | - $this->savconf=$conf; |
|
80 | - $this->savuser=$user; |
|
81 | - $this->savlangs=$langs; |
|
82 | - $this->savdb=$db; |
|
78 | + global $conf, $user, $langs, $db; |
|
79 | + $this->savconf = $conf; |
|
80 | + $this->savuser = $user; |
|
81 | + $this->savlangs = $langs; |
|
82 | + $this->savdb = $db; |
|
83 | 83 | |
84 | 84 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
85 | 85 | //print " - db ".$db->db; |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | // Static methods |
90 | 90 | public static function setUpBeforeClass() |
91 | 91 | { |
92 | - global $conf,$user,$langs,$db; |
|
93 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
92 | + global $conf, $user, $langs, $db; |
|
93 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
94 | 94 | |
95 | 95 | print __METHOD__."\n"; |
96 | 96 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | // tear down after class |
99 | 99 | public static function tearDownAfterClass() |
100 | 100 | { |
101 | - global $conf,$user,$langs,$db; |
|
101 | + global $conf, $user, $langs, $db; |
|
102 | 102 | $db->rollback(); |
103 | 103 | |
104 | 104 | print __METHOD__."\n"; |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | */ |
112 | 112 | protected function setUp() |
113 | 113 | { |
114 | - global $conf,$user,$langs,$db; |
|
115 | - $conf=$this->savconf; |
|
116 | - $user=$this->savuser; |
|
117 | - $langs=$this->savlangs; |
|
118 | - $db=$this->savdb; |
|
114 | + global $conf, $user, $langs, $db; |
|
115 | + $conf = $this->savconf; |
|
116 | + $user = $this->savuser; |
|
117 | + $langs = $this->savlangs; |
|
118 | + $db = $this->savdb; |
|
119 | 119 | |
120 | 120 | print __METHOD__."\n"; |
121 | 121 | } |
@@ -137,66 +137,66 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function testGETPOST() |
139 | 139 | { |
140 | - global $conf,$user,$langs,$db; |
|
141 | - $conf=$this->savconf; |
|
142 | - $user=$this->savuser; |
|
143 | - $langs=$this->savlangs; |
|
144 | - $db=$this->savdb; |
|
145 | - |
|
146 | - $_COOKIE["id"]=111; |
|
147 | - $_GET["param1"]="222"; |
|
148 | - $_POST["param1"]="333"; |
|
149 | - $_GET["param2"]='a/b#e(pr)qq-rr\cc'; |
|
150 | - $_GET["param3"]='"a/b#e(pr)qq-rr\cc'; // Same than param2 + " |
|
151 | - $_GET["param4"]='../dir'; |
|
152 | - $_GET["param5"]="a_1-b"; |
|
140 | + global $conf, $user, $langs, $db; |
|
141 | + $conf = $this->savconf; |
|
142 | + $user = $this->savuser; |
|
143 | + $langs = $this->savlangs; |
|
144 | + $db = $this->savdb; |
|
145 | + |
|
146 | + $_COOKIE["id"] = 111; |
|
147 | + $_GET["param1"] = "222"; |
|
148 | + $_POST["param1"] = "333"; |
|
149 | + $_GET["param2"] = 'a/b#e(pr)qq-rr\cc'; |
|
150 | + $_GET["param3"] = '"a/b#e(pr)qq-rr\cc'; // Same than param2 + " |
|
151 | + $_GET["param4"] = '../dir'; |
|
152 | + $_GET["param5"] = "a_1-b"; |
|
153 | 153 | |
154 | 154 | // Test int |
155 | - $result=GETPOST('id','int'); // Must return nothing |
|
155 | + $result = GETPOST('id', 'int'); // Must return nothing |
|
156 | 156 | print __METHOD__." result=".$result."\n"; |
157 | - $this->assertEquals($result,''); |
|
157 | + $this->assertEquals($result, ''); |
|
158 | 158 | |
159 | - $result=GETPOST("param1",'int'); |
|
159 | + $result = GETPOST("param1", 'int'); |
|
160 | 160 | print __METHOD__." result=".$result."\n"; |
161 | - $this->assertEquals($result,222); |
|
161 | + $this->assertEquals($result, 222); |
|
162 | 162 | |
163 | - $result=GETPOST("param1",'int',2); |
|
163 | + $result = GETPOST("param1", 'int', 2); |
|
164 | 164 | print __METHOD__." result=".$result."\n"; |
165 | - $this->assertEquals($result,333); |
|
165 | + $this->assertEquals($result, 333); |
|
166 | 166 | |
167 | 167 | // Test alpha |
168 | - $result=GETPOST("param2",'alpha'); |
|
168 | + $result = GETPOST("param2", 'alpha'); |
|
169 | 169 | print __METHOD__." result=".$result."\n"; |
170 | - $this->assertEquals($result,$_GET["param2"]); |
|
170 | + $this->assertEquals($result, $_GET["param2"]); |
|
171 | 171 | |
172 | - $result=GETPOST("param3",'alpha'); // Must return '' as there is a forbidden char " |
|
172 | + $result = GETPOST("param3", 'alpha'); // Must return '' as there is a forbidden char " |
|
173 | 173 | print __METHOD__." result=".$result."\n"; |
174 | - $this->assertEquals($result,''); |
|
174 | + $this->assertEquals($result, ''); |
|
175 | 175 | |
176 | - $result=GETPOST("param4",'alpha'); // Must return '' as there is a forbidden char ../ |
|
176 | + $result = GETPOST("param4", 'alpha'); // Must return '' as there is a forbidden char ../ |
|
177 | 177 | print __METHOD__." result=".$result."\n"; |
178 | - $this->assertEquals($result,''); |
|
178 | + $this->assertEquals($result, ''); |
|
179 | 179 | |
180 | 180 | // Test aZ09 |
181 | - $result=GETPOST("param1",'aZ09'); // Must return '' as there is a forbidden char ../ |
|
181 | + $result = GETPOST("param1", 'aZ09'); // Must return '' as there is a forbidden char ../ |
|
182 | 182 | print __METHOD__." result=".$result."\n"; |
183 | - $this->assertEquals($result,$_GET["param1"]); |
|
183 | + $this->assertEquals($result, $_GET["param1"]); |
|
184 | 184 | |
185 | - $result=GETPOST("param2",'aZ09'); // Must return '' as there is a forbidden char ../ |
|
185 | + $result = GETPOST("param2", 'aZ09'); // Must return '' as there is a forbidden char ../ |
|
186 | 186 | print __METHOD__." result=".$result."\n"; |
187 | - $this->assertEquals($result,''); |
|
187 | + $this->assertEquals($result, ''); |
|
188 | 188 | |
189 | - $result=GETPOST("param3",'aZ09'); // Must return '' as there is a forbidden char ../ |
|
189 | + $result = GETPOST("param3", 'aZ09'); // Must return '' as there is a forbidden char ../ |
|
190 | 190 | print __METHOD__." result=".$result."\n"; |
191 | - $this->assertEquals($result,''); |
|
191 | + $this->assertEquals($result, ''); |
|
192 | 192 | |
193 | - $result=GETPOST("param4",'aZ09'); // Must return '' as there is a forbidden char ../ |
|
193 | + $result = GETPOST("param4", 'aZ09'); // Must return '' as there is a forbidden char ../ |
|
194 | 194 | print __METHOD__." result=".$result."\n"; |
195 | - $this->assertEquals($result,''); |
|
195 | + $this->assertEquals($result, ''); |
|
196 | 196 | |
197 | - $result=GETPOST("param5",'aZ09'); |
|
197 | + $result = GETPOST("param5", 'aZ09'); |
|
198 | 198 | print __METHOD__." result=".$result."\n"; |
199 | - $this->assertEquals($result,$_GET["param5"]); |
|
199 | + $this->assertEquals($result, $_GET["param5"]); |
|
200 | 200 | |
201 | 201 | return $result; |
202 | 202 | } |
@@ -208,25 +208,25 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function testCheckLoginPassEntity() |
210 | 210 | { |
211 | - $login=checkLoginPassEntity('loginbidon','passwordbidon',1,array('dolibarr')); |
|
211 | + $login = checkLoginPassEntity('loginbidon', 'passwordbidon', 1, array('dolibarr')); |
|
212 | 212 | print __METHOD__." login=".$login."\n"; |
213 | - $this->assertEquals($login,''); |
|
213 | + $this->assertEquals($login, ''); |
|
214 | 214 | |
215 | - $login=checkLoginPassEntity('admin','passwordbidon',1,array('dolibarr')); |
|
215 | + $login = checkLoginPassEntity('admin', 'passwordbidon', 1, array('dolibarr')); |
|
216 | 216 | print __METHOD__." login=".$login."\n"; |
217 | - $this->assertEquals($login,''); |
|
217 | + $this->assertEquals($login, ''); |
|
218 | 218 | |
219 | - $login=checkLoginPassEntity('admin','admin',1,array('dolibarr')); // Should works because admin/admin exists |
|
219 | + $login = checkLoginPassEntity('admin', 'admin', 1, array('dolibarr')); // Should works because admin/admin exists |
|
220 | 220 | print __METHOD__." login=".$login."\n"; |
221 | - $this->assertEquals($login,'admin'); |
|
221 | + $this->assertEquals($login, 'admin'); |
|
222 | 222 | |
223 | - $login=checkLoginPassEntity('admin','admin',1,array('http','dolibarr')); // Should work because of second authetntication method |
|
223 | + $login = checkLoginPassEntity('admin', 'admin', 1, array('http', 'dolibarr')); // Should work because of second authetntication method |
|
224 | 224 | print __METHOD__." login=".$login."\n"; |
225 | - $this->assertEquals($login,'admin'); |
|
225 | + $this->assertEquals($login, 'admin'); |
|
226 | 226 | |
227 | - $login=checkLoginPassEntity('admin','admin',1,array('forceuser')); |
|
227 | + $login = checkLoginPassEntity('admin', 'admin', 1, array('forceuser')); |
|
228 | 228 | print __METHOD__." login=".$login."\n"; |
229 | - $this->assertEquals($login,''); // Expected '' because should failed because login 'auto' does not exists |
|
229 | + $this->assertEquals($login, ''); // Expected '' because should failed because login 'auto' does not exists |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -236,17 +236,17 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function testEncodeDecode() |
238 | 238 | { |
239 | - $stringtotest="This is a string to test encode/decode. This is a string to test encode/decode. This is a string to test encode/decode."; |
|
239 | + $stringtotest = "This is a string to test encode/decode. This is a string to test encode/decode. This is a string to test encode/decode."; |
|
240 | 240 | |
241 | - $encodedstring=dol_encode($stringtotest); |
|
242 | - $decodedstring=dol_decode($encodedstring); |
|
241 | + $encodedstring = dol_encode($stringtotest); |
|
242 | + $decodedstring = dol_decode($encodedstring); |
|
243 | 243 | print __METHOD__." encodedstring=".$encodedstring." ".base64_encode($stringtotest)."\n"; |
244 | - $this->assertEquals($stringtotest,$decodedstring, 'Use dol_encode/decode with no parameter'); |
|
244 | + $this->assertEquals($stringtotest, $decodedstring, 'Use dol_encode/decode with no parameter'); |
|
245 | 245 | |
246 | - $encodedstring=dol_encode($stringtotest, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
247 | - $decodedstring=dol_decode($encodedstring, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
246 | + $encodedstring = dol_encode($stringtotest, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
247 | + $decodedstring = dol_decode($encodedstring, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
248 | 248 | print __METHOD__." encodedstring=".$encodedstring." ".base64_encode($stringtotest)."\n"; |
249 | - $this->assertEquals($stringtotest,$decodedstring, 'Use dol_encode/decode with a key parameter'); |
|
249 | + $this->assertEquals($stringtotest, $decodedstring, 'Use dol_encode/decode with a key parameter'); |
|
250 | 250 | |
251 | 251 | return 0; |
252 | 252 | } |
@@ -260,21 +260,21 @@ discard block |
||
260 | 260 | { |
261 | 261 | global $conf; |
262 | 262 | |
263 | - $genpass1=getRandomPassword(true); // Should be a string return by dol_hash (if no option set, will be md5) |
|
263 | + $genpass1 = getRandomPassword(true); // Should be a string return by dol_hash (if no option set, will be md5) |
|
264 | 264 | print __METHOD__." genpass1=".$genpass1."\n"; |
265 | 265 | $this->assertEquals(strlen($genpass1), 32); |
266 | 266 | |
267 | - $genpass1=getRandomPassword(true, array('I')); // Should be a string return by dol_hash (if no option set, will be md5) |
|
267 | + $genpass1 = getRandomPassword(true, array('I')); // Should be a string return by dol_hash (if no option set, will be md5) |
|
268 | 268 | print __METHOD__." genpass1=".$genpass1."\n"; |
269 | 269 | $this->assertEquals(strlen($genpass1), 32); |
270 | 270 | |
271 | - $conf->global->USER_PASSWORD_GENERATED='None'; |
|
272 | - $genpass2=getRandomPassword(false); // Should return an empty string |
|
271 | + $conf->global->USER_PASSWORD_GENERATED = 'None'; |
|
272 | + $genpass2 = getRandomPassword(false); // Should return an empty string |
|
273 | 273 | print __METHOD__." genpass2=".$genpass2."\n"; |
274 | 274 | $this->assertEquals($genpass2, ''); |
275 | 275 | |
276 | - $conf->global->USER_PASSWORD_GENERATED='Standard'; |
|
277 | - $genpass3=getRandomPassword(false); // Should return a password of 8 chars |
|
276 | + $conf->global->USER_PASSWORD_GENERATED = 'Standard'; |
|
277 | + $genpass3 = getRandomPassword(false); // Should return a password of 8 chars |
|
278 | 278 | print __METHOD__." genpass3=".$genpass3."\n"; |
279 | 279 | $this->assertEquals(strlen($genpass3), 8); |
280 | 280 | |
@@ -288,16 +288,16 @@ discard block |
||
288 | 288 | */ |
289 | 289 | public function testRestrictedArea() |
290 | 290 | { |
291 | - global $conf,$user,$langs,$db; |
|
292 | - $conf=$this->savconf; |
|
293 | - $user=$this->savuser; |
|
294 | - $langs=$this->savlangs; |
|
295 | - $db=$this->savdb; |
|
291 | + global $conf, $user, $langs, $db; |
|
292 | + $conf = $this->savconf; |
|
293 | + $user = $this->savuser; |
|
294 | + $langs = $this->savlangs; |
|
295 | + $db = $this->savdb; |
|
296 | 296 | |
297 | 297 | //$dummyuser=new User($db); |
298 | 298 | //$result=restrictedArea($dummyuser,'societe'); |
299 | 299 | |
300 | - $result=restrictedArea($user,'societe'); |
|
301 | - $this->assertEquals(1,$result); |
|
300 | + $result = restrictedArea($user, 'societe'); |
|
301 | + $this->assertEquals(1, $result); |
|
302 | 302 | } |
303 | 303 | } |
@@ -30,16 +30,39 @@ |
||
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php'; |
31 | 31 | require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php'; |
32 | 32 | |
33 | -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); |
|
34 | -if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); |
|
35 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
36 | -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); |
|
37 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); |
|
38 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); |
|
39 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show |
|
40 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php |
|
41 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
42 | -if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) |
|
33 | +if (! defined('NOREQUIREUSER')) { |
|
34 | + define('NOREQUIREUSER','1'); |
|
35 | +} |
|
36 | +if (! defined('NOREQUIREDB')) { |
|
37 | + define('NOREQUIREDB','1'); |
|
38 | +} |
|
39 | +if (! defined('NOREQUIRESOC')) { |
|
40 | + define('NOREQUIRESOC','1'); |
|
41 | +} |
|
42 | +if (! defined('NOREQUIRETRAN')) { |
|
43 | + define('NOREQUIRETRAN','1'); |
|
44 | +} |
|
45 | +if (! defined('NOCSRFCHECK')) { |
|
46 | + define('NOCSRFCHECK','1'); |
|
47 | +} |
|
48 | +if (! defined('NOTOKENRENEWAL')) { |
|
49 | + define('NOTOKENRENEWAL','1'); |
|
50 | +} |
|
51 | +if (! defined('NOREQUIREMENU')) { |
|
52 | + define('NOREQUIREMENU','1'); |
|
53 | +} |
|
54 | +// If there is no menu to show |
|
55 | +if (! defined('NOREQUIREHTML')) { |
|
56 | + define('NOREQUIREHTML','1'); |
|
57 | +} |
|
58 | +// If we don't need to load the html.form.class.php |
|
59 | +if (! defined('NOREQUIREAJAX')) { |
|
60 | + define('NOREQUIREAJAX','1'); |
|
61 | +} |
|
62 | +if (! defined("NOLOGIN")) { |
|
63 | + define("NOLOGIN",'1'); |
|
64 | +} |
|
65 | +// If this page is public (can be called outside logged session) |
|
43 | 66 | |
44 | 67 | if (empty($user->id)) |
45 | 68 | { |
@@ -63,9 +63,9 @@ |
||
63 | 63 | */ |
64 | 64 | function __construct() |
65 | 65 | { |
66 | - parent::__construct(); |
|
66 | + parent::__construct(); |
|
67 | 67 | |
68 | - //$this->sharedFixture |
|
68 | + //$this->sharedFixture |
|
69 | 69 | global $conf,$user,$langs,$db; |
70 | 70 | $this->savconf=$conf; |
71 | 71 | $this->savuser=$user; |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
24 | 24 | */ |
25 | 25 | |
26 | -global $conf,$user,$langs,$db; |
|
26 | +global $conf, $user, $langs, $db; |
|
27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php'; |
31 | -require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP |
|
31 | +require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP |
|
32 | 32 | |
33 | 33 | |
34 | 34 | if (empty($user->id)) { |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | $user->fetch(1); |
37 | 37 | $user->getrights(); |
38 | 38 | } |
39 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
39 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
40 | 40 | |
41 | -$conf->global->MAIN_UMASK='0666'; |
|
41 | +$conf->global->MAIN_UMASK = '0666'; |
|
42 | 42 | |
43 | 43 | |
44 | 44 | /** |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | parent::__construct(); |
67 | 67 | |
68 | 68 | //$this->sharedFixture |
69 | - global $conf,$user,$langs,$db; |
|
70 | - $this->savconf=$conf; |
|
71 | - $this->savuser=$user; |
|
72 | - $this->savlangs=$langs; |
|
73 | - $this->savdb=$db; |
|
69 | + global $conf, $user, $langs, $db; |
|
70 | + $this->savconf = $conf; |
|
71 | + $this->savuser = $user; |
|
72 | + $this->savlangs = $langs; |
|
73 | + $this->savdb = $db; |
|
74 | 74 | |
75 | 75 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
76 | 76 | //print " - db ".$db->db; |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | // Static methods |
81 | 81 | public static function setUpBeforeClass() |
82 | 82 | { |
83 | - global $conf,$user,$langs,$db; |
|
84 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
83 | + global $conf, $user, $langs, $db; |
|
84 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
85 | 85 | |
86 | 86 | print __METHOD__."\n"; |
87 | 87 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | // tear down after class |
90 | 90 | public static function tearDownAfterClass() |
91 | 91 | { |
92 | - global $conf,$user,$langs,$db; |
|
92 | + global $conf, $user, $langs, $db; |
|
93 | 93 | $db->rollback(); |
94 | 94 | |
95 | 95 | print __METHOD__."\n"; |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function setUp() |
104 | 104 | { |
105 | - global $conf,$user,$langs,$db; |
|
106 | - $conf=$this->savconf; |
|
107 | - $user=$this->savuser; |
|
108 | - $langs=$this->savlangs; |
|
109 | - $db=$this->savdb; |
|
105 | + global $conf, $user, $langs, $db; |
|
106 | + $conf = $this->savconf; |
|
107 | + $user = $this->savuser; |
|
108 | + $langs = $this->savlangs; |
|
109 | + $db = $this->savdb; |
|
110 | 110 | |
111 | 111 | print __METHOD__."\n"; |
112 | 112 | } |
@@ -129,26 +129,26 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function testWSOrderGetOrder() |
131 | 131 | { |
132 | - global $conf,$user,$langs,$db; |
|
133 | - $conf=$this->savconf; |
|
134 | - $user=$this->savuser; |
|
135 | - $langs=$this->savlangs; |
|
136 | - $db=$this->savdb; |
|
132 | + global $conf, $user, $langs, $db; |
|
133 | + $conf = $this->savconf; |
|
134 | + $user = $this->savuser; |
|
135 | + $langs = $this->savlangs; |
|
136 | + $db = $this->savdb; |
|
137 | 137 | |
138 | 138 | $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_order.php'; |
139 | 139 | $WS_METHOD = 'getOrder'; |
140 | - $ns='http://www.dolibarr.org/ns/'; |
|
140 | + $ns = 'http://www.dolibarr.org/ns/'; |
|
141 | 141 | |
142 | 142 | // Set the WebService URL |
143 | 143 | print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; |
144 | 144 | $soapclient = new nusoap_client($WS_DOL_URL); |
145 | 145 | if ($soapclient) { |
146 | - $soapclient->soap_defencoding='UTF-8'; |
|
146 | + $soapclient->soap_defencoding = 'UTF-8'; |
|
147 | 147 | $soapclient->decodeUTF8(false); |
148 | 148 | } |
149 | 149 | |
150 | 150 | // Call the WebService method and store its result in $result. |
151 | - $authentication=array( |
|
151 | + $authentication = array( |
|
152 | 152 | 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, |
153 | 153 | 'sourceapplication'=>'DEMO', |
154 | 154 | 'login'=>'admin', |
@@ -157,15 +157,15 @@ discard block |
||
157 | 157 | ); |
158 | 158 | |
159 | 159 | // Test URL |
160 | - $parameters = array('authentication'=>$authentication,'id'=>1); |
|
160 | + $parameters = array('authentication'=>$authentication, 'id'=>1); |
|
161 | 161 | print __METHOD__." call method ".$WS_METHOD."\n"; |
162 | 162 | try { |
163 | - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); |
|
164 | - } catch(SoapFault $exception) { |
|
163 | + $result = $soapclient->call($WS_METHOD, $parameters, $ns, ''); |
|
164 | + } catch (SoapFault $exception) { |
|
165 | 165 | echo $exception; |
166 | - $result=0; |
|
166 | + $result = 0; |
|
167 | 167 | } |
168 | - if (! $result || ! empty($result['faultstring'])) { |
|
168 | + if (!$result || !empty($result['faultstring'])) { |
|
169 | 169 | //var_dump($soapclient); |
170 | 170 | print $soapclient->error_str; |
171 | 171 | print "\n<br>\n"; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | print __METHOD__." result=".$result."\n"; |
179 | - $this->assertEquals('OK',$result['result']['result_code']); |
|
179 | + $this->assertEquals('OK', $result['result']['result_code']); |
|
180 | 180 | |
181 | 181 | return $result; |
182 | 182 | } |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | |
32 | 32 | if (empty($user->id)) |
33 | 33 | { |
34 | - print "Load permissions for admin user nb 1\n"; |
|
35 | - $user->fetch(1); |
|
36 | - $user->getrights(); |
|
34 | + print "Load permissions for admin user nb 1\n"; |
|
35 | + $user->fetch(1); |
|
36 | + $user->getrights(); |
|
37 | 37 | } |
38 | 38 | $conf->global->MAIN_DISABLE_ALL_MAILS=1; |
39 | 39 | |
@@ -47,74 +47,74 @@ discard block |
||
47 | 47 | */ |
48 | 48 | class ContratTest extends PHPUnit_Framework_TestCase |
49 | 49 | { |
50 | - protected $savconf; |
|
51 | - protected $savuser; |
|
52 | - protected $savlangs; |
|
53 | - protected $savdb; |
|
54 | - |
|
55 | - /** |
|
56 | - * Constructor |
|
57 | - * We save global variables into local variables |
|
58 | - * |
|
59 | - * @return ContratTest |
|
60 | - */ |
|
61 | - function __construct() |
|
62 | - { |
|
63 | - parent::__construct(); |
|
64 | - |
|
65 | - //$this->sharedFixture |
|
66 | - global $conf,$user,$langs,$db; |
|
67 | - $this->savconf=$conf; |
|
68 | - $this->savuser=$user; |
|
69 | - $this->savlangs=$langs; |
|
70 | - $this->savdb=$db; |
|
71 | - |
|
72 | - print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
|
73 | - //print " - db ".$db->db; |
|
74 | - print "\n"; |
|
75 | - } |
|
76 | - |
|
77 | - // Static methods |
|
78 | - public static function setUpBeforeClass() |
|
50 | + protected $savconf; |
|
51 | + protected $savuser; |
|
52 | + protected $savlangs; |
|
53 | + protected $savdb; |
|
54 | + |
|
55 | + /** |
|
56 | + * Constructor |
|
57 | + * We save global variables into local variables |
|
58 | + * |
|
59 | + * @return ContratTest |
|
60 | + */ |
|
61 | + function __construct() |
|
79 | 62 | { |
80 | - global $conf,$user,$langs,$db; |
|
81 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
63 | + parent::__construct(); |
|
82 | 64 | |
83 | - print __METHOD__."\n"; |
|
65 | + //$this->sharedFixture |
|
66 | + global $conf,$user,$langs,$db; |
|
67 | + $this->savconf=$conf; |
|
68 | + $this->savuser=$user; |
|
69 | + $this->savlangs=$langs; |
|
70 | + $this->savdb=$db; |
|
71 | + |
|
72 | + print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
|
73 | + //print " - db ".$db->db; |
|
74 | + print "\n"; |
|
75 | + } |
|
76 | + |
|
77 | + // Static methods |
|
78 | + public static function setUpBeforeClass() |
|
79 | + { |
|
80 | + global $conf,$user,$langs,$db; |
|
81 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
82 | + |
|
83 | + print __METHOD__."\n"; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | // tear down after class |
87 | 87 | public static function tearDownAfterClass() |
88 | 88 | { |
89 | - global $conf,$user,$langs,$db; |
|
90 | - $db->rollback(); |
|
89 | + global $conf,$user,$langs,$db; |
|
90 | + $db->rollback(); |
|
91 | 91 | |
92 | - print __METHOD__."\n"; |
|
92 | + print __METHOD__."\n"; |
|
93 | 93 | } |
94 | 94 | |
95 | - /** |
|
96 | - * Init phpunit tests |
|
97 | - * |
|
98 | - * @return void |
|
99 | - */ |
|
95 | + /** |
|
96 | + * Init phpunit tests |
|
97 | + * |
|
98 | + * @return void |
|
99 | + */ |
|
100 | 100 | protected function setUp() |
101 | 101 | { |
102 | - global $conf,$user,$langs,$db; |
|
103 | - $conf=$this->savconf; |
|
104 | - $user=$this->savuser; |
|
105 | - $langs=$this->savlangs; |
|
106 | - $db=$this->savdb; |
|
102 | + global $conf,$user,$langs,$db; |
|
103 | + $conf=$this->savconf; |
|
104 | + $user=$this->savuser; |
|
105 | + $langs=$this->savlangs; |
|
106 | + $db=$this->savdb; |
|
107 | 107 | |
108 | - print __METHOD__."\n"; |
|
108 | + print __METHOD__."\n"; |
|
109 | 109 | } |
110 | - /** |
|
111 | - * End phpunit tests |
|
112 | - * |
|
113 | - * @return void |
|
114 | - */ |
|
110 | + /** |
|
111 | + * End phpunit tests |
|
112 | + * |
|
113 | + * @return void |
|
114 | + */ |
|
115 | 115 | protected function tearDown() |
116 | 116 | { |
117 | - print __METHOD__."\n"; |
|
117 | + print __METHOD__."\n"; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -124,20 +124,20 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function testContratCreate() |
126 | 126 | { |
127 | - global $conf,$user,$langs,$db; |
|
128 | - $conf=$this->savconf; |
|
129 | - $user=$this->savuser; |
|
130 | - $langs=$this->savlangs; |
|
131 | - $db=$this->savdb; |
|
127 | + global $conf,$user,$langs,$db; |
|
128 | + $conf=$this->savconf; |
|
129 | + $user=$this->savuser; |
|
130 | + $langs=$this->savlangs; |
|
131 | + $db=$this->savdb; |
|
132 | 132 | |
133 | - $localobject=new Contrat($this->savdb); |
|
134 | - $localobject->initAsSpecimen(); |
|
135 | - $result=$localobject->create($user); |
|
133 | + $localobject=new Contrat($this->savdb); |
|
134 | + $localobject->initAsSpecimen(); |
|
135 | + $result=$localobject->create($user); |
|
136 | 136 | |
137 | - print __METHOD__." result=".$result."\n"; |
|
138 | - $this->assertLessThan($result, 0); |
|
137 | + print __METHOD__." result=".$result."\n"; |
|
138 | + $this->assertLessThan($result, 0); |
|
139 | 139 | |
140 | - return $result; |
|
140 | + return $result; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -151,22 +151,22 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function testContratFetch($id) |
153 | 153 | { |
154 | - global $conf,$user,$langs,$db; |
|
155 | - $conf=$this->savconf; |
|
156 | - $user=$this->savuser; |
|
157 | - $langs=$this->savlangs; |
|
158 | - $db=$this->savdb; |
|
154 | + global $conf,$user,$langs,$db; |
|
155 | + $conf=$this->savconf; |
|
156 | + $user=$this->savuser; |
|
157 | + $langs=$this->savlangs; |
|
158 | + $db=$this->savdb; |
|
159 | 159 | |
160 | - $localobject=new Contrat($this->savdb); |
|
161 | - $result=$localobject->fetch($id); |
|
160 | + $localobject=new Contrat($this->savdb); |
|
161 | + $result=$localobject->fetch($id); |
|
162 | 162 | |
163 | - print __METHOD__." id=".$id." result=".$result."\n"; |
|
164 | - $this->assertLessThan($result, 0); |
|
163 | + print __METHOD__." id=".$id." result=".$result."\n"; |
|
164 | + $this->assertLessThan($result, 0); |
|
165 | 165 | |
166 | - return $localobject; |
|
166 | + return $localobject; |
|
167 | 167 | } |
168 | 168 | |
169 | - /** |
|
169 | + /** |
|
170 | 170 | * testContratOther |
171 | 171 | * |
172 | 172 | * @param Object $localobject Object contract |
@@ -206,18 +206,18 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function testContratDelete($id) |
208 | 208 | { |
209 | - global $conf,$user,$langs,$db; |
|
210 | - $conf=$this->savconf; |
|
211 | - $user=$this->savuser; |
|
212 | - $langs=$this->savlangs; |
|
213 | - $db=$this->savdb; |
|
214 | - |
|
215 | - $localobject=new Contrat($this->savdb); |
|
216 | - $result=$localobject->fetch($id); |
|
217 | - $result=$localobject->delete($user); |
|
218 | - |
|
219 | - print __METHOD__." id=".$id." result=".$result."\n"; |
|
220 | - $this->assertLessThan($result, 0); |
|
221 | - return $result; |
|
209 | + global $conf,$user,$langs,$db; |
|
210 | + $conf=$this->savconf; |
|
211 | + $user=$this->savuser; |
|
212 | + $langs=$this->savlangs; |
|
213 | + $db=$this->savdb; |
|
214 | + |
|
215 | + $localobject=new Contrat($this->savdb); |
|
216 | + $result=$localobject->fetch($id); |
|
217 | + $result=$localobject->delete($user); |
|
218 | + |
|
219 | + print __METHOD__." id=".$id." result=".$result."\n"; |
|
220 | + $this->assertLessThan($result, 0); |
|
221 | + return $result; |
|
222 | 222 | } |
223 | 223 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
24 | 24 | */ |
25 | 25 | |
26 | -global $conf,$user,$langs,$db; |
|
26 | +global $conf, $user, $langs, $db; |
|
27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $user->fetch(1); |
36 | 36 | $user->getrights(); |
37 | 37 | } |
38 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
38 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
39 | 39 | |
40 | 40 | |
41 | 41 | /** |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | parent::__construct(); |
64 | 64 | |
65 | 65 | //$this->sharedFixture |
66 | - global $conf,$user,$langs,$db; |
|
67 | - $this->savconf=$conf; |
|
68 | - $this->savuser=$user; |
|
69 | - $this->savlangs=$langs; |
|
70 | - $this->savdb=$db; |
|
66 | + global $conf, $user, $langs, $db; |
|
67 | + $this->savconf = $conf; |
|
68 | + $this->savuser = $user; |
|
69 | + $this->savlangs = $langs; |
|
70 | + $this->savdb = $db; |
|
71 | 71 | |
72 | 72 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
73 | 73 | //print " - db ".$db->db; |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | // Static methods |
78 | 78 | public static function setUpBeforeClass() |
79 | 79 | { |
80 | - global $conf,$user,$langs,$db; |
|
81 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
80 | + global $conf, $user, $langs, $db; |
|
81 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
82 | 82 | |
83 | 83 | print __METHOD__."\n"; |
84 | 84 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | // tear down after class |
87 | 87 | public static function tearDownAfterClass() |
88 | 88 | { |
89 | - global $conf,$user,$langs,$db; |
|
89 | + global $conf, $user, $langs, $db; |
|
90 | 90 | $db->rollback(); |
91 | 91 | |
92 | 92 | print __METHOD__."\n"; |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | */ |
100 | 100 | protected function setUp() |
101 | 101 | { |
102 | - global $conf,$user,$langs,$db; |
|
103 | - $conf=$this->savconf; |
|
104 | - $user=$this->savuser; |
|
105 | - $langs=$this->savlangs; |
|
106 | - $db=$this->savdb; |
|
102 | + global $conf, $user, $langs, $db; |
|
103 | + $conf = $this->savconf; |
|
104 | + $user = $this->savuser; |
|
105 | + $langs = $this->savlangs; |
|
106 | + $db = $this->savdb; |
|
107 | 107 | |
108 | 108 | print __METHOD__."\n"; |
109 | 109 | } |
@@ -124,15 +124,15 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function testContratCreate() |
126 | 126 | { |
127 | - global $conf,$user,$langs,$db; |
|
128 | - $conf=$this->savconf; |
|
129 | - $user=$this->savuser; |
|
130 | - $langs=$this->savlangs; |
|
131 | - $db=$this->savdb; |
|
127 | + global $conf, $user, $langs, $db; |
|
128 | + $conf = $this->savconf; |
|
129 | + $user = $this->savuser; |
|
130 | + $langs = $this->savlangs; |
|
131 | + $db = $this->savdb; |
|
132 | 132 | |
133 | - $localobject=new Contrat($this->savdb); |
|
133 | + $localobject = new Contrat($this->savdb); |
|
134 | 134 | $localobject->initAsSpecimen(); |
135 | - $result=$localobject->create($user); |
|
135 | + $result = $localobject->create($user); |
|
136 | 136 | |
137 | 137 | print __METHOD__." result=".$result."\n"; |
138 | 138 | $this->assertLessThan($result, 0); |
@@ -151,14 +151,14 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function testContratFetch($id) |
153 | 153 | { |
154 | - global $conf,$user,$langs,$db; |
|
155 | - $conf=$this->savconf; |
|
156 | - $user=$this->savuser; |
|
157 | - $langs=$this->savlangs; |
|
158 | - $db=$this->savdb; |
|
154 | + global $conf, $user, $langs, $db; |
|
155 | + $conf = $this->savconf; |
|
156 | + $user = $this->savuser; |
|
157 | + $langs = $this->savlangs; |
|
158 | + $db = $this->savdb; |
|
159 | 159 | |
160 | - $localobject=new Contrat($this->savdb); |
|
161 | - $result=$localobject->fetch($id); |
|
160 | + $localobject = new Contrat($this->savdb); |
|
161 | + $result = $localobject->fetch($id); |
|
162 | 162 | |
163 | 163 | print __METHOD__." id=".$id." result=".$result."\n"; |
164 | 164 | $this->assertLessThan($result, 0); |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function testContratOther($localobject) |
179 | 179 | { |
180 | - global $conf,$user,$langs,$db; |
|
181 | - $conf=$this->savconf; |
|
182 | - $user=$this->savuser; |
|
183 | - $langs=$this->savlangs; |
|
184 | - $db=$this->savdb; |
|
180 | + global $conf, $user, $langs, $db; |
|
181 | + $conf = $this->savconf; |
|
182 | + $user = $this->savuser; |
|
183 | + $langs = $this->savlangs; |
|
184 | + $db = $this->savdb; |
|
185 | 185 | |
186 | 186 | /*$result=$localobject->setstatus(0); |
187 | 187 | print __METHOD__." id=".$localobject->id." result=".$result."\n"; |
@@ -206,15 +206,15 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function testContratDelete($id) |
208 | 208 | { |
209 | - global $conf,$user,$langs,$db; |
|
210 | - $conf=$this->savconf; |
|
211 | - $user=$this->savuser; |
|
212 | - $langs=$this->savlangs; |
|
213 | - $db=$this->savdb; |
|
214 | - |
|
215 | - $localobject=new Contrat($this->savdb); |
|
216 | - $result=$localobject->fetch($id); |
|
217 | - $result=$localobject->delete($user); |
|
209 | + global $conf, $user, $langs, $db; |
|
210 | + $conf = $this->savconf; |
|
211 | + $user = $this->savuser; |
|
212 | + $langs = $this->savlangs; |
|
213 | + $db = $this->savdb; |
|
214 | + |
|
215 | + $localobject = new Contrat($this->savdb); |
|
216 | + $result = $localobject->fetch($id); |
|
217 | + $result = $localobject->delete($user); |
|
218 | 218 | |
219 | 219 | print __METHOD__." id=".$id." result=".$result."\n"; |
220 | 220 | $this->assertLessThan($result, 0); |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | */ |
64 | 64 | function __construct() |
65 | 65 | { |
66 | - parent::__construct(); |
|
66 | + parent::__construct(); |
|
67 | 67 | |
68 | - //$this->sharedFixture |
|
68 | + //$this->sharedFixture |
|
69 | 69 | global $conf,$user,$langs,$db; |
70 | 70 | $this->savconf=$conf; |
71 | 71 | $this->savuser=$user; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * Init phpunit tests |
100 | 100 | * |
101 | 101 | * @return void |
102 | - */ |
|
102 | + */ |
|
103 | 103 | protected function setUp() |
104 | 104 | { |
105 | 105 | global $conf,$user,$langs,$db; |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
24 | 24 | */ |
25 | 25 | |
26 | -global $conf,$user,$langs,$db; |
|
26 | +global $conf, $user, $langs, $db; |
|
27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php'; |
31 | -require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP |
|
31 | +require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP |
|
32 | 32 | |
33 | 33 | |
34 | 34 | if (empty($user->id)) { |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | $user->fetch(1); |
37 | 37 | $user->getrights(); |
38 | 38 | } |
39 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
39 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
40 | 40 | |
41 | -$conf->global->MAIN_UMASK='0666'; |
|
41 | +$conf->global->MAIN_UMASK = '0666'; |
|
42 | 42 | |
43 | 43 | |
44 | 44 | /** |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | parent::__construct(); |
67 | 67 | |
68 | 68 | //$this->sharedFixture |
69 | - global $conf,$user,$langs,$db; |
|
70 | - $this->savconf=$conf; |
|
71 | - $this->savuser=$user; |
|
72 | - $this->savlangs=$langs; |
|
73 | - $this->savdb=$db; |
|
69 | + global $conf, $user, $langs, $db; |
|
70 | + $this->savconf = $conf; |
|
71 | + $this->savuser = $user; |
|
72 | + $this->savlangs = $langs; |
|
73 | + $this->savdb = $db; |
|
74 | 74 | |
75 | 75 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
76 | 76 | //print " - db ".$db->db; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | // Static methods |
81 | 81 | public static function setUpBeforeClass() |
82 | 82 | { |
83 | - global $conf,$user,$langs,$db; |
|
83 | + global $conf, $user, $langs, $db; |
|
84 | 84 | $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
85 | 85 | |
86 | 86 | print __METHOD__."\n"; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | // tear down after class |
90 | 90 | public static function tearDownAfterClass() |
91 | 91 | { |
92 | - global $conf,$user,$langs,$db; |
|
92 | + global $conf, $user, $langs, $db; |
|
93 | 93 | $db->rollback(); |
94 | 94 | |
95 | 95 | print __METHOD__."\n"; |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function setUp() |
104 | 104 | { |
105 | - global $conf,$user,$langs,$db; |
|
106 | - $conf=$this->savconf; |
|
107 | - $user=$this->savuser; |
|
108 | - $langs=$this->savlangs; |
|
109 | - $db=$this->savdb; |
|
105 | + global $conf, $user, $langs, $db; |
|
106 | + $conf = $this->savconf; |
|
107 | + $user = $this->savuser; |
|
108 | + $langs = $this->savlangs; |
|
109 | + $db = $this->savdb; |
|
110 | 110 | |
111 | 111 | print __METHOD__."\n"; |
112 | 112 | } |
@@ -129,26 +129,26 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function testWSOtherGetVersions() |
131 | 131 | { |
132 | - global $conf,$user,$langs,$db; |
|
133 | - $conf=$this->savconf; |
|
134 | - $user=$this->savuser; |
|
135 | - $langs=$this->savlangs; |
|
136 | - $db=$this->savdb; |
|
132 | + global $conf, $user, $langs, $db; |
|
133 | + $conf = $this->savconf; |
|
134 | + $user = $this->savuser; |
|
135 | + $langs = $this->savlangs; |
|
136 | + $db = $this->savdb; |
|
137 | 137 | |
138 | 138 | $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_other.php'; |
139 | 139 | $WS_METHOD = 'getVersions'; |
140 | - $ns='http://www.dolibarr.org/ns/'; |
|
140 | + $ns = 'http://www.dolibarr.org/ns/'; |
|
141 | 141 | |
142 | 142 | // Set the WebService URL |
143 | 143 | print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; |
144 | 144 | $soapclient = new nusoap_client($WS_DOL_URL); |
145 | 145 | if ($soapclient) { |
146 | - $soapclient->soap_defencoding='UTF-8'; |
|
146 | + $soapclient->soap_defencoding = 'UTF-8'; |
|
147 | 147 | $soapclient->decodeUTF8(false); |
148 | 148 | } |
149 | 149 | |
150 | 150 | // Call the WebService method and store its result in $result. |
151 | - $authentication=array( |
|
151 | + $authentication = array( |
|
152 | 152 | 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, |
153 | 153 | 'sourceapplication'=>'DEMO', |
154 | 154 | 'login'=>'admin', |
@@ -157,20 +157,20 @@ discard block |
||
157 | 157 | ); |
158 | 158 | |
159 | 159 | // Test URL |
160 | - $result=''; |
|
160 | + $result = ''; |
|
161 | 161 | $parameters = array('authentication'=>$authentication); |
162 | 162 | print __METHOD__." call method ".$WS_METHOD."\n"; |
163 | 163 | try { |
164 | - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); |
|
165 | - } catch(SoapFault $exception) { |
|
164 | + $result = $soapclient->call($WS_METHOD, $parameters, $ns, ''); |
|
165 | + } catch (SoapFault $exception) { |
|
166 | 166 | echo $exception; |
167 | - $result=0; |
|
167 | + $result = 0; |
|
168 | 168 | } |
169 | - if (! empty($result['faultstring'])) { |
|
169 | + if (!empty($result['faultstring'])) { |
|
170 | 170 | print $result['faultstring']."\n"; |
171 | - $result=0; |
|
171 | + $result = 0; |
|
172 | 172 | } |
173 | - if (! $result) { |
|
173 | + if (!$result) { |
|
174 | 174 | //var_dump($soapclient); |
175 | 175 | print $soapclient->error_str; |
176 | 176 | print "\n<br>\n"; |
@@ -181,20 +181,20 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | print __METHOD__." result=".$result."\n"; |
184 | - $this->assertEquals('OK',$result['result']['result_code']); |
|
184 | + $this->assertEquals('OK', $result['result']['result_code']); |
|
185 | 185 | |
186 | 186 | // Test method that does not exists |
187 | - $WS_METHOD='methodthatdoesnotexists'; |
|
188 | - $result=''; |
|
187 | + $WS_METHOD = 'methodthatdoesnotexists'; |
|
188 | + $result = ''; |
|
189 | 189 | $parameters = array('authentication'=>$authentication); |
190 | 190 | print __METHOD__." call method ".$WS_METHOD."\n"; |
191 | 191 | try { |
192 | - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); |
|
193 | - } catch(SoapFault $exception) { |
|
192 | + $result = $soapclient->call($WS_METHOD, $parameters, $ns, ''); |
|
193 | + } catch (SoapFault $exception) { |
|
194 | 194 | echo $exception; |
195 | - $result=0; |
|
195 | + $result = 0; |
|
196 | 196 | } |
197 | - if (! $result || ! empty($result['faultstring'])) { |
|
197 | + if (!$result || !empty($result['faultstring'])) { |
|
198 | 198 | //var_dump($soapclient); |
199 | 199 | print $soapclient->error_str; |
200 | 200 | print "\n<br>\n"; |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | */ |
63 | 63 | function __construct() |
64 | 64 | { |
65 | - parent::__construct(); |
|
65 | + parent::__construct(); |
|
66 | 66 | |
67 | - //$this->sharedFixture |
|
67 | + //$this->sharedFixture |
|
68 | 68 | global $conf,$user,$langs,$db; |
69 | 69 | $this->savconf=$conf; |
70 | 70 | $this->savuser=$user; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * Init phpunit tests |
99 | 99 | * |
100 | 100 | * @return void |
101 | - */ |
|
101 | + */ |
|
102 | 102 | protected function setUp() |
103 | 103 | { |
104 | 104 | global $conf,$user,$langs,$db; |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | |
222 | 222 | if ($testtodo != 0) |
223 | 223 | { |
224 | - print __METHOD__." DOL_MAIN_URL_ROOT=".DOL_MAIN_URL_ROOT."\n"; |
|
225 | - print __METHOD__." DOL_URL_ROOT=".DOL_URL_ROOT."\n"; |
|
226 | - $this->assertEquals($expectedresult, DOL_URL_ROOT); |
|
224 | + print __METHOD__." DOL_MAIN_URL_ROOT=".DOL_MAIN_URL_ROOT."\n"; |
|
225 | + print __METHOD__." DOL_URL_ROOT=".DOL_URL_ROOT."\n"; |
|
226 | + $this->assertEquals($expectedresult, DOL_URL_ROOT); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | return true; |
@@ -263,44 +263,44 @@ discard block |
||
263 | 263 | function testSqlAndScriptInject($val, $type) |
264 | 264 | { |
265 | 265 | // phpcs:enable |
266 | - $inj = 0; |
|
267 | - // For SQL Injection (only GET and POST are used to be included into bad escaped SQL requests) |
|
268 | - if ($type != 2) |
|
269 | - { |
|
270 | - $inj += preg_match('/delete\s+from/i', $val); |
|
271 | - $inj += preg_match('/create\s+table/i', $val); |
|
272 | - $inj += preg_match('/update.+set.+=/i', $val); |
|
273 | - $inj += preg_match('/insert\s+into/i', $val); |
|
274 | - $inj += preg_match('/select.+from/i', $val); |
|
275 | - $inj += preg_match('/union.+select/i', $val); |
|
276 | - $inj += preg_match('/into\s+(outfile|dumpfile)/i', $val); |
|
277 | - $inj += preg_match('/(\.\.%2f)+/i', $val); |
|
278 | - } |
|
279 | - // For XSS Injection done by adding javascript with script |
|
280 | - // This is all cases a browser consider text is javascript: |
|
281 | - // When it found '<script', 'javascript:', '<style', 'onload\s=' on body tag, '="&' on a tag size with old browsers |
|
282 | - // All examples on page: http://ha.ckers.org/xss.html#XSScalc |
|
283 | - // More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet |
|
284 | - $inj += preg_match('/<script/i', $val); |
|
285 | - $inj += preg_match('/<iframe/i', $val); |
|
286 | - $inj += preg_match('/Set\.constructor/i', $val); // ECMA script 6 |
|
287 | - if (! defined('NOSTYLECHECK')) $inj += preg_match('/<style/i', $val); |
|
288 | - $inj += preg_match('/base[\s]+href/si', $val); |
|
289 | - $inj += preg_match('/<.*onmouse/si', $val); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)> |
|
290 | - $inj += preg_match('/onerror\s*=/i', $val); // onerror can be set on img or any html tag like <img title='...' onerror = alert(1)> |
|
291 | - $inj += preg_match('/onfocus\s*=/i', $val); // onfocus can be set on input text html tag like <input type='text' value='...' onfocus = alert(1)> |
|
292 | - $inj += preg_match('/onload\s*=/i', $val); // onload can be set on svg tag <svg/onload=alert(1)> or other tag like body <body onload=alert(1)> |
|
293 | - //$inj += preg_match('/on[A-Z][a-z]+\*=/', $val); // To lock event handlers onAbort(), ... |
|
294 | - $inj += preg_match('/:|:|:/i', $val); // refused string ':' encoded (no reason to have it encoded) to lock 'javascript:...' |
|
295 | - //if ($type == 1) |
|
296 | - //{ |
|
297 | - $inj += preg_match('/javascript:/i', $val); |
|
298 | - $inj += preg_match('/vbscript:/i', $val); |
|
299 | - //} |
|
300 | - // For XSS Injection done by adding javascript closing html tags like with onmousemove, etc... (closing a src or href tag with not cleaned param) |
|
301 | - if ($type == 1) $inj += preg_match('/"/i', $val); // We refused " in GET parameters value |
|
302 | - if ($type == 2) $inj += preg_match('/[;"]/', $val); // PHP_SELF is a file system path. It can contains spaces. |
|
303 | - return $inj; |
|
266 | + $inj = 0; |
|
267 | + // For SQL Injection (only GET and POST are used to be included into bad escaped SQL requests) |
|
268 | + if ($type != 2) |
|
269 | + { |
|
270 | + $inj += preg_match('/delete\s+from/i', $val); |
|
271 | + $inj += preg_match('/create\s+table/i', $val); |
|
272 | + $inj += preg_match('/update.+set.+=/i', $val); |
|
273 | + $inj += preg_match('/insert\s+into/i', $val); |
|
274 | + $inj += preg_match('/select.+from/i', $val); |
|
275 | + $inj += preg_match('/union.+select/i', $val); |
|
276 | + $inj += preg_match('/into\s+(outfile|dumpfile)/i', $val); |
|
277 | + $inj += preg_match('/(\.\.%2f)+/i', $val); |
|
278 | + } |
|
279 | + // For XSS Injection done by adding javascript with script |
|
280 | + // This is all cases a browser consider text is javascript: |
|
281 | + // When it found '<script', 'javascript:', '<style', 'onload\s=' on body tag, '="&' on a tag size with old browsers |
|
282 | + // All examples on page: http://ha.ckers.org/xss.html#XSScalc |
|
283 | + // More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet |
|
284 | + $inj += preg_match('/<script/i', $val); |
|
285 | + $inj += preg_match('/<iframe/i', $val); |
|
286 | + $inj += preg_match('/Set\.constructor/i', $val); // ECMA script 6 |
|
287 | + if (! defined('NOSTYLECHECK')) $inj += preg_match('/<style/i', $val); |
|
288 | + $inj += preg_match('/base[\s]+href/si', $val); |
|
289 | + $inj += preg_match('/<.*onmouse/si', $val); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)> |
|
290 | + $inj += preg_match('/onerror\s*=/i', $val); // onerror can be set on img or any html tag like <img title='...' onerror = alert(1)> |
|
291 | + $inj += preg_match('/onfocus\s*=/i', $val); // onfocus can be set on input text html tag like <input type='text' value='...' onfocus = alert(1)> |
|
292 | + $inj += preg_match('/onload\s*=/i', $val); // onload can be set on svg tag <svg/onload=alert(1)> or other tag like body <body onload=alert(1)> |
|
293 | + //$inj += preg_match('/on[A-Z][a-z]+\*=/', $val); // To lock event handlers onAbort(), ... |
|
294 | + $inj += preg_match('/:|:|:/i', $val); // refused string ':' encoded (no reason to have it encoded) to lock 'javascript:...' |
|
295 | + //if ($type == 1) |
|
296 | + //{ |
|
297 | + $inj += preg_match('/javascript:/i', $val); |
|
298 | + $inj += preg_match('/vbscript:/i', $val); |
|
299 | + //} |
|
300 | + // For XSS Injection done by adding javascript closing html tags like with onmousemove, etc... (closing a src or href tag with not cleaned param) |
|
301 | + if ($type == 1) $inj += preg_match('/"/i', $val); // We refused " in GET parameters value |
|
302 | + if ($type == 2) $inj += preg_match('/[;"]/', $val); // PHP_SELF is a file system path. It can contains spaces. |
|
303 | + return $inj; |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | // Run tests |
@@ -340,12 +340,12 @@ discard block |
||
340 | 340 | $test='<IMG SRC=/ onerror="alert(1)">'; |
341 | 341 | $result=testSqlAndScriptInject($test, 0); |
342 | 342 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa6'); |
343 | - $test='<IMG SRC="  javascript:alert(1);">'; |
|
344 | - $result=testSqlAndScriptInject($test, 0); |
|
345 | - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa7'); |
|
343 | + $test='<IMG SRC="  javascript:alert(1);">'; |
|
344 | + $result=testSqlAndScriptInject($test, 0); |
|
345 | + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa7'); |
|
346 | 346 | |
347 | - $test='<IMG SRC=javascript:alert('XSS')>'; |
|
348 | - $result=testSqlAndScriptInject($test, 0); |
|
347 | + $test='<IMG SRC=javascript:alert('XSS')>'; |
|
348 | + $result=testSqlAndScriptInject($test, 0); |
|
349 | 349 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject bbb'); |
350 | 350 | |
351 | 351 | $test='<SCRIPT SRC=http://xss.rocks/xss.js></SCRIPT>'; |
@@ -375,26 +375,26 @@ discard block |
||
375 | 375 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee'); |
376 | 376 | |
377 | 377 | $test="<IMG SRC=\"jav\tascript:alert('XSS');\">"; // Is locked by some brwoser like chrome because the default directive no-referrer-when-downgrade is sent when requesting the SRC and then refused because of browser protection on img src load without referrer. |
378 | - $test="<IMG SRC=\"jav
ascript:alert('XSS');\">"; // Same |
|
379 | - |
|
380 | - $test='<SCRIPT/XSS SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
381 | - $result=testSqlAndScriptInject($test, 0); |
|
382 | - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff1'); |
|
383 | - $test='<SCRIPT/SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
384 | - $result=testSqlAndScriptInject($test, 0); |
|
385 | - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff2'); |
|
386 | - |
|
387 | - // This case seems to be filtered by browsers now. |
|
388 | - $test='<BODY onload!#$%&()*~+-_.,:;?@[/|\]^`=alert(1)>'; |
|
389 | - //$result=testSqlAndScriptInject($test, 0); |
|
390 | - //$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ggg'); |
|
391 | - |
|
392 | - $test='<iframe src=http://xss.rocks/scriptlet.html <'; |
|
393 | - $result=testSqlAndScriptInject($test, 0); |
|
394 | - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject hhh'); |
|
395 | - |
|
396 | - $test='Set.constructor`alert\x281\x29```'; |
|
397 | - $result=testSqlAndScriptInject($test, 0); |
|
398 | - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject iii'); |
|
378 | + $test="<IMG SRC=\"jav
ascript:alert('XSS');\">"; // Same |
|
379 | + |
|
380 | + $test='<SCRIPT/XSS SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
381 | + $result=testSqlAndScriptInject($test, 0); |
|
382 | + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff1'); |
|
383 | + $test='<SCRIPT/SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
384 | + $result=testSqlAndScriptInject($test, 0); |
|
385 | + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff2'); |
|
386 | + |
|
387 | + // This case seems to be filtered by browsers now. |
|
388 | + $test='<BODY onload!#$%&()*~+-_.,:;?@[/|\]^`=alert(1)>'; |
|
389 | + //$result=testSqlAndScriptInject($test, 0); |
|
390 | + //$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ggg'); |
|
391 | + |
|
392 | + $test='<iframe src=http://xss.rocks/scriptlet.html <'; |
|
393 | + $result=testSqlAndScriptInject($test, 0); |
|
394 | + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject hhh'); |
|
395 | + |
|
396 | + $test='Set.constructor`alert\x281\x29```'; |
|
397 | + $result=testSqlAndScriptInject($test, 0); |
|
398 | + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject iii'); |
|
399 | 399 | } |
400 | 400 | } |
@@ -23,21 +23,21 @@ discard block |
||
23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
24 | 24 | */ |
25 | 25 | |
26 | -global $conf,$user,$langs,$db; |
|
26 | +global $conf, $user, $langs, $db; |
|
27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
29 | 29 | //require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
30 | 30 | |
31 | -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); |
|
32 | -if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); |
|
33 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
34 | -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); |
|
35 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); |
|
36 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); |
|
37 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show |
|
38 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php |
|
39 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
40 | -if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) |
|
31 | +if (!defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); |
|
32 | +if (!defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); |
|
33 | +if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); |
|
34 | +if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); |
|
35 | +if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); |
|
36 | +if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); |
|
37 | +if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show |
|
38 | +if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php |
|
39 | +if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); |
|
40 | +if (!defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
41 | 41 | |
42 | 42 | |
43 | 43 | /** |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | parent::__construct(); |
66 | 66 | |
67 | 67 | //$this->sharedFixture |
68 | - global $conf,$user,$langs,$db; |
|
69 | - $this->savconf=$conf; |
|
70 | - $this->savuser=$user; |
|
71 | - $this->savlangs=$langs; |
|
72 | - $this->savdb=$db; |
|
68 | + global $conf, $user, $langs, $db; |
|
69 | + $this->savconf = $conf; |
|
70 | + $this->savuser = $user; |
|
71 | + $this->savlangs = $langs; |
|
72 | + $this->savdb = $db; |
|
73 | 73 | |
74 | 74 | //print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
75 | 75 | //print " - db ".$db->db; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | // Static methods |
80 | 80 | public static function setUpBeforeClass() |
81 | 81 | { |
82 | - global $conf,$user,$langs,$db; |
|
82 | + global $conf, $user, $langs, $db; |
|
83 | 83 | //$db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
84 | 84 | |
85 | 85 | print __METHOD__."\n"; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | // tear down after class |
89 | 89 | public static function tearDownAfterClass() |
90 | 90 | { |
91 | - global $conf,$user,$langs,$db; |
|
91 | + global $conf, $user, $langs, $db; |
|
92 | 92 | //$db->rollback(); |
93 | 93 | |
94 | 94 | print __METHOD__."\n"; |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | */ |
102 | 102 | protected function setUp() |
103 | 103 | { |
104 | - global $conf,$user,$langs,$db; |
|
105 | - $conf=$this->savconf; |
|
106 | - $user=$this->savuser; |
|
107 | - $langs=$this->savlangs; |
|
108 | - $db=$this->savdb; |
|
104 | + global $conf, $user, $langs, $db; |
|
105 | + $conf = $this->savconf; |
|
106 | + $user = $this->savuser; |
|
107 | + $langs = $this->savlangs; |
|
108 | + $db = $this->savdb; |
|
109 | 109 | |
110 | 110 | print __METHOD__."\n"; |
111 | 111 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | global $dolibarr_main_db_type; |
140 | 140 | global $dolibarr_main_db_prefix; |
141 | 141 | |
142 | - $testtodo=0; |
|
142 | + $testtodo = 0; |
|
143 | 143 | |
144 | 144 | // Case 1: |
145 | 145 | // Test for subdir dolibarrnew (that point to htdocs) in root directory /var/www |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | // - Create link from htdocs to /var/www/dolibarrnew |
149 | 149 | // - Put into conf.php $dolibarr_main_document_root='/var/www/dolibarrnew'; |
150 | 150 | if ($testtodo == 1) { |
151 | - $_SERVER["HTTPS"]=''; |
|
152 | - $_SERVER["SERVER_NAME"]='localhost'; |
|
153 | - $_SERVER["SERVER_PORT"]='80'; |
|
154 | - $_SERVER["DOCUMENT_ROOT"]='/var/www'; |
|
155 | - $_SERVER["SCRIPT_NAME"]='/dolibarrnew/admin/system/phpinfo.php'; |
|
156 | - $expectedresult='/dolibarrnew'; |
|
151 | + $_SERVER["HTTPS"] = ''; |
|
152 | + $_SERVER["SERVER_NAME"] = 'localhost'; |
|
153 | + $_SERVER["SERVER_PORT"] = '80'; |
|
154 | + $_SERVER["DOCUMENT_ROOT"] = '/var/www'; |
|
155 | + $_SERVER["SCRIPT_NAME"] = '/dolibarrnew/admin/system/phpinfo.php'; |
|
156 | + $expectedresult = '/dolibarrnew'; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | // Case 2: |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | // - Create link from dolibarr to /var/www/aaa |
164 | 164 | // - Put into conf.php $dolibarr_main_document_root='/var/www/aaa/htdocs'; |
165 | 165 | if ($testtodo == 2) { |
166 | - $_SERVER["HTTPS"]=''; |
|
167 | - $_SERVER["SERVER_NAME"]='localhost'; |
|
168 | - $_SERVER["SERVER_PORT"]='80'; |
|
169 | - $_SERVER["DOCUMENT_ROOT"]='/var/www'; |
|
170 | - $_SERVER["SCRIPT_NAME"]='/aaa/htdocs/admin/system/phpinfo.php'; |
|
171 | - $expectedresult='/aaa/htdocs'; |
|
166 | + $_SERVER["HTTPS"] = ''; |
|
167 | + $_SERVER["SERVER_NAME"] = 'localhost'; |
|
168 | + $_SERVER["SERVER_PORT"] = '80'; |
|
169 | + $_SERVER["DOCUMENT_ROOT"] = '/var/www'; |
|
170 | + $_SERVER["SCRIPT_NAME"] = '/aaa/htdocs/admin/system/phpinfo.php'; |
|
171 | + $expectedresult = '/aaa/htdocs'; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // Case 3: |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | // - Create virtual host localhostdolibarrnew that point to /home/ldestailleur/git/dolibarr/htdocs |
180 | 180 | // - Put into conf.php $dolibarr_main_document_root='/home/ldestailleur/git/dolibarr/htdocs'; |
181 | 181 | if ($testtodo == 3) { |
182 | - $_SERVER["HTTPS"]=''; |
|
183 | - $_SERVER["SERVER_NAME"]='localhostdolibarrnew'; |
|
184 | - $_SERVER["SERVER_PORT"]='80'; |
|
185 | - $_SERVER["DOCUMENT_ROOT"]='/home/ldestailleur/git/dolibarr/htdocs'; |
|
186 | - $_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php'; |
|
187 | - $expectedresult=''; |
|
182 | + $_SERVER["HTTPS"] = ''; |
|
183 | + $_SERVER["SERVER_NAME"] = 'localhostdolibarrnew'; |
|
184 | + $_SERVER["SERVER_PORT"] = '80'; |
|
185 | + $_SERVER["DOCUMENT_ROOT"] = '/home/ldestailleur/git/dolibarr/htdocs'; |
|
186 | + $_SERVER["SCRIPT_NAME"] = '/admin/system/phpinfo.php'; |
|
187 | + $expectedresult = ''; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | // Case 4: |
@@ -192,12 +192,12 @@ discard block |
||
192 | 192 | // a symbolic link |
193 | 193 | // URL: http://localhostdolibarrnew/admin/system/phpinfo.php |
194 | 194 | if ($testtodo == 4) { |
195 | - $_SERVER["HTTPS"]=''; |
|
196 | - $_SERVER["SERVER_NAME"]='localhostdolibarrnew'; |
|
197 | - $_SERVER["SERVER_PORT"]='80'; |
|
198 | - $_SERVER["DOCUMENT_ROOT"]='/var/www/dolibarr'; // This is a link that point to /home/ldestail/workspace/dolibarr/htdocs |
|
199 | - $_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php'; |
|
200 | - $expectedresult=''; |
|
195 | + $_SERVER["HTTPS"] = ''; |
|
196 | + $_SERVER["SERVER_NAME"] = 'localhostdolibarrnew'; |
|
197 | + $_SERVER["SERVER_PORT"] = '80'; |
|
198 | + $_SERVER["DOCUMENT_ROOT"] = '/var/www/dolibarr'; // This is a link that point to /home/ldestail/workspace/dolibarr/htdocs |
|
199 | + $_SERVER["SCRIPT_NAME"] = '/admin/system/phpinfo.php'; |
|
200 | + $expectedresult = ''; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | // Case 5: |
@@ -208,12 +208,12 @@ discard block |
||
208 | 208 | // - Put into conf.php $dolibarr_main_document_root='/var/www/dolibarr/htdocs'; |
209 | 209 | // - Put into conf.php $dolibarr_main_url_root='http://localhost/dolibarralias'; (because autodetect will fails in this case) |
210 | 210 | if ($testtodo == 5) { |
211 | - $_SERVER["HTTPS"]=''; |
|
212 | - $_SERVER["SERVER_NAME"]='localhost'; |
|
213 | - $_SERVER["SERVER_PORT"]='80'; |
|
214 | - $_SERVER["DOCUMENT_ROOT"]='/var/www'; |
|
215 | - $_SERVER["SCRIPT_NAME"]='/dolibarralias/admin/system/phpinfo.php'; |
|
216 | - $expectedresult='/dolibarralias'; |
|
211 | + $_SERVER["HTTPS"] = ''; |
|
212 | + $_SERVER["SERVER_NAME"] = 'localhost'; |
|
213 | + $_SERVER["SERVER_PORT"] = '80'; |
|
214 | + $_SERVER["DOCUMENT_ROOT"] = '/var/www'; |
|
215 | + $_SERVER["SCRIPT_NAME"] = '/dolibarralias/admin/system/phpinfo.php'; |
|
216 | + $expectedresult = '/dolibarralias'; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | // Force to rerun filefunc.inc.php |
@@ -283,23 +283,23 @@ discard block |
||
283 | 283 | // More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet |
284 | 284 | $inj += preg_match('/<script/i', $val); |
285 | 285 | $inj += preg_match('/<iframe/i', $val); |
286 | - $inj += preg_match('/Set\.constructor/i', $val); // ECMA script 6 |
|
287 | - if (! defined('NOSTYLECHECK')) $inj += preg_match('/<style/i', $val); |
|
286 | + $inj += preg_match('/Set\.constructor/i', $val); // ECMA script 6 |
|
287 | + if (!defined('NOSTYLECHECK')) $inj += preg_match('/<style/i', $val); |
|
288 | 288 | $inj += preg_match('/base[\s]+href/si', $val); |
289 | - $inj += preg_match('/<.*onmouse/si', $val); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)> |
|
290 | - $inj += preg_match('/onerror\s*=/i', $val); // onerror can be set on img or any html tag like <img title='...' onerror = alert(1)> |
|
291 | - $inj += preg_match('/onfocus\s*=/i', $val); // onfocus can be set on input text html tag like <input type='text' value='...' onfocus = alert(1)> |
|
292 | - $inj += preg_match('/onload\s*=/i', $val); // onload can be set on svg tag <svg/onload=alert(1)> or other tag like body <body onload=alert(1)> |
|
289 | + $inj += preg_match('/<.*onmouse/si', $val); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)> |
|
290 | + $inj += preg_match('/onerror\s*=/i', $val); // onerror can be set on img or any html tag like <img title='...' onerror = alert(1)> |
|
291 | + $inj += preg_match('/onfocus\s*=/i', $val); // onfocus can be set on input text html tag like <input type='text' value='...' onfocus = alert(1)> |
|
292 | + $inj += preg_match('/onload\s*=/i', $val); // onload can be set on svg tag <svg/onload=alert(1)> or other tag like body <body onload=alert(1)> |
|
293 | 293 | //$inj += preg_match('/on[A-Z][a-z]+\*=/', $val); // To lock event handlers onAbort(), ... |
294 | - $inj += preg_match('/:|:|:/i', $val); // refused string ':' encoded (no reason to have it encoded) to lock 'javascript:...' |
|
294 | + $inj += preg_match('/:|:|:/i', $val); // refused string ':' encoded (no reason to have it encoded) to lock 'javascript:...' |
|
295 | 295 | //if ($type == 1) |
296 | 296 | //{ |
297 | 297 | $inj += preg_match('/javascript:/i', $val); |
298 | 298 | $inj += preg_match('/vbscript:/i', $val); |
299 | 299 | //} |
300 | 300 | // For XSS Injection done by adding javascript closing html tags like with onmousemove, etc... (closing a src or href tag with not cleaned param) |
301 | - if ($type == 1) $inj += preg_match('/"/i', $val); // We refused " in GET parameters value |
|
302 | - if ($type == 2) $inj += preg_match('/[;"]/', $val); // PHP_SELF is a file system path. It can contains spaces. |
|
301 | + if ($type == 1) $inj += preg_match('/"/i', $val); // We refused " in GET parameters value |
|
302 | + if ($type == 2) $inj += preg_match('/[;"]/', $val); // PHP_SELF is a file system path. It can contains spaces. |
|
303 | 303 | return $inj; |
304 | 304 | } |
305 | 305 | |
@@ -307,60 +307,60 @@ discard block |
||
307 | 307 | // More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet |
308 | 308 | |
309 | 309 | // Should be OK |
310 | - $expectedresult=0; |
|
310 | + $expectedresult = 0; |
|
311 | 311 | |
312 | - $_SERVER["PHP_SELF"]='/DIR WITH SPACE/htdocs/admin/index.php?mainmenu=home&leftmenu=setup&username=weservices'; |
|
313 | - $result=testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); |
|
312 | + $_SERVER["PHP_SELF"] = '/DIR WITH SPACE/htdocs/admin/index.php?mainmenu=home&leftmenu=setup&username=weservices'; |
|
313 | + $result = testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); |
|
314 | 314 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject 1a'); |
315 | 315 | |
316 | 316 | // Should detect XSS |
317 | - $expectedresult=1; |
|
317 | + $expectedresult = 1; |
|
318 | 318 | |
319 | - $_SERVER["PHP_SELF"]='/DIR WITH SPACE/htdocs/admin/index.php?mainmenu=home&leftmenu=setup&username=weservices;badaction'; |
|
320 | - $result=testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); |
|
319 | + $_SERVER["PHP_SELF"] = '/DIR WITH SPACE/htdocs/admin/index.php?mainmenu=home&leftmenu=setup&username=weservices;badaction'; |
|
320 | + $result = testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); |
|
321 | 321 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject 1b'); |
322 | 322 | |
323 | - $test="<img src='1.jpg' onerror =javascript:alert('XSS')>"; |
|
324 | - $result=testSqlAndScriptInject($test, 0); |
|
323 | + $test = "<img src='1.jpg' onerror =javascript:alert('XSS')>"; |
|
324 | + $result = testSqlAndScriptInject($test, 0); |
|
325 | 325 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa'); |
326 | 326 | |
327 | - $test="<img src='1.jpg' onerror =javascript:alert('XSS')>"; |
|
328 | - $result=testSqlAndScriptInject($test, 2); |
|
327 | + $test = "<img src='1.jpg' onerror =javascript:alert('XSS')>"; |
|
328 | + $result = testSqlAndScriptInject($test, 2); |
|
329 | 329 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa2'); |
330 | 330 | |
331 | - $test='<IMG SRC=# onmouseover="alert(1)">'; |
|
332 | - $result=testSqlAndScriptInject($test, 0); |
|
331 | + $test = '<IMG SRC=# onmouseover="alert(1)">'; |
|
332 | + $result = testSqlAndScriptInject($test, 0); |
|
333 | 333 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa3'); |
334 | - $test='<IMG SRC onmouseover="alert(1)">'; |
|
335 | - $result=testSqlAndScriptInject($test, 0); |
|
334 | + $test = '<IMG SRC onmouseover="alert(1)">'; |
|
335 | + $result = testSqlAndScriptInject($test, 0); |
|
336 | 336 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa4'); |
337 | - $test='<IMG onmouseover="alert(1)">'; |
|
338 | - $result=testSqlAndScriptInject($test, 0); |
|
337 | + $test = '<IMG onmouseover="alert(1)">'; |
|
338 | + $result = testSqlAndScriptInject($test, 0); |
|
339 | 339 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa5'); |
340 | - $test='<IMG SRC=/ onerror="alert(1)">'; |
|
341 | - $result=testSqlAndScriptInject($test, 0); |
|
340 | + $test = '<IMG SRC=/ onerror="alert(1)">'; |
|
341 | + $result = testSqlAndScriptInject($test, 0); |
|
342 | 342 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa6'); |
343 | - $test='<IMG SRC="  javascript:alert(1);">'; |
|
344 | - $result=testSqlAndScriptInject($test, 0); |
|
343 | + $test = '<IMG SRC="  javascript:alert(1);">'; |
|
344 | + $result = testSqlAndScriptInject($test, 0); |
|
345 | 345 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa7'); |
346 | 346 | |
347 | - $test='<IMG SRC=javascript:alert('XSS')>'; |
|
348 | - $result=testSqlAndScriptInject($test, 0); |
|
347 | + $test = '<IMG SRC=javascript:alert('XSS')>'; |
|
348 | + $result = testSqlAndScriptInject($test, 0); |
|
349 | 349 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject bbb'); |
350 | 350 | |
351 | - $test='<SCRIPT SRC=http://xss.rocks/xss.js></SCRIPT>'; |
|
352 | - $result=testSqlAndScriptInject($test, 0); |
|
351 | + $test = '<SCRIPT SRC=http://xss.rocks/xss.js></SCRIPT>'; |
|
352 | + $result = testSqlAndScriptInject($test, 0); |
|
353 | 353 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ccc'); |
354 | 354 | |
355 | - $test='<IMG SRC="javascript:alert(\'XSS\');">'; |
|
356 | - $result=testSqlAndScriptInject($test, 1); |
|
355 | + $test = '<IMG SRC="javascript:alert(\'XSS\');">'; |
|
356 | + $result = testSqlAndScriptInject($test, 1); |
|
357 | 357 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ddd'); |
358 | 358 | |
359 | - $test='<IMG """><SCRIPT>alert("XSS")</SCRIPT>">'; |
|
360 | - $result=testSqlAndScriptInject($test, 0); |
|
359 | + $test = '<IMG """><SCRIPT>alert("XSS")</SCRIPT>">'; |
|
360 | + $result = testSqlAndScriptInject($test, 0); |
|
361 | 361 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee'); |
362 | 362 | |
363 | - $test='<!-- Google analytics --> |
|
363 | + $test = '<!-- Google analytics --> |
|
364 | 364 | <script> |
365 | 365 | (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){ |
366 | 366 | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
@@ -371,30 +371,30 @@ discard block |
||
371 | 371 | ga(\'send\', \'pageview\'); |
372 | 372 | |
373 | 373 | </script>'; |
374 | - $result=testSqlAndScriptInject($test, 0); |
|
374 | + $result = testSqlAndScriptInject($test, 0); |
|
375 | 375 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee'); |
376 | 376 | |
377 | - $test="<IMG SRC=\"jav\tascript:alert('XSS');\">"; // Is locked by some brwoser like chrome because the default directive no-referrer-when-downgrade is sent when requesting the SRC and then refused because of browser protection on img src load without referrer. |
|
378 | - $test="<IMG SRC=\"jav
ascript:alert('XSS');\">"; // Same |
|
377 | + $test = "<IMG SRC=\"jav\tascript:alert('XSS');\">"; // Is locked by some brwoser like chrome because the default directive no-referrer-when-downgrade is sent when requesting the SRC and then refused because of browser protection on img src load without referrer. |
|
378 | + $test = "<IMG SRC=\"jav
ascript:alert('XSS');\">"; // Same |
|
379 | 379 | |
380 | - $test='<SCRIPT/XSS SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
381 | - $result=testSqlAndScriptInject($test, 0); |
|
380 | + $test = '<SCRIPT/XSS SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
381 | + $result = testSqlAndScriptInject($test, 0); |
|
382 | 382 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff1'); |
383 | - $test='<SCRIPT/SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
384 | - $result=testSqlAndScriptInject($test, 0); |
|
383 | + $test = '<SCRIPT/SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
384 | + $result = testSqlAndScriptInject($test, 0); |
|
385 | 385 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff2'); |
386 | 386 | |
387 | 387 | // This case seems to be filtered by browsers now. |
388 | - $test='<BODY onload!#$%&()*~+-_.,:;?@[/|\]^`=alert(1)>'; |
|
388 | + $test = '<BODY onload!#$%&()*~+-_.,:;?@[/|\]^`=alert(1)>'; |
|
389 | 389 | //$result=testSqlAndScriptInject($test, 0); |
390 | 390 | //$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ggg'); |
391 | 391 | |
392 | - $test='<iframe src=http://xss.rocks/scriptlet.html <'; |
|
393 | - $result=testSqlAndScriptInject($test, 0); |
|
392 | + $test = '<iframe src=http://xss.rocks/scriptlet.html <'; |
|
393 | + $result = testSqlAndScriptInject($test, 0); |
|
394 | 394 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject hhh'); |
395 | 395 | |
396 | - $test='Set.constructor`alert\x281\x29```'; |
|
397 | - $result=testSqlAndScriptInject($test, 0); |
|
396 | + $test = 'Set.constructor`alert\x281\x29```'; |
|
397 | + $result = testSqlAndScriptInject($test, 0); |
|
398 | 398 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject iii'); |
399 | 399 | } |
400 | 400 | } |
@@ -28,16 +28,39 @@ discard block |
||
28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
29 | 29 | //require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
30 | 30 | |
31 | -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); |
|
32 | -if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); |
|
33 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
34 | -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); |
|
35 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); |
|
36 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); |
|
37 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show |
|
38 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php |
|
39 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
40 | -if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) |
|
31 | +if (! defined('NOREQUIREUSER')) { |
|
32 | + define('NOREQUIREUSER','1'); |
|
33 | +} |
|
34 | +if (! defined('NOREQUIREDB')) { |
|
35 | + define('NOREQUIREDB','1'); |
|
36 | +} |
|
37 | +if (! defined('NOREQUIRESOC')) { |
|
38 | + define('NOREQUIRESOC','1'); |
|
39 | +} |
|
40 | +if (! defined('NOREQUIRETRAN')) { |
|
41 | + define('NOREQUIRETRAN','1'); |
|
42 | +} |
|
43 | +if (! defined('NOCSRFCHECK')) { |
|
44 | + define('NOCSRFCHECK','1'); |
|
45 | +} |
|
46 | +if (! defined('NOTOKENRENEWAL')) { |
|
47 | + define('NOTOKENRENEWAL','1'); |
|
48 | +} |
|
49 | +if (! defined('NOREQUIREMENU')) { |
|
50 | + define('NOREQUIREMENU','1'); |
|
51 | +} |
|
52 | +// If there is no menu to show |
|
53 | +if (! defined('NOREQUIREHTML')) { |
|
54 | + define('NOREQUIREHTML','1'); |
|
55 | +} |
|
56 | +// If we don't need to load the html.form.class.php |
|
57 | +if (! defined('NOREQUIREAJAX')) { |
|
58 | + define('NOREQUIREAJAX','1'); |
|
59 | +} |
|
60 | +if (! defined("NOLOGIN")) { |
|
61 | + define("NOLOGIN",'1'); |
|
62 | +} |
|
63 | +// If this page is public (can be called outside logged session) |
|
41 | 64 | |
42 | 65 | |
43 | 66 | /** |
@@ -284,7 +307,9 @@ discard block |
||
284 | 307 | $inj += preg_match('/<script/i', $val); |
285 | 308 | $inj += preg_match('/<iframe/i', $val); |
286 | 309 | $inj += preg_match('/Set\.constructor/i', $val); // ECMA script 6 |
287 | - if (! defined('NOSTYLECHECK')) $inj += preg_match('/<style/i', $val); |
|
310 | + if (! defined('NOSTYLECHECK')) { |
|
311 | + $inj += preg_match('/<style/i', $val); |
|
312 | + } |
|
288 | 313 | $inj += preg_match('/base[\s]+href/si', $val); |
289 | 314 | $inj += preg_match('/<.*onmouse/si', $val); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)> |
290 | 315 | $inj += preg_match('/onerror\s*=/i', $val); // onerror can be set on img or any html tag like <img title='...' onerror = alert(1)> |
@@ -298,8 +323,14 @@ discard block |
||
298 | 323 | $inj += preg_match('/vbscript:/i', $val); |
299 | 324 | //} |
300 | 325 | // For XSS Injection done by adding javascript closing html tags like with onmousemove, etc... (closing a src or href tag with not cleaned param) |
301 | - if ($type == 1) $inj += preg_match('/"/i', $val); // We refused " in GET parameters value |
|
302 | - if ($type == 2) $inj += preg_match('/[;"]/', $val); // PHP_SELF is a file system path. It can contains spaces. |
|
326 | + if ($type == 1) { |
|
327 | + $inj += preg_match('/"/i', $val); |
|
328 | + } |
|
329 | + // We refused " in GET parameters value |
|
330 | + if ($type == 2) { |
|
331 | + $inj += preg_match('/[;"]/', $val); |
|
332 | + } |
|
333 | + // PHP_SELF is a file system path. It can contains spaces. |
|
303 | 334 | return $inj; |
304 | 335 | } |
305 | 336 |