From fbbfd84803bb6cd508e7f3cc0bb549af84dabbd4 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Fri, 31 Aug 2018 11:22:45 +0800 Subject: [PATCH] MDL-62554 tool_dataprivacy: Behat tests for managing registry defaults * Also new step definitions and generator for: - Creating categories and purposes - Assigning category and purpose to context instances. --- .../tests/behat/behat_tool_dataprivacy.php | 284 +++++++++++++++++ .../tests/behat/manage_defaults.feature | 298 ++++++++++++++++++ .../tool/dataprivacy/tests/generator/lib.php | 115 +++++++ 3 files changed, 697 insertions(+) create mode 100644 admin/tool/dataprivacy/tests/behat/behat_tool_dataprivacy.php create mode 100644 admin/tool/dataprivacy/tests/behat/manage_defaults.feature create mode 100644 admin/tool/dataprivacy/tests/generator/lib.php diff --git a/admin/tool/dataprivacy/tests/behat/behat_tool_dataprivacy.php b/admin/tool/dataprivacy/tests/behat/behat_tool_dataprivacy.php new file mode 100644 index 00000000000..857bb336ba7 --- /dev/null +++ b/admin/tool/dataprivacy/tests/behat/behat_tool_dataprivacy.php @@ -0,0 +1,284 @@ +. + +/** + * Step definitions to generate database fixtures for the data privacy tool. + * + * @package tool_dataprivacy + * @category test + * @copyright 2018 Jun Pataleta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php'); + +use Behat\Gherkin\Node\TableNode as TableNode; +use Behat\Behat\Tester\Exception\PendingException as PendingException; +use tool_dataprivacy\api; + +/** + * Step definitions to generate database fixtures for the data privacy tool. + * + * @package tool_dataprivacy + * @category test + * @copyright 2018 Jun Pataleta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_tool_dataprivacy extends behat_base { + + /** + * Each element specifies: + * - The data generator suffix used. + * - The required fields. + * - The mapping between other elements references and database field names. + * @var array + */ + protected static $elements = array( + 'categories' => array( + 'datagenerator' => 'category', + 'required' => array() + ), + 'purposes' => array( + 'datagenerator' => 'purpose', + 'required' => array() + ), + ); + + /** + * Creates the specified element. More info about available elements in http://docs.moodle.org/dev/Acceptance_testing#Fixtures. + * + * @Given /^the following data privacy "(?P(?:[^"]|\\")*)" exist:$/ + * + * @param string $elementname The name of the entity to add + * @param TableNode $data + */ + public function the_following_data_categories_exist($elementname, TableNode $data) { + + // Now that we need them require the data generators. + require_once(__DIR__.'/../../../../../lib/phpunit/classes/util.php'); + + if (empty(self::$elements[$elementname])) { + throw new PendingException($elementname . ' data generator is not implemented'); + } + + $datagenerator = testing_util::get_data_generator(); + $dataprivacygenerator = $datagenerator->get_plugin_generator('tool_dataprivacy'); + + $elementdatagenerator = self::$elements[$elementname]['datagenerator']; + $requiredfields = self::$elements[$elementname]['required']; + if (!empty(self::$elements[$elementname]['switchids'])) { + $switchids = self::$elements[$elementname]['switchids']; + } + + foreach ($data->getHash() as $elementdata) { + + // Check if all the required fields are there. + foreach ($requiredfields as $requiredfield) { + if (!isset($elementdata[$requiredfield])) { + throw new Exception($elementname . ' requires the field ' . $requiredfield . ' to be specified'); + } + } + + // Switch from human-friendly references to ids. + if (isset($switchids)) { + foreach ($switchids as $element => $field) { + $methodname = 'get_' . $element . '_id'; + + // Not all the switch fields are required, default vars will be assigned by data generators. + if (isset($elementdata[$element])) { + // Temp $id var to avoid problems when $element == $field. + $id = $this->{$methodname}($elementdata[$element]); + unset($elementdata[$element]); + $elementdata[$field] = $id; + } + } + } + + // Preprocess the entities that requires a special treatment. + if (method_exists($this, 'preprocess_' . $elementdatagenerator)) { + $elementdata = $this->{'preprocess_' . $elementdatagenerator}($elementdata); + } + + // Creates element. + $methodname = 'create_' . $elementdatagenerator; + if (method_exists($dataprivacygenerator, $methodname)) { + // Using data generators directly. + $dataprivacygenerator->{$methodname}($elementdata); + + } else if (method_exists($this, 'process_' . $elementdatagenerator)) { + // Using an alternative to the direct data generator call. + $this->{'process_' . $elementdatagenerator}($elementdata); + } else { + throw new PendingException($elementname . ' data generator is not implemented'); + } + } + } + + /** + * Sets the data category and data storage purpose for the site. + * + * @Given /^I set the site category and purpose to "(?P(?:[^"]|\\")*)" and "(?P(?:[^"]|\\")*)"$/ + * + * @param string $category The ID of the category to be set for the instance. + * @param string $purpose The ID of the purpose to be set for the instance. + */ + public function i_set_the_site_category_and_purpose($category, $purpose) { + $category = \tool_dataprivacy\category::get_record(['name' => $category]); + $purpose = \tool_dataprivacy\purpose::get_record(['name' => $purpose]); + $data = (object)[ + 'contextlevel' => CONTEXT_SYSTEM, + 'categoryid' => $category->get('id'), + 'purposeid' => $purpose->get('id'), + ]; + api::set_contextlevel($data); + } + + /** + * Sets the data category and data storage purpose for a course category instance. + * + * @Given /^I set the category and purpose for the course category "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)" and "(?P(?:[^"]|\\")*)"$/ + * + * @param string $name The instance name. It should match the name or the idnumber. + * @param string $category The ID of the category to be set for the instance. + * @param string $purpose The ID of the purpose to be set for the instance. + */ + public function i_set_the_category_and_purpose_for_course_category($name, $category, $purpose) { + global $DB; + + $params = [ + 'name' => $name, + 'idnumber' => $name, + ]; + $select = 'name = :name OR idnumber = :idnumber'; + $coursecatid = $DB->get_field_select('course_categories', 'id', $select, $params, MUST_EXIST); + $context = context_coursecat::instance($coursecatid); + + $this->set_category_and_purpose($context->id, $category, $purpose); + } + + /** + * Sets the data category and data storage purpose for a course instance. + * + * @Given /^I set the category and purpose for the course "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)" and "(?P(?:[^"]|\\")*)"$/ + * + * @param string $name The instance name. It should match the fullname or the shortname, or the idnumber. + * @param string $category The ID of the category to be set for the instance. + * @param string $purpose The ID of the purpose to be set for the instance. + */ + public function i_set_the_category_and_purpose_for_course($name, $category, $purpose) { + global $DB; + + $params = [ + 'shortname' => $name, + 'fullname' => $name, + 'idnumber' => $name, + ]; + $select = 'shortname = :shortname OR fullname = :fullname OR idnumber = :idnumber'; + $courseid = $DB->get_field_select('course', 'id', $select, $params, MUST_EXIST); + $context = context_course::instance($courseid); + + $this->set_category_and_purpose($context->id, $category, $purpose); + } + + /** + * Sets the data category and data storage purpose for a course instance. + * + * @Given /^I set the category and purpose for the "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)" in course "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)" and "(?P(?:[^"]|\\")*)"$/ + * + * @param string $name The instance name. It should match the name of the activity. + * @param string $type The activity type. E.g. assign, quiz, forum, etc. + * @param string $coursename The course name. It should match the fullname or the shortname, or the idnumber. + * @param string $category The ID of the category to be set for the instance. + * @param string $purpose The ID of the purpose to be set for the instance. + */ + public function i_set_the_category_and_purpose_for_activity($name, $type, $coursename, $category, $purpose) { + global $DB; + + $params = [ + 'shortname' => $coursename, + 'fullname' => $coursename, + 'idnumber' => $coursename, + ]; + $select = 'shortname = :shortname OR fullname = :fullname OR idnumber = :idnumber'; + $courseid = $DB->get_field_select('course', 'id', $select, $params, MUST_EXIST); + + $cmid = null; + $cms = get_coursemodules_in_course($type, $courseid); + foreach ($cms as $cm) { + if ($cm->name === $name || $cm->idnumber === $name) { + $cmid = $cm->id; + break; + } + } + if ($cmid === null) { + throw new coding_exception("Activity module '{$name}' of type '{$type}' not found!"); + } + $context = context_module::instance($cmid); + + $this->set_category_and_purpose($context->id, $category, $purpose); + } + + /** + * Sets the data category and data storage purpose for a course instance. + * + * @Given /^I set the category and purpose for the "(?P(?:[^"]|\\")*)" block in the "(?P(?:[^"]|\\")*)" course to "(?P(?:[^"]|\\")*)" and "(?P(?:[^"]|\\")*)"$/ + * + * @param string $name The instance name. It should match the name of the block. (e.g. online_users) + * @param string $coursename The course name. It should match the fullname or the shortname, or the idnumber. + * @param string $category The ID of the category to be set for the instance. + * @param string $purpose The ID of the purpose to be set for the instance. + */ + public function i_set_the_category_and_purpose_for_block($name, $coursename, $category, $purpose) { + global $DB; + + $params = [ + 'shortname' => $coursename, + 'fullname' => $coursename, + 'idnumber' => $coursename, + ]; + $select = 'shortname = :shortname OR fullname = :fullname OR idnumber = :idnumber'; + $courseid = $DB->get_field_select('course', 'id', $select, $params, MUST_EXIST); + + // Fetch the course context. + $coursecontext = context_course::instance($courseid); + + // Fetch the block record and context. + $blockid = $DB->get_field('block_instances', 'id', ['blockname' => $name, 'parentcontextid' => $coursecontext->id]); + $context = context_block::instance($blockid); + + // Set the category and purpose. + $this->set_category_and_purpose($context->id, $category, $purpose); + } + + /** + * Sets the category and purpose for a context instance. + * + * @param int $contextid The context ID. + * @param int $categoryname The category name. + * @param int $purposename The purpose name. + * @throws coding_exception + */ + protected function set_category_and_purpose($contextid, $categoryname, $purposename) { + $category = \tool_dataprivacy\category::get_record(['name' => $categoryname]); + $purpose = \tool_dataprivacy\purpose::get_record(['name' => $purposename]); + + api::set_context_instance((object) [ + 'contextid' => $contextid, + 'purposeid' => $purpose->get('id'), + 'categoryid' => $category->get('id'), + ]); + } +} diff --git a/admin/tool/dataprivacy/tests/behat/manage_defaults.feature b/admin/tool/dataprivacy/tests/behat/manage_defaults.feature new file mode 100644 index 00000000000..a6287d595ad --- /dev/null +++ b/admin/tool/dataprivacy/tests/behat/manage_defaults.feature @@ -0,0 +1,298 @@ +@tool @tool_dataprivacy @javascript +Feature: Manage data registry defaults + As the privacy officer + In order to manage the data registry + I need to be able to manage the default data categories and data storage purposes for various context levels. + + Background: + Given I log in as "admin" + And the following "categories" exist: + | name | idnumber | category | + | Science and technology | scitech | | + | Physics | st-phys | scitech | + And the following "courses" exist: + | fullname | shortname | category | + | Fundamentals of physics 1 | Physics 101 | st-phys | + And the following "activities" exist: + | activity | name | idnumber | course | + | assign | Assignment 1 | assign1 | Physics 101 | + | forum | Forum 1 | forum1 | Physics 101 | + And the following "blocks" exist: + | blockname | contextlevel | reference | pagetypepattern | defaultregion | + | online_users | Course | Physics 101 | course-view-* | site-post | + And the following data privacy "categories" exist: + | name | + | Site category | + | Category 1 | + | Category 2 | + And the following data privacy "purposes" exist: + | name | retentionperiod | + | Site purpose | P10Y | + | Purpose 1 | P3Y | + | Purpose 2 | P5Y | + And I set the site category and purpose to "Site category" and "Site purpose" + + Scenario: Set course category data registry defaults + Given I set the category and purpose for the course category "scitech" to "Category 2" and "Purpose 2" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Set defaults" "link" + And I should see "Inherit" + And I should not see "Add a new module default" + And I press "Edit" + And I set the field "Category" to "Category 1" + And I set the field "Purpose" to "Purpose 1" + When I press "Save changes" + Then I should see "Category 1" + And I should see "Purpose 1" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Science and technology" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Category 2" + And the field "purposeid" matches value "Purpose 2" + And I should see "5 years" + + Scenario: Set course category data registry defaults with override + Given I set the category and purpose for the course category "scitech" to "Category 2" and "Purpose 2" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Set defaults" "link" + And I should see "Inherit" + And I should not see "Add a new module default" + And I press "Edit" + And I set the field "Category" to "Category 1" + And I set the field "Purpose" to "Purpose 1" + And I click on "Reset instances with custom values" "checkbox" + When I press "Save changes" + Then I should see "Category 1" + And I should see "Purpose 1" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Science and technology" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Not set (use the default value)" + And the field "purposeid" matches value "Not set (use the default value)" + And I should see "3 years" + + Scenario: Set course data registry defaults + Given I set the category and purpose for the course "Physics 101" to "Category 2" and "Purpose 2" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Set defaults" "link" + And I click on "Courses" "link" + And I should see "Inherit" + And I should not see "Add a new module default" + And I press "Edit" + And I set the field "Category" to "Category 1" + And I set the field "Purpose" to "Purpose 1" + When I press "Save changes" + Then I should see "Category 1" + And I should see "Purpose 1" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Science and technology" "link" + And I wait until the page is ready + And I click on "Courses" "link" + And I wait until the page is ready + And I click on "Physics 101" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Category 2" + And the field "purposeid" matches value "Purpose 2" + And I should see "5 years (after the course end date)" + + Scenario: Set course data registry defaults with override + Given I set the category and purpose for the course "Physics 101" to "Category 2" and "Purpose 2" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Set defaults" "link" + And I click on "Courses" "link" + And I should see "Inherit" + And I should not see "Add a new module default" + And I press "Edit" + And I set the field "Category" to "Category 1" + And I set the field "Purpose" to "Purpose 1" + And I click on "Reset instances with custom values" "checkbox" + When I press "Save changes" + Then I should see "Category 1" + And I should see "Purpose 1" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Science and technology" "link" + And I wait until the page is ready + And I click on "Courses" "link" + And I wait until the page is ready + And I click on "Physics 101" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Not set (use the default value)" + And the field "purposeid" matches value "Not set (use the default value)" + And I should see "3 years (after the course end date)" + + Scenario: Set module level data registry defaults + Given I set the category and purpose for the "assign1" "assign" in course "Physics 101" to "Category 2" and "Purpose 2" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Set defaults" "link" + And I click on "Activity modules" "link" + And I should see "Inherit" + And I should see "Add a new module default" + And I press "Edit" + And I set the field "Category" to "Category 1" + And I set the field "Purpose" to "Purpose 1" + When I press "Save changes" + Then I should see "Category 1" + And I should see "Purpose 1" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Science and technology" "link" + And I wait until the page is ready + And I click on "Courses" "link" + And I wait until the page is ready + And I click on "Physics 101" "link" + And I wait until the page is ready + And I click on "Activities and resources" "link" + And I wait until the page is ready + And I click on "Assignment 1 (Assignment)" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Category 2" + And the field "purposeid" matches value "Purpose 2" + And I should see "5 years (after the course end date)" + + Scenario: Set module level data registry defaults with override + Given I set the category and purpose for the "assign1" "assign" in course "Physics 101" to "Category 2" and "Purpose 2" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Set defaults" "link" + And I click on "Activity modules" "link" + And I should see "Inherit" + And I should see "Add a new module default" + And I press "Edit" + And I set the field "Category" to "Category 1" + And I set the field "Purpose" to "Purpose 1" + And I click on "Reset instances with custom values" "checkbox" + When I press "Save changes" + Then I should see "Category 1" + And I should see "Purpose 1" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Science and technology" "link" + And I wait until the page is ready + And I click on "Courses" "link" + And I wait until the page is ready + And I click on "Physics 101" "link" + And I wait until the page is ready + And I click on "Activities and resources" "link" + And I wait until the page is ready + And I click on "Assignment 1 (Assignment)" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Not set (use the default value)" + And the field "purposeid" matches value "Not set (use the default value)" + And I click on "Forum 1 (Forum)" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Not set (use the default value)" + And the field "purposeid" matches value "Not set (use the default value)" + And I should see "3 years (after the course end date)" + + Scenario: Set data registry defaults for an activity module + Given I set the category and purpose for the "assign1" "assign" in course "Physics 101" to "Category 2" and "Purpose 2" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Set defaults" "link" + And I click on "Activity modules" "link" + And I should see "Inherit" + And I should see "Add a new module default" + And I press "Add a new module default" + And I set the field "Activity module" to "Assignment" + And I set the field "Category" to "Category 1" + And I set the field "Purpose" to "Purpose 1" + When I press "Save changes" + Then I should see "Category 1" in the "Assignment" "table_row" + And I should see "Purpose 1" in the "Assignment" "table_row" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Science and technology" "link" + And I wait until the page is ready + And I click on "Courses" "link" + And I wait until the page is ready + And I click on "Physics 101" "link" + And I wait until the page is ready + And I click on "Activities and resources" "link" + And I wait until the page is ready + And I click on "Assignment 1 (Assignment)" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Category 2" + And the field "purposeid" matches value "Purpose 2" + And I should see "5 years (after the course end date)" + + Scenario: Set data registry defaults for an activity module with override + Given I set the category and purpose for the "assign1" "assign" in course "Physics 101" to "Category 2" and "Purpose 2" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Set defaults" "link" + And I click on "Activity modules" "link" + And I should see "Inherit" + And I should see "Add a new module default" + And I press "Add a new module default" + And I set the field "Activity module" to "Assignment" + And I set the field "Category" to "Category 1" + And I set the field "Purpose" to "Purpose 1" + And I click on "Reset instances with custom values" "checkbox" + When I press "Save changes" + Then I should see "Category 1" in the "Assignment" "table_row" + And I should see "Purpose 1" in the "Assignment" "table_row" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Science and technology" "link" + And I wait until the page is ready + And I click on "Courses" "link" + And I wait until the page is ready + And I click on "Physics 101" "link" + And I wait until the page is ready + And I click on "Activities and resources" "link" + And I wait until the page is ready + And I click on "Assignment 1 (Assignment)" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Not set (use the default value)" + And the field "purposeid" matches value "Not set (use the default value)" + And I should see "3 years (after the course end date)" + + Scenario: Set block category data registry defaults + Given I set the category and purpose for the "online_users" block in the "Physics 101" course to "Category 2" and "Purpose 2" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Set defaults" "link" + And I click on "Blocks" "link" + And I should see "Inherit" + And I should not see "Add a new module default" + And I press "Edit" + And I set the field "Category" to "Category 1" + And I set the field "Purpose" to "Purpose 1" + When I press "Save changes" + Then I should see "Category 1" + And I should see "Purpose 1" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Science and technology" "link" + And I wait until the page is ready + And I click on "Courses" "link" + And I wait until the page is ready + And I click on "Physics 101" "link" + And I wait until the page is ready + And I click on "Blocks" "link" + And I wait until the page is ready + And I click on "Online users" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Category 2" + And the field "purposeid" matches value "Purpose 2" + And I should see "5 years (after the course end date)" + + Scenario: Set course category data registry defaults with override + Given I set the category and purpose for the "online_users" block in the "Physics 101" course to "Category 2" and "Purpose 2" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Set defaults" "link" + And I click on "Blocks" "link" + And I should see "Inherit" + And I should not see "Add a new module default" + And I press "Edit" + And I set the field "Category" to "Category 1" + And I set the field "Purpose" to "Purpose 1" + And I click on "Reset instances with custom values" "checkbox" + When I press "Save changes" + Then I should see "Category 1" + And I should see "Purpose 1" + And I navigate to "Users > Privacy and policies > Data registry" in site administration + And I click on "Science and technology" "link" + And I wait until the page is ready + And I click on "Courses" "link" + And I wait until the page is ready + And I click on "Physics 101" "link" + And I wait until the page is ready + And I click on "Blocks" "link" + And I wait until the page is ready + And I click on "Online users" "link" + And I wait until the page is ready + And the field "categoryid" matches value "Not set (use the default value)" + And the field "purposeid" matches value "Not set (use the default value)" + And I should see "3 years (after the course end date)" diff --git a/admin/tool/dataprivacy/tests/generator/lib.php b/admin/tool/dataprivacy/tests/generator/lib.php new file mode 100644 index 00000000000..744e34a5b83 --- /dev/null +++ b/admin/tool/dataprivacy/tests/generator/lib.php @@ -0,0 +1,115 @@ +. + +/** + * Data privacy tool data generator. + * + * @package tool_dataprivacy + * @category test + * @copyright 2018 Jun Pataleta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use tool_dataprivacy\api; +use tool_dataprivacy\category; +use tool_dataprivacy\purpose; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Data privacy tool data generator class. + * + * @package tool_dataprivacy + * @category test + * @copyright 2018 Jun Pataleta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class tool_dataprivacy_generator extends component_generator_base { + + /** @var int Number of created categories. */ + protected $categorycount = 0; + + /** @var int Number of created purposes. */ + protected $purposecount = 0; + + /** + * Reset process. + * + * Do not call directly. + * + * @return void + */ + public function reset() { + $this->categorycount = 0; + $this->purposecount = 0; + } + + /** + * Create a new category. + * + * @param array|stdClass $record + * @return category + */ + public function create_category($record = null) { + $this->categorycount++; + $i = $this->categorycount; + $record = (object)$record; + + if (!isset($record->name)) { + $record->name = "Test purpose $i"; + } + + if (!isset($record->description)) { + $record->description = "{$record->name} description"; + } + + $category = api::create_category($record); + + return $category; + } + + /** + * Create a new purpose. + * + * @param array|stdClass $record + * @return purpose + */ + public function create_purpose($record = null) { + $this->purposecount++; + $i = $this->purposecount; + $record = (object)$record; + + if (!isset($record->name)) { + $record->name = "Test purpose $i"; + } + + if (!isset($record->description)) { + $record->description = "{$record->name} $i description"; + } + + if (!isset($record->retentionperiod)) { + $record->retentionperiod = 'PT1M'; + } + + if (!isset($record->lawfulbases)) { + $record->lawfulbases = 'gdpr_art_6_1_a'; + } + + $purpose = api::create_purpose($record); + + return $purpose; + } +}