From 528c79c1aa9e351e21245f5eabe16429c608cce3 Mon Sep 17 00:00:00 2001 From: kiswa Date: Sat, 7 May 2016 11:55:35 +0000 Subject: [PATCH] API WIP commit --- src/api/controllers/AutoActions.php | 19 +++++++++++++++++++ src/api/controllers/Boards.php | 3 ++- src/api/models/AutoAction.php | 16 +++++++++++++++- test/api/controllers/AutoActionsTest.php | 23 +++++++++++++++++++++++ test/api/models/AutoActionTest.php | 12 +++++++++++- test/api/models/BoardTest.php | 1 - test/api/phpunit.xml | 2 +- 7 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 test/api/controllers/AutoActionsTest.php diff --git a/src/api/controllers/AutoActions.php b/src/api/controllers/AutoActions.php index e41008f..1a5ca67 100644 --- a/src/api/controllers/AutoActions.php +++ b/src/api/controllers/AutoActions.php @@ -2,5 +2,24 @@ use RedBeanPHP\R; class AutoActions extends BaseController { + + public function getAllActions($request, $response, $args) { + $actionBeans = R::findAll('auto_action'); + + if(count($actionBeans)) { + $this->apiJson->setSuccess(); + + foreach($actionBeans as $bean) { + $this->apiJson->addData( + AutoAction::fromBean($this->container, $bean)); + } + } else { + $this->logger->addInfo('No automatic actions in database.'); + $this->apiJson->addAlert('info', + 'No automatic actions in database.'); + } + + return $this->jsonResponse($response); + } } diff --git a/src/api/controllers/Boards.php b/src/api/controllers/Boards.php index 1c5c3f6..d219ab7 100644 --- a/src/api/controllers/Boards.php +++ b/src/api/controllers/Boards.php @@ -10,7 +10,8 @@ class Boards extends BaseController { $this->apiJson->setSuccess(); foreach($boardBeans as $bean) { - $this->apiJson->addData(Board::fromBean($this->container, $bean)); + $this->apiJson->addData( + Board::fromBean($this->container, $bean)); } } else { $this->logger->addInfo('No boards in database.'); diff --git a/src/api/models/AutoAction.php b/src/api/models/AutoAction.php index 0fbb24f..c41ae4f 100644 --- a/src/api/models/AutoAction.php +++ b/src/api/models/AutoAction.php @@ -5,6 +5,7 @@ class ActionTrigger extends Enum { const MoveToColumn = 1; const AssignedToUser = 2; const SetToCategory = 3; + const PointsChanged = 4; } class ActionType extends Enum { @@ -12,6 +13,7 @@ class ActionType extends Enum { const SetCategory = 2; const SetAssignee = 3; const ClearDueDate = 4; + const UseBaseColor = 5; } class AutoAction extends BaseModel { @@ -21,14 +23,26 @@ class AutoAction extends BaseModel { public $type; public $change_to = ''; // Whatever the target of the action changes to - public function __construct($container, $id = 0) { + public function __construct($container, $id = 0, $internal = false) { parent::__construct('auto_action', $id, $container); $this->trigger = new ActionTrigger(ActionTrigger::MoveToColumn); $this->type = new ActionType(ActionType::SetColor); + + if ($internal) { + return; + } + $this->loadFromBean($this->bean); } + public static function fromBean($container, $bean) { + $instance = new self($container, 0, true); + $instance->loadFromBean($bean); + + return $instance; + } + public function updateBean() { $bean = $this->bean; diff --git a/test/api/controllers/AutoActionsTest.php b/test/api/controllers/AutoActionsTest.php new file mode 100644 index 0000000..2e49445 --- /dev/null +++ b/test/api/controllers/AutoActionsTest.php @@ -0,0 +1,23 @@ +actions = new AutoActions(new ContainerMock()); + } + + public function testGetAllActions() { + + } +} + diff --git a/test/api/models/AutoActionTest.php b/test/api/models/AutoActionTest.php index a9b19d9..4d72455 100644 --- a/test/api/models/AutoActionTest.php +++ b/test/api/models/AutoActionTest.php @@ -23,11 +23,21 @@ class AutoActionTest extends PHPUnit_Framework_TestCase { $this->bean = $action; } - public function testCreateAttachment() { + public function testCreateNewAutoAction() { $action = new AutoAction(new ContainerMock()); $this->assertDefaultProperties($action); } + public function testCreateFromBean() { + $action = AutoAction::fromBean(new ContainerMock, null); + + $this->assertDefaultProperties($action); + + $action = AutoAction::fromBean(new ContainerMock(), $this->bean); + + $this->assertTrue($action->id === 1); + } + public function testLoadFromJson() { $action = new AutoAction(new ContainerMock()); diff --git a/test/api/models/BoardTest.php b/test/api/models/BoardTest.php index 0f322d7..dadca2c 100644 --- a/test/api/models/BoardTest.php +++ b/test/api/models/BoardTest.php @@ -49,7 +49,6 @@ class BoardTest extends PHPUnit_Framework_TestCase { public function testCreateNewBoard() { $board = new Board(new ContainerMock()); - $this->assertDefaultProperties($board); } diff --git a/test/api/phpunit.xml b/test/api/phpunit.xml index 0722f8f..49366e3 100644 --- a/test/api/phpunit.xml +++ b/test/api/phpunit.xml @@ -11,7 +11,7 @@ -