mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Minor fixes for template
This commit is contained in:
parent
5cbf8abae2
commit
91a36e3d0e
@ -54,6 +54,19 @@ class DesignFilters extends QueryFilters
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
||||
public function entities(string $entities = ''): Builder
|
||||
{
|
||||
|
||||
if (strlen($entities) == 0 || str_contains($entities, ',')) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder
|
||||
->where('is_template', true)
|
||||
->whereRaw('FIND_IN_SET( ? ,entities)', [trim($entities)]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the query by the users company ID.
|
||||
*
|
||||
|
@ -52,6 +52,85 @@ class DesignApiTest extends TestCase
|
||||
Model::reguard();
|
||||
}
|
||||
|
||||
public function testFindInSetQueries()
|
||||
{
|
||||
|
||||
$design = DesignFactory::create($this->company->id, $this->user->id);
|
||||
$design->is_template = true;
|
||||
$design->name = 'Test Template';
|
||||
$design->entities = 'searchable,payment,quote';
|
||||
$design->save();
|
||||
|
||||
$searchable = 'searchable';
|
||||
|
||||
$q = Design::query()
|
||||
->where('is_template', true)
|
||||
->whereRaw('FIND_IN_SET( ? ,entities)', [$searchable]);
|
||||
|
||||
$this->assertEquals(1, $q->count());
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/designs?entities=payment');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
$this->assertCount(1, $arr['data']);
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/designs?entities=,,,3,3,3,');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/designs?entities=unsearchable');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
$this->assertCount(0, $arr['data']);
|
||||
|
||||
$design = DesignFactory::create($this->company->id, $this->user->id);
|
||||
$design->is_template = true;
|
||||
$design->name = 'Test Template';
|
||||
$design->entities = 'searchable,payment,quote';
|
||||
$design->save();
|
||||
|
||||
$searchable = 'unsearchable';
|
||||
|
||||
$q = Design::query()
|
||||
->where('is_template', true)
|
||||
->whereRaw('FIND_IN_SET( ? ,entities)', [$searchable]);
|
||||
|
||||
$this->assertEquals(0, $q->count());
|
||||
|
||||
$design = DesignFactory::create($this->company->id, $this->user->id);
|
||||
$design->is_template = true;
|
||||
$design->name = 'Test Template';
|
||||
$design->entities = 'searchable,payment,quote';
|
||||
$design->save();
|
||||
|
||||
$searchable = 'searchable,payment';
|
||||
|
||||
$q = Design::query()
|
||||
->where('is_template', true)
|
||||
->whereRaw('FIND_IN_SET( ? ,entities)', [$searchable]);
|
||||
|
||||
$this->assertEquals(0, $q->count());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testDesignTemplates()
|
||||
{
|
||||
$design = DesignFactory::create($this->company->id, $this->user->id);
|
||||
|
Loading…
Reference in New Issue
Block a user