Skip to content

Commit 9a118bc

Browse files
authored
Merge pull request #11 from codeccoop/feat/addons-tests
feat: odoo tests
2 parents b892b7e + 9c51c37 commit 9a118bc

File tree

3 files changed

+729
-18
lines changed

3 files changed

+729
-18
lines changed

forms-bridge/addons/odoo/class-odoo-form-bridge.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ public static function rpc_response( $res ) {
8787
}
8888

8989
if ( empty( $res['data'] ) ) {
90-
$content_type =
91-
Http_Client::get_content_type( $res['headers'] ) ?? 'undefined';
90+
$content_type = Http_Client::get_content_type( $res['headers'] ) ?? 'undefined';
9291

9392
return new WP_Error(
9493
'unkown_content_type',

forms-bridge/addons/odoo/hooks.php

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
/**
3+
* Odoo addon hooks
4+
*
5+
* @package formsbridge
6+
*/
27

38
if ( ! defined( 'ABSPATH' ) ) {
49
exit();
@@ -7,7 +12,7 @@
712
add_filter(
813
'forms_bridge_bridge_schema',
914
function ( $schema, $addon ) {
10-
if ( $addon !== 'odoo' ) {
15+
if ( 'odoo' !== $addon ) {
1116
return $schema;
1217
}
1318

@@ -45,7 +50,7 @@ function ( $schema, $addon ) {
4550
add_filter(
4651
'forms_bridge_template_defaults',
4752
function ( $defaults, $addon, $schema ) {
48-
if ( $addon !== 'odoo' ) {
53+
if ( 'odoo' !== $addon ) {
4954
return $defaults;
5055
}
5156

@@ -150,20 +155,22 @@ function ( $defaults, $addon, $schema ) {
150155
add_filter(
151156
'forms_bridge_template_data',
152157
function ( $data, $template_id ) {
153-
if ( strpos( $template_id, 'odoo-' ) !== 0 ) {
158+
if ( 0 !== strpos( $template_id, 'odoo-' ) ) {
154159
return $data;
155160
}
156161

157162
$index = array_search(
158163
'tag_ids',
159-
array_column( $data['bridge']['custom_fields'], 'name' )
164+
array_column( $data['bridge']['custom_fields'], 'name' ),
165+
true
160166
);
161167

162-
if ( $index !== false ) {
168+
if ( false !== $index ) {
163169
$field = $data['bridge']['custom_fields'][ $index ];
164170
$tags = $field['value'] ?? array();
165171

166-
for ( $i = 0; $i < count( $tags ); $i++ ) {
172+
$l = count( $tags );
173+
for ( $i = 0; $i < $l; $i++ ) {
167174
$data['bridge']['custom_fields'][] = array(
168175
'name' => "tag_ids[{$i}]",
169176
'value' => $tags[ $i ],
@@ -181,14 +188,16 @@ function ( $data, $template_id ) {
181188

182189
$index = array_search(
183190
'categ_ids',
184-
array_column( $data['bridge']['custom_fields'], 'name' )
191+
array_column( $data['bridge']['custom_fields'], 'name' ),
192+
true
185193
);
186194

187-
if ( $index !== false ) {
195+
if ( false !== $index ) {
188196
$field = $data['bridge']['custom_fields'][ $index ];
189197
$tags = $field['value'] ?? array();
190198

191-
for ( $i = 0; $i < count( $tags ); $i++ ) {
199+
$l = count( $tags );
200+
for ( $i = 0; $i < $l; $i++ ) {
192201
$data['bridge']['custom_fields'][] = array(
193202
'name' => "categ_ids[{$i}]",
194203
'value' => $tags[ $i ],
@@ -206,14 +215,16 @@ function ( $data, $template_id ) {
206215

207216
$index = array_search(
208217
'list_ids',
209-
array_column( $data['bridge']['custom_fields'], 'name' )
218+
array_column( $data['bridge']['custom_fields'], 'name' ),
219+
true
210220
);
211221

212-
if ( $index !== false ) {
222+
if ( false !== $index ) {
213223
$field = $data['bridge']['custom_fields'][ $index ];
214224
$lists = $field['value'] ?? array();
215225

216-
for ( $i = 0; $i < count( $lists ); $i++ ) {
226+
$l = count( $lists );
227+
for ( $i = 0; $i < $l; $i++ ) {
217228
$data['bridge']['custom_fields'][] = array(
218229
'name' => "list_ids[{$i}]",
219230
'value' => $lists[ $i ],
@@ -231,10 +242,11 @@ function ( $data, $template_id ) {
231242

232243
$index = array_search(
233244
'allday',
234-
array_column( $data['bridge']['custom_fields'], 'name' )
245+
array_column( $data['bridge']['custom_fields'], 'name' ),
246+
true
235247
);
236248

237-
if ( $index !== false ) {
249+
if ( false !== $index ) {
238250
$data['form']['fields'] = array_filter(
239251
$data['form']['fields'],
240252
function ( $field ) {
@@ -253,10 +265,11 @@ function ( $field ) {
253265

254266
$index = array_search(
255267
'duration',
256-
array_column( $data['bridge']['custom_fields'], 'name' )
268+
array_column( $data['bridge']['custom_fields'], 'name' ),
269+
true
257270
);
258271

259-
if ( $index !== false ) {
272+
if ( false !== $index ) {
260273
array_splice( $data['bridge']['custom_fields'], $index, 1 );
261274
}
262275
}

0 commit comments

Comments
 (0)