mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-52485 tool_lp: Do not validate unchanged due dates in plans
This commit is contained in:
parent
a967d2aa8c
commit
c78ebeac1b
2 changed files with 39 additions and 1 deletions
|
@ -436,6 +436,18 @@ class plan extends persistent {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// During update.
|
||||||
|
if ($this->get_id()) {
|
||||||
|
$before = $this->beforeupdate->get_duedate();
|
||||||
|
$beforestatus = $this->beforeupdate->get_status();
|
||||||
|
|
||||||
|
// The value has not changed, then it's always OK. Though if we're going
|
||||||
|
// from draft to active it has to has to be validated.
|
||||||
|
if ($before == $value && $beforestatus != self::STATUS_DRAFT) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($value <= time()) {
|
if ($value <= time()) {
|
||||||
// We cannot set the date in the past.
|
// We cannot set the date in the past.
|
||||||
return new lang_string('errorcannotsetduedateinthepast', 'tool_lp');
|
return new lang_string('errorcannotsetduedateinthepast', 'tool_lp');
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
|
use tool_lp\plan;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plan persistent testcase.
|
* Plan persistent testcase.
|
||||||
*
|
*
|
||||||
|
@ -301,6 +303,23 @@ class tool_lp_plan_testcase extends advanced_testcase {
|
||||||
// Updating active plan.
|
// Updating active plan.
|
||||||
$plan->update();
|
$plan->update();
|
||||||
|
|
||||||
|
// Active to active: past => same past (pass).
|
||||||
|
$record = $plan->to_record();
|
||||||
|
$record->duedate = 1;
|
||||||
|
$DB->update_record(plan::TABLE, $record);
|
||||||
|
$plan->read();
|
||||||
|
$plan->set_description(uniqid()); // Force revalidation.
|
||||||
|
$this->assertTrue($plan->is_valid());
|
||||||
|
|
||||||
|
// Active to active: past => unset (pass).
|
||||||
|
$plan->set_duedate(0);
|
||||||
|
$this->assertTrue($plan->is_valid());
|
||||||
|
$plan->update();
|
||||||
|
|
||||||
|
// Active to active: unset => unset (pass).
|
||||||
|
$plan->set_description(uniqid()); // Force revalidation.
|
||||||
|
$this->assertTrue($plan->is_valid());
|
||||||
|
|
||||||
// Active to active: unset date => past date(fail).
|
// Active to active: unset date => past date(fail).
|
||||||
$plan->set_duedate(time() - 100);
|
$plan->set_duedate(time() - 100);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -322,6 +341,10 @@ class tool_lp_plan_testcase extends advanced_testcase {
|
||||||
// Updating active plan with future date.
|
// Updating active plan with future date.
|
||||||
$plan->update();
|
$plan->update();
|
||||||
|
|
||||||
|
// Active to active: future => same future (pass).
|
||||||
|
$plan->set_description(uniqid()); // Force revalidation.
|
||||||
|
$this->assertTrue($plan->is_valid());
|
||||||
|
|
||||||
// Active to active: future date => unset date (pass).
|
// Active to active: future date => unset date (pass).
|
||||||
$plan->set_duedate(0);
|
$plan->set_duedate(0);
|
||||||
$this->assertEquals(true, $plan->validate());
|
$this->assertEquals(true, $plan->validate());
|
||||||
|
@ -411,7 +434,10 @@ class tool_lp_plan_testcase extends advanced_testcase {
|
||||||
$success = tool_lp\api::reopen_plan($plan->get_id());
|
$success = tool_lp\api::reopen_plan($plan->get_id());
|
||||||
$this->assertTrue($success);
|
$this->assertTrue($success);
|
||||||
$plan->read();
|
$plan->read();
|
||||||
$this->assertEquals(time() + tool_lp\plan::DUEDATE_THRESHOLD + 10, $plan->get_duedate());
|
|
||||||
|
// Check that the due date has not changed, but allow for PHP Unit latency.
|
||||||
|
$this->assertTrue($plan->get_duedate() >= time() + tool_lp\plan::DUEDATE_THRESHOLD + 10);
|
||||||
|
$this->assertTrue($plan->get_duedate() <= time() + tool_lp\plan::DUEDATE_THRESHOLD + 15);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue