Skip to content
Snippets Groups Projects
Commit f5fb33f0 authored by Yorick Reum's avatar Yorick Reum
Browse files

tests, mostly behat, phphunit started...

parent d7f4ffe1
No related branches found
No related tags found
No related merge requests found
......@@ -233,21 +233,29 @@ class workflow_manager {
}
if ($action === ACTION_WORKFLOW_ABORTDISABLE) {
if ($confirm and confirm_sesskey()) {
self::abortprocesses($workflowid);
self::disable($workflowid);
self::abortprocesses($workflowid);
} else {
self::render_demand_confirm($action, $workflowid, get_string('abortdisableworkflow_confirm', 'tool_lifecycle'));
}
}
if ($action === ACTION_WORKFLOW_DELETE) {
if (self::get_workflow($workflowid)) { // check workflow wasnt already deleted, in case someone refreshes the page
if (!self::is_removable($workflowid)) {
echo $OUTPUT->notification(get_string('workflow_not_removeable', 'tool_lifecycle')
, 'warning');
if ($action === ACTION_WORKFLOW_ABORT) {
if ($confirm and confirm_sesskey()) {
self::abortprocesses($workflowid);
} else {
self::render_demand_confirm($action, $workflowid, get_string('abortprocesses_confirm', 'tool_lifecycle'));
}
}
if ($action === ACTION_WORKFLOW_DELETE) {
if (self::get_workflow($workflowid) && self::is_removable($workflowid)) { // check workflow wasn't already deleted, in case someone refreshes the page
if ($confirm and confirm_sesskey()) {
self::remove($workflowid);
} else {
self::render_demand_confirm($action, $workflowid, get_string('deleteworkflow_confirm', 'tool_lifecycle'));
}
} else {
echo $OUTPUT->notification(get_string('workflow_not_removeable', 'tool_lifecycle')
, 'warning'); // @todo these notifications aren't shown properly currently
}
}
}
......@@ -398,7 +406,7 @@ class workflow_manager {
}
/**
* Workflows should only be editable, if never been activated before
* Workflows should only be editable if never been activated before
*
* @param $workflowid
* @return bool
......@@ -411,6 +419,26 @@ class workflow_manager {
return true;
}
/**
* Workflows should only be abortable if disabled but some processes are still running
*
* @param $workflowid
* @return bool
*/
public static function is_abortable($workflowid) {
$countprocesses = process_manager::count_processes_by_workflow($workflowid);
if ($countprocesses > 0) {
return true;
}
return false;
}
/**
* Workflows should only be removable if disableable and no more processes are running
*
* @param $workflowid
* @return bool
*/
public static function is_removable($workflowid) {
$countprocesses = process_manager::count_processes_by_workflow($workflowid);
if (self::is_disableable($workflowid) && $countprocesses == 0) {
......
......@@ -50,7 +50,7 @@ class active_automatic_workflows_table extends workflow_table {
}
public function init() {
$this->define_columns(['title', 'timeactive', 'trigger', 'processes', 'sortindex', 'tools', 'disable']);
$this->define_columns(['title', 'timeactive', 'trigger', 'processes', 'sortindex', 'tools']);
$this->define_headers([
get_string('workflow_title', 'tool_lifecycle'),
get_string('workflow_timeactive', 'tool_lifecycle'),
......@@ -58,7 +58,6 @@ class active_automatic_workflows_table extends workflow_table {
get_string('workflow_processes', 'tool_lifecycle'),
get_string('workflow_sortindex', 'tool_lifecycle'),
get_string('workflow_tools', 'tool_lifecycle'),
get_string('disableworkflow', 'tool_lifecycle'),
]);
$this->sortable(false, 'sortindex');
$this->setup();
......@@ -96,31 +95,36 @@ class active_automatic_workflows_table extends workflow_table {
}
/**
* Render disable column.
* Render tools column.
*
* @param $row
* @return string action buttons for workflows
*/
public function col_disable($row) {
public function col_tools($row) {
global $OUTPUT;
$output = '';
$alt = get_string('viewsteps', 'tool_lifecycle');
$icon = 't/viewdetails';
$url = new \moodle_url('/admin/tool/lifecycle/workflowsettings.php',
array('workflowid' => $row->id, 'sesskey' => sesskey()));
$output .= $OUTPUT->action_icon($url, new \pix_icon($icon, $alt, 'moodle', array('title' => $alt)),
null, array('title' => $alt));
if (workflow_manager::is_disableable($row->id)) {
$alt = get_string('disableworkflow', 'tool_lifecycle');
$icon = 't/disable';
$url = new \moodle_url('/admin/tool/lifecycle/deactivatedworkflows.php',
array('workflowid' => $row->id, 'action' => ACTION_WORKFLOW_DISABLE, 'sesskey' => sesskey()));
$output .=
'<div>' . $OUTPUT->single_button(
$url,
get_string('disableworkflow', 'tool_lifecycle'))
. '</div>';
$output .= $OUTPUT->action_icon($url, new \pix_icon($icon, $alt, 'tool_lifecycle', array('title' => $alt)),
null, array('title' => $alt));
$alt = get_string('abortdisableworkflow', 'tool_lifecycle');
$icon = 't/stop';
$url = new \moodle_url('/admin/tool/lifecycle/deactivatedworkflows.php',
array('workflowid' => $row->id, 'action' => ACTION_WORKFLOW_ABORTDISABLE, 'sesskey' => sesskey()));
$output .=
'<div>' . $OUTPUT->single_button(
$url,
get_string('abortdisableworkflow', 'tool_lifecycle'))
. '</div>';
$output .= $OUTPUT->action_icon($url, new \pix_icon($icon, $alt, 'moodle', array('title' => $alt)),
null, array('title' => $alt));
}
return $output;
......
......@@ -91,11 +91,22 @@ class deactivated_workflows_table extends workflow_table {
$icon = 't/edit';
$output .= $this->format_icon_link($action, $row->id, $icon, $alt);
if (!workflow_manager::is_active($row->id)) {
$action = ACTION_WORKFLOW_DELETE; // @todo make sure the action checks if no more processes are running
if (workflow_manager::is_abortable($row->id)) {
$alt = get_string('abortprocesses', 'tool_lifecycle');
$icon = 't/stop';
$url = new \moodle_url('/admin/tool/lifecycle/deactivatedworkflows.php',
array('workflowid' => $row->id, 'action' => ACTION_WORKFLOW_ABORT, 'sesskey' => sesskey()));
$output .= $OUTPUT->action_icon($url, new \pix_icon($icon, $alt, 'moodle', array('title' => $alt)),
null, array('title' => $alt));
}
if (workflow_manager::is_removable($row->id)) {
$alt = get_string('deleteworkflow', 'tool_lifecycle');
$url = new \moodle_url('/admin/tool/lifecycle/deactivatedworkflows.php',
array('workflowid' => $row->id, 'action' => ACTION_WORKFLOW_DELETE, 'sesskey' => sesskey()));
$icon = 't/delete';
$output .= $this->format_icon_link($action, $row->id, $icon, $alt);
$output .= $OUTPUT->action_icon($url, new \pix_icon($icon, $alt, 'moodle', array('title' => $alt)),
null, array('title' => $alt));
}
}
......
......@@ -75,16 +75,19 @@ $string['workflow_active'] = 'Active';
$string['workflow_processes'] = 'Active processes';
$string['workflow_timeactive'] = 'Active since';
$string['workflow_sortindex'] = 'Up/Down';
$string['workflow_tools'] = 'Tools';
$string['workflow_tools'] = 'Actions';
$string['viewsteps'] = 'View Workflow Steps';
$string['editworkflow'] = 'Edit Title';
$string['duplicateworkflow'] = 'Duplicate Workflow';
$string['deleteworkflow'] = 'Delete Workflow';
$string['deleteworkflow_confirm'] = 'The workflow is going to be deleted. This can\'t be undone. Are you sure?';
$string['activateworkflow'] = 'Activate';
$string['disableworkflow'] = 'Disable Workflow';
$string['disableworkflow'] = 'Disable Workflow (processes keep running)';
$string['disableworkflow_confirm'] = 'The workflow is going to be disabled. Are you sure?';
$string['abortdisableworkflow'] = 'Abort processes & disable Workflow';
$string['abortdisableworkflow'] = 'Disable Workflow (abort processes, maybe unsafe!)';
$string['abortdisableworkflow_confirm'] = 'The workflow is going to be disabled and all running processes of this workflow will be aborted. Are you sure?';
$string['abortprocesses'] = 'Abort running processes (maybe unsafe!)';
$string['abortprocesses_confirm'] = 'All running processes of this workflow will be aborted. Are you sure?';
$string['workflow_duplicate_title'] = '{$a} (Copy)';
// deactivated workflows
......
......@@ -43,3 +43,14 @@ define('ACTION_WORKFLOW_DUPLICATE', 'workflow_instance_duplicate');
define('ACTION_WORKFLOW_ACTIVATE', 'workflow_instance_activate');
define('ACTION_WORKFLOW_DISABLE', 'workflow_instance_disable');
define('ACTION_WORKFLOW_ABORTDISABLE', 'workflow_instance_abortdisable');
define('ACTION_WORKFLOW_ABORT', 'workflow_instance_abort');
/**
* Get icon mapping for font-awesome.
*
*/
function tool_lifecycle_get_fontawesome_icon_map() {
return [
'tool_lifecycle:t/disable' => 'fa-hand-paper-o',
];
}
\ No newline at end of file
......@@ -126,6 +126,26 @@ class behat_tool_lifecycle extends behat_base {
throw new ExpectationException('"The table "' . $tablename . '" was found."', $this->getSession());
}
/**
* I should see an entire row.
*
* @When /^I should see the row "([^"]*)" in the "([^"]*)" table$/
*
* @param $tablename string identifier of the table
* @throws Exception
*/
public function i_should_see_the_row($rowname, $tablename) {
// @todo solve without relaying on exceptions
try {
$this->get_xpath_of_row($rowname, $tablename);
} catch (ExpectationException $e) { // gets also threw on not existing table!
throw new ExpectationException('"The row "' . $tablename . '" was found."', $this->getSession());
}
return;
}
/**
* I should not see an entire row.
*
......
@tool @tool_lifecycle
Feature: Disable a workflow
Further, check that all edit possibilities are disabled.
Background:
Given the following "courses" exist:
| fullname | shortname | category | startdate |
| Course 1 | C1 | 0 | ##4 days ago## |
And I log in as "admin"
And I navigate to "Life Cycle > Workflow Settings" in site administration
And I press "Add Workflow"
And I set the following fields to these values:
| Title | My Workflow |
| Displayed workflow title | Teachers view on workflow |
And I press "Save changes"
And I select "Start date delay trigger" from the "triggername" singleselect
And I set the following fields to these values:
| Instance Name | My Trigger |
| delay[number] | 3 |
| delay[timeunit] | days |
And I press "Save changes"
And I select "Email Step" from the "stepname" singleselect
And I set the following fields to these values:
| Instance Name | Email Step |
| responsetimeout[number] | 42 |
| responsetimeout[timeunit] | days |
| Subject Template | Subject |
| Content Template | Content |
| Content HTML Template | Content HTML |
And I press "Save changes"
And I select "Delete Course Step" from the "stepname" singleselect
And I set the field "Instance Name" to "Delete Course 1"
And I press "Save changes"
And I press "Back"
And I press "Activate"
When I wait "10" seconds
And I run the scheduled task "tool_lifecycle\task\lifecycle_task"
And I log out
Scenario: Disable an workflow, keep processes running, then abort all processes and delete workflow
Given I log in as "admin"
And I navigate to "Life Cycle > Workflow Settings" in site administration
Then I should see the row "My Workflow" in the "tool_lifecycle_active_automatic_workflows" table
And I should see the tool "Disable Workflow (processes keep running)" in the "My Workflow" row of the "tool_lifecycle_active_automatic_workflows" table
When I click on the tool "Disable Workflow (processes keep running)" in the "My Workflow" row of the "tool_lifecycle_active_automatic_workflows" table
Then I should see "The workflow is going to be disabled. Are you sure?"
When I press "Continue"
Then I should see the tool "Abort running processes (maybe unsafe!)" in the "My Workflow" row of the "tool_lifecycle_deactivated_workflows" table
And I should not see the tool "Delete Workflow" in the "My Workflow" row of the "tool_lifecycle_deactivated_workflows" table
When I click on the tool "Abort running processes (maybe unsafe!)" in the "My Workflow" row of the "tool_lifecycle_deactivated_workflows" table
Then I should see "All running processes of this workflow will be aborted. Are you sure?"
When I press "Continue"
Then I should see the tool "Delete Workflow" in the "My Workflow" row of the "tool_lifecycle_deactivated_workflows" table
And I should not see the tool "Abort running processes (maybe unsafe!)" in the "My Workflow" row of the "tool_lifecycle_deactivated_workflows" table
When I click on the tool "Delete Workflow" in the "My Workflow" row of the "tool_lifecycle_deactivated_workflows" table
Then I should see "The workflow is going to be deleted. This can't be undone. Are you sure?"
When I press "Continue"
Then I should see "Nothing to display"
Scenario: Disable an workflow then create (duplicate) a new one with the same configuration
Given I log in as "admin"
And I navigate to "Life Cycle > Workflow Settings" in site administration
Then I should see the row "My Workflow" in the "tool_lifecycle_active_automatic_workflows" table
When I click on the tool "Disable Workflow (processes keep running)" in the "My Workflow" row of the "tool_lifecycle_active_automatic_workflows" table
Then I should see "The workflow is going to be disabled. Are you sure?"
Then I press "Continue"
When I click on the tool "Duplicate Workflow" in the "My Workflow" row of the "tool_lifecycle_deactivated_workflows" table
Then I should see the row "My Workflow" in the "tool_lifecycle_workflow_definitions" table
And I should not see the row "My Workflow" in the "tool_lifecycle_active_automatic_workflows" table
When I press "Activate"
Then I should not see the row "My Workflow" in the "tool_lifecycle_workflow_definitions" table
And I should see the row "My Workflow" in the "tool_lifecycle_active_automatic_workflows" table
# TODO: disable and abort button
\ No newline at end of file
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/generator/lib.php');
require_once(__DIR__ . '/../lib.php');
use tool_lifecycle\manager\workflow_manager;
use tool_lifecycle\entity\workflow;
/**
* Tests activating, disabling and duplicating workflows
*
* @package tool_lifecycle
* @category test
* @group tool_lifecycle
* @copyright 2018 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_lifecycle_workflow_activate_disable_duplicate_testcase extends \advanced_testcase {
// @TODO
private $workflow1;
private $workflow2;
private $workflow3;
public function setUp() {
$this->resetAfterTest(true);
$generator = $this->getDataGenerator()->get_plugin_generator('tool_lifecycle');
// Remove preset workflows.
$workflows = workflow_manager::get_active_automatic_workflows();
foreach ($workflows as $workflow) {
workflow_manager::remove($workflow->id, true); // remove() hasn't removed unremovable workflows (like presets) anymore…
}
$this->workflow1 = $generator->create_workflow();
$this->workflow2 = $generator->create_workflow();
$this->workflow3 = $generator->create_workflow();
$this->assertFalse($this->workflow1->active);
$this->assertFalse($this->workflow2->active);
$this->assertFalse($this->workflow3->active);
$this->assertNull($this->workflow1->sortindex);
$this->assertNull($this->workflow2->sortindex);
$this->assertNull($this->workflow3->sortindex);
}
/**
* Test to activate the first workflow.
*/
public function test_activate_first() {
workflow_manager::handle_action(ACTION_WORKFLOW_ACTIVATE, $this->workflow1->id);
$reloadworkflow = workflow_manager::get_workflow($this->workflow1->id);
$this->assertTrue(workflow_manager::is_active($this->workflow1->id));
$this->assertEquals(1, $reloadworkflow->sortindex);
}
/**
* Test to activate the first and the second workflow.
*/
public function test_activate_second() {
workflow_manager::handle_action(ACTION_WORKFLOW_ACTIVATE, $this->workflow1->id);
workflow_manager::handle_action(ACTION_WORKFLOW_ACTIVATE, $this->workflow2->id);
$reloadworkflow = workflow_manager::get_workflow($this->workflow2->id);
$this->assertTrue(workflow_manager::is_active($this->workflow2->id));
$this->assertEquals(2, $reloadworkflow->sortindex);
}
/**
* Test to activate all three workflow.
*/
public function test_activate_third() {
workflow_manager::handle_action(ACTION_WORKFLOW_ACTIVATE, $this->workflow1->id);
workflow_manager::handle_action(ACTION_WORKFLOW_ACTIVATE, $this->workflow2->id);
workflow_manager::handle_action(ACTION_WORKFLOW_ACTIVATE, $this->workflow3->id);
$reloadworkflow = workflow_manager::get_workflow($this->workflow3->id);
$this->assertTrue(workflow_manager::is_active($this->workflow3->id));
$this->assertEquals(3, $reloadworkflow->sortindex);
}
// @todo
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment