Skip to content

Commit

Permalink
Fix creating new categories
Browse files Browse the repository at this point in the history
Fixes #24
  • Loading branch information
AJenbo committed Apr 2, 2018
1 parent 0314669 commit 9f3c950
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function create(Request $request): JsonResponse
throw new InvalidInput(_('You must enter a title and choose a location for the new category.'));
}

$icon = app('orm')->getOne(File::class, $iconId);
$icon = $iconId ? app('orm')->getOne(File::class, $iconId) : null;
$parent = app('orm')->getOne(Category::class, $parentId);

$category = new Category([
Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/Http/Controllers/Admin/CategoryControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ public function testCreate(): void
);
}

public function testCreateNoIcon(): void
{
$data = [
'title' => 'New title',
'parentId' => -1,
'render_mode' => 2,
'email' => '[email protected]',
'icon_id' => null,
];

$this->json('POST', '/admin/categories/', $data)
->assertResponseStatus(200);

$this->assertDatabaseHas(
'kat',
[
'navn' => $data['title'],
'bind' => $data['parentId'],
'vis' => $data['render_mode'],
'email' => $data['email'],
'icon_id' => $data['icon_id'],
]
);
}

public function testCreateNoTitle(): void
{
$data = [
Expand Down
5 changes: 5 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ private function isInDatabase(string $table, array $data): bool
{
$sets = [];
foreach ($data as $filedName => $value) {
if ($value === null) {
$sets[] = '`' . $filedName . '` IS NULL';
continue;
}

$sets[] = '`' . $filedName . '` = ' . app('db')->quote($value);
}
$query = 'SELECT * FROM `' . $table . '` WHERE ' . implode(' AND ', $sets);
Expand Down

0 comments on commit 9f3c950

Please sign in to comment.