diff options
author | Frédéric Guillot <fguillot@users.noreply.github.com> | 2014-03-11 21:12:53 -0400 |
---|---|---|
committer | Frédéric Guillot <fguillot@users.noreply.github.com> | 2014-03-11 21:12:53 -0400 |
commit | c0ab45110688d698c1038d203017fda2385c5142 (patch) | |
tree | 57427ded9c096d3a558980b1b32de6e1b3242b62 /actions | |
parent | 66c7cf0caa5802c825e3f511158bb719cf82cafa (diff) |
Add unit test for the "task close" action
Diffstat (limited to 'actions')
-rw-r--r-- | actions/base.php | 85 | ||||
-rw-r--r-- | actions/task_close.php | 33 |
2 files changed, 118 insertions, 0 deletions
diff --git a/actions/base.php b/actions/base.php index bb9b8bc1..13e4b6ee 100644 --- a/actions/base.php +++ b/actions/base.php @@ -2,30 +2,101 @@ namespace Action; +/** + * Base class for automatic actions + * + * @package action + * @author Frederic Guillot + */ abstract class Base implements \Core\Listener { + /** + * Project id + * + * @access private + * @var integer + */ private $project_id = 0; + + /** + * User parameters + * + * @access private + * @var array + */ private $params = array(); + /** + * Execute the action + * + * @abstract + * @access public + * @param array $data Event data dictionary + * @return bool True if the action was executed or false when not executed + */ abstract public function doAction(array $data); + + /** + * Get the required parameter for the action (defined by the user) + * + * @abstract + * @access public + * @return array + */ abstract public function getActionRequiredParameters(); + + /** + * Get the required parameter for the event (check if for the event data) + * + * @abstract + * @access public + * @return array + */ abstract public function getEventRequiredParameters(); + /** + * Constructor + * + * @access public + * @param integer $project_id Project id + */ public function __construct($project_id) { $this->project_id = $project_id; } + /** + * Set an user defined parameter + * + * @access public + * @param string $name Parameter name + * @param mixed $value Value + */ public function setParam($name, $value) { $this->params[$name] = $value; } + /** + * Get an user defined parameter + * + * @access public + * @param string $name Parameter name + * @param mixed $default_value Default value + * @return mixed + */ public function getParam($name, $default_value = null) { return isset($this->params[$name]) ? $this->params[$name] : $default_value; } + /** + * Check if an action is executable (right project and required parameters) + * + * @access public + * @param array $data Event data dictionary + * @return bool True if the action is executable + */ public function isExecutable(array $data) { if (isset($data['project_id']) && $data['project_id'] == $this->project_id && $this->hasRequiredParameters($data)) { @@ -35,6 +106,13 @@ abstract class Base implements \Core\Listener return false; } + /** + * Check if the event data has required parameters to execute the action + * + * @access public + * @param array $data Event data dictionary + * @return bool True if all keys are there + */ public function hasRequiredParameters(array $data) { foreach ($this->getEventRequiredParameters() as $parameter) { @@ -44,6 +122,13 @@ abstract class Base implements \Core\Listener return true; } + /** + * Execute the action + * + * @access public + * @param array $data Event data dictionary + * @return bool True if the action was executed or false when not executed + */ public function execute(array $data) { if ($this->isExecutable($data)) { diff --git a/actions/task_close.php b/actions/task_close.php index 4ac579c4..4d129d73 100644 --- a/actions/task_close.php +++ b/actions/task_close.php @@ -4,14 +4,33 @@ namespace Action; require_once __DIR__.'/base.php'; +/** + * Close automatically a task + * + * @package action + * @author Frederic Guillot + */ class TaskClose extends Base { + /** + * Constructor + * + * @access public + * @param integer $project_id Project id + * @param Task $task Task model instance + */ public function __construct($project_id, \Model\Task $task) { parent::__construct($project_id); $this->task = $task; } + /** + * Get the required parameter for the action (defined by the user) + * + * @access public + * @return array + */ public function getActionRequiredParameters() { return array( @@ -19,6 +38,13 @@ class TaskClose extends Base ); } + /** + * Get the required parameter for the event (check if for the event data) + * + * @abstract + * @access public + * @return array + */ public function getEventRequiredParameters() { return array( @@ -27,6 +53,13 @@ class TaskClose extends Base ); } + /** + * Execute the action + * + * @access public + * @param array $data Event data dictionary + * @return bool True if the action was executed or false when not executed + */ public function doAction(array $data) { if ($data['column_id'] == $this->getParam('column_id')) { |