-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PHPUnit test for deleting a page containing elements. Previously this action resulted in an error.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Contains tests for template's page operations. | ||
* | ||
* @package mod_customcert | ||
* @copyright 2023 Leon Stringer <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mod_customcert\event; | ||
|
||
/** | ||
* Contains tests for template's page operations. | ||
* | ||
* @package mod_customcert | ||
* @copyright 2023 Leon Stringer <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class page_test extends \advanced_testcase { | ||
public function setUp(): void { | ||
$this->resetAfterTest(); | ||
} | ||
|
||
/** | ||
* Check deleting a non-empty page has no errors. | ||
* 1. Create a template. | ||
* 2. Add a second page. | ||
* 3. Add an element to the second page. | ||
* 4. Delete the second page. | ||
* Previously the above scenario resulted in an error (#571). | ||
*/ | ||
public function test_delete_non_empty_page(): void { | ||
global $DB; | ||
|
||
$template = \mod_customcert\template::create('Test name', \context_system::instance()->id); | ||
|
||
// Add a second page and add an element to it. | ||
$page2id = $template->add_page(); | ||
$element = new \stdClass(); | ||
$element->pageid = $page2id; | ||
$element->name = 'Image'; | ||
$element->element = 'image'; | ||
$elementid = $DB->insert_record('customcert_elements', $element); | ||
|
||
$template->delete_page($page2id); | ||
|
||
$records = $DB->get_records('customcert_elements', array('pageid' => $page2id)); | ||
$this->assertCount(0, $records); | ||
|
||
$records = $DB->get_records('customcert_pages', array('id' => $page2id)); | ||
$this->assertCount(0, $records); | ||
} | ||
} |