API WIP commit
This commit is contained in:
parent
e46b7e2ca7
commit
528c79c1aa
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.');
|
||||
|
@ -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;
|
||||
|
||||
|
23
test/api/controllers/AutoActionsTest.php
Normal file
23
test/api/controllers/AutoActionsTest.php
Normal 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() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
||||
|
@ -49,7 +49,6 @@ class BoardTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testCreateNewBoard() {
|
||||
$board = new Board(new ContainerMock());
|
||||
|
||||
$this->assertDefaultProperties($board);
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<log type="coverage-html" target="api-coverage/"
|
||||
<log type="coverage-html" target="../../api-coverage/"
|
||||
lowUpperBound="40" highLowerBound="80" />
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
Reference in New Issue
Block a user