mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
Tests for category controller
This commit is contained in:
@@ -38,13 +38,13 @@ interface CategoryRepositoryInterface
|
||||
*/
|
||||
public function store($data);
|
||||
|
||||
public function update($data);
|
||||
public function update($category, $data);
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function destroy($categoryId);
|
||||
public function destroy($category);
|
||||
|
||||
}
|
@@ -9,19 +9,6 @@ namespace Firefly\Storage\Category;
|
||||
*/
|
||||
class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->categories()->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
public function find($categoryId)
|
||||
{
|
||||
return \Auth::user()->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
@@ -39,6 +26,18 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
public function destroy($category)
|
||||
{
|
||||
$category->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function find($categoryId)
|
||||
{
|
||||
return \Auth::user()->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
@@ -54,6 +53,14 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->categories()->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
@@ -70,29 +77,14 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
return $category;
|
||||
}
|
||||
|
||||
public function update($data)
|
||||
public function update($category, $data)
|
||||
{
|
||||
$category = $this->find($data['id']);
|
||||
if ($category) {
|
||||
// update account accordingly:
|
||||
$category->name = $data['name'];
|
||||
if ($category->validate()) {
|
||||
$category->save();
|
||||
}
|
||||
// update account accordingly:
|
||||
$category->name = $data['name'];
|
||||
if ($category->validate()) {
|
||||
$category->save();
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
public function destroy($categoryId)
|
||||
{
|
||||
$category = $this->find($categoryId);
|
||||
if ($category) {
|
||||
$category->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user