API WIP commit

This commit is contained in:
kiswa 2016-05-07 11:55:35 +00:00
parent e46b7e2ca7
commit 528c79c1aa
7 changed files with 71 additions and 5 deletions

View File

@ -2,5 +2,24 @@
use RedBeanPHP\R; use RedBeanPHP\R;
class AutoActions extends BaseController { 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);
}
} }

View File

@ -10,7 +10,8 @@ class Boards extends BaseController {
$this->apiJson->setSuccess(); $this->apiJson->setSuccess();
foreach($boardBeans as $bean) { foreach($boardBeans as $bean) {
$this->apiJson->addData(Board::fromBean($this->container, $bean)); $this->apiJson->addData(
Board::fromBean($this->container, $bean));
} }
} else { } else {
$this->logger->addInfo('No boards in database.'); $this->logger->addInfo('No boards in database.');

View File

@ -5,6 +5,7 @@ class ActionTrigger extends Enum {
const MoveToColumn = 1; const MoveToColumn = 1;
const AssignedToUser = 2; const AssignedToUser = 2;
const SetToCategory = 3; const SetToCategory = 3;
const PointsChanged = 4;
} }
class ActionType extends Enum { class ActionType extends Enum {
@ -12,6 +13,7 @@ class ActionType extends Enum {
const SetCategory = 2; const SetCategory = 2;
const SetAssignee = 3; const SetAssignee = 3;
const ClearDueDate = 4; const ClearDueDate = 4;
const UseBaseColor = 5;
} }
class AutoAction extends BaseModel { class AutoAction extends BaseModel {
@ -21,14 +23,26 @@ class AutoAction extends BaseModel {
public $type; public $type;
public $change_to = ''; // Whatever the target of the action changes to 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); parent::__construct('auto_action', $id, $container);
$this->trigger = new ActionTrigger(ActionTrigger::MoveToColumn); $this->trigger = new ActionTrigger(ActionTrigger::MoveToColumn);
$this->type = new ActionType(ActionType::SetColor); $this->type = new ActionType(ActionType::SetColor);
if ($internal) {
return;
}
$this->loadFromBean($this->bean); $this->loadFromBean($this->bean);
} }
public static function fromBean($container, $bean) {
$instance = new self($container, 0, true);
$instance->loadFromBean($bean);
return $instance;
}
public function updateBean() { public function updateBean() {
$bean = $this->bean; $bean = $this->bean;

View File

@ -0,0 +1,23 @@
<?php
require_once __DIR__ . '/../Mocks.php';
class AutoActionsTest extends PHPUnit_Framework_TestCase {
private $boards;
public static function setupBeforeClass() {
try {
RedBeanPHP\R::setup('sqlite:tests.db');
} catch (Exception $ex) { }
}
public function setUp() {
RedBeanPHP\R::nuke();
$this->actions = new AutoActions(new ContainerMock());
}
public function testGetAllActions() {
}
}

View File

@ -23,11 +23,21 @@ class AutoActionTest extends PHPUnit_Framework_TestCase {
$this->bean = $action; $this->bean = $action;
} }
public function testCreateAttachment() { public function testCreateNewAutoAction() {
$action = new AutoAction(new ContainerMock()); $action = new AutoAction(new ContainerMock());
$this->assertDefaultProperties($action); $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() { public function testLoadFromJson() {
$action = new AutoAction(new ContainerMock()); $action = new AutoAction(new ContainerMock());

View File

@ -49,7 +49,6 @@ class BoardTest extends PHPUnit_Framework_TestCase {
public function testCreateNewBoard() { public function testCreateNewBoard() {
$board = new Board(new ContainerMock()); $board = new Board(new ContainerMock());
$this->assertDefaultProperties($board); $this->assertDefaultProperties($board);
} }

View File

@ -11,7 +11,7 @@
</whitelist> </whitelist>
</filter> </filter>
<logging> <logging>
<log type="coverage-html" target="api-coverage/" <log type="coverage-html" target="../../api-coverage/"
lowUpperBound="40" highLowerBound="80" /> lowUpperBound="40" highLowerBound="80" />
</logging> </logging>
</phpunit> </phpunit>