mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 01:54:36 -04:00
Tests for types
This commit is contained in:
parent
e56aac5e73
commit
859efb9445
@ -75,6 +75,7 @@ trait CompanySettingsSaver
|
|||||||
|
|
||||||
/*Catch all filter */
|
/*Catch all filter */
|
||||||
if($this->checkAttribute($value, $settings->{$key})){
|
if($this->checkAttribute($value, $settings->{$key})){
|
||||||
|
\Log::error("System says true {$key} a {$value} = ".$settings->{$key});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
unset($settings->{$key});
|
unset($settings->{$key});
|
||||||
@ -98,7 +99,7 @@ trait CompanySettingsSaver
|
|||||||
case 'real':
|
case 'real':
|
||||||
case 'float':
|
case 'float':
|
||||||
case 'double':
|
case 'double':
|
||||||
return is_float($value);
|
return is_float($value) || is_numeric(strval($value));
|
||||||
case 'string':
|
case 'string':
|
||||||
return method_exists($value, '__toString' ) || is_null($value) || is_string($value);
|
return method_exists($value, '__toString' ) || is_null($value) || is_string($value);
|
||||||
case 'bool':
|
case 'bool':
|
||||||
|
@ -65,12 +65,14 @@ class CompanySettingsTest extends TestCase
|
|||||||
$this->assertEquals($arr['data']['settings']['timezone_id'],15);
|
$this->assertEquals($arr['data']['settings']['timezone_id'],15);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSettingCasts()
|
public function testIntegerEdgeCases()
|
||||||
{
|
{
|
||||||
$settings = $this->company->settings;
|
$settings = $this->company->settings;
|
||||||
|
|
||||||
$settings->client_number_counter = "a";
|
$settings->client_number_counter = "a";
|
||||||
$settings->invoice_number_counter = 1000;
|
$settings->invoice_number_counter = 1000;
|
||||||
|
$settings->quote_number_counter = 1.2;
|
||||||
|
$settings->credit_number_counter = 10.1;
|
||||||
|
|
||||||
$this->company->settings = $settings;
|
$this->company->settings = $settings;
|
||||||
|
|
||||||
@ -82,9 +84,38 @@ class CompanySettingsTest extends TestCase
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$arr = $response->json();
|
$arr = $response->json();
|
||||||
\Log::error($arr);
|
|
||||||
|
|
||||||
$this->assertEquals($arr['data']['settings']['client_number_counter'],1);
|
$this->assertEquals($arr['data']['settings']['client_number_counter'],1);
|
||||||
|
$this->assertEquals($arr['data']['settings']['quote_number_counter'],1);
|
||||||
|
$this->assertEquals($arr['data']['settings']['credit_number_counter'],1);
|
||||||
$this->assertEquals($arr['data']['settings']['invoice_number_counter'],1000);
|
$this->assertEquals($arr['data']['settings']['invoice_number_counter'],1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFloatEdgeCases()
|
||||||
|
{
|
||||||
|
$settings = $this->company->settings;
|
||||||
|
|
||||||
|
$settings->default_task_rate = "a";
|
||||||
|
$settings->tax_rate1 = 10.0;
|
||||||
|
$settings->tax_rate2 = "10.0";
|
||||||
|
$settings->tax_rate3 = "10.5";
|
||||||
|
|
||||||
|
$this->company->settings = $settings;
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-Token' => $this->token,
|
||||||
|
])->put('/api/v1/companies/'.$this->encodePrimaryKey($this->company->id), $this->company->toArray());
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals($arr['data']['settings']['default_task_rate'],0);
|
||||||
|
$this->assertEquals($arr['data']['settings']['tax_rate1'],10.0);
|
||||||
|
$this->assertEquals($arr['data']['settings']['tax_rate2'],10.0);
|
||||||
|
$this->assertEquals($arr['data']['settings']['tax_rate3'],10.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user