From f15d0b00dff695bd4759310a5d08031da112d495 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Fri, 22 Mar 2024 12:50:10 +1100 Subject: [PATCH 1/2] issue #55: fix broken checkbox field --- .../condition/cohort_field.php | 24 ++--- .../condition/fields_trait.php | 40 +++++++-- .../condition/user_profile.php | 34 +++---- lang/en/tool_dynamic_cohorts.php | 1 + .../condition/cohort_field_test.php | 90 +++++++++++++++---- .../condition/user_custom_profile_test.php | 67 ++++++++------ .../condition/user_profile_test.php | 34 +++---- 7 files changed, 183 insertions(+), 107 deletions(-) diff --git a/classes/local/tool_dynamic_cohorts/condition/cohort_field.php b/classes/local/tool_dynamic_cohorts/condition/cohort_field.php index f34a390..9cc1bf6 100644 --- a/classes/local/tool_dynamic_cohorts/condition/cohort_field.php +++ b/classes/local/tool_dynamic_cohorts/condition/cohort_field.php @@ -330,33 +330,21 @@ protected function get_cohort_operator_value() { */ public function get_config_description(): string { $cohortoperator = $this->get_cohort_operators()[$this->get_cohort_operator_value()]; - $fieldname = $this->get_field_name(); + $configuredfieldname = $this->get_field_name(); - if (empty($fieldname)) { + if (empty($configuredfieldname)) { return ''; } - $fieldinfo = $this->get_fields_info()[$fieldname]; + $fieldinfo = $this->get_fields_info()[$configuredfieldname]; + $displayedfieldname = $this->get_field_name_text(); $fieldoperator = $this->get_operator_text($fieldinfo->datatype); - $fieldvalue = $this->get_field_value(); - if ($fieldname == 'contextid') { - $fieldvalue = $this->get_category_options()[$fieldvalue]; - } - - if (in_array($this->get_operator_value(), [self::TEXT_IS_EMPTY, self::TEXT_IS_NOT_EMPTY])) { - $fieldvalue = null; - } - - if ($fieldinfo->datatype === self::FIELD_DATA_TYPE_SELECT) { - $fieldvalue = $fieldinfo->param1[$fieldvalue]; - } - - $fieldname = $fieldinfo->name; + $fieldvalue = $this->get_field_value_text(); $description = get_string('condition:cohort_field_description', 'tool_dynamic_cohorts', (object)[ 'operator' => $cohortoperator, - 'field' => $fieldname, + 'field' => $displayedfieldname, 'fieldoperator' => $fieldoperator, 'fieldvalue' => $fieldvalue, ]); diff --git a/classes/local/tool_dynamic_cohorts/condition/fields_trait.php b/classes/local/tool_dynamic_cohorts/condition/fields_trait.php index 0cee639..602b0b5 100644 --- a/classes/local/tool_dynamic_cohorts/condition/fields_trait.php +++ b/classes/local/tool_dynamic_cohorts/condition/fields_trait.php @@ -80,15 +80,43 @@ protected function get_field_value(): ?string { $fieldvalue = $configdata[$field . '_value']; } - // A special case for checkbox field. + return $fieldvalue; + } + + /** + * Return the field name as a text. + * + * @return string + */ + protected function get_field_name_text(): string { + return $this->get_fields_info()[$this->get_field_name()]->name ?? '-'; + } + + /** + * Return a field value as a human-readable text. + * + * @return string|null + */ + protected function get_field_value_text(): ?string { $fieldname = $this->get_field_name(); - if (!empty($fieldname) && !empty($this->get_fields_info()[$fieldname])) { - $datatype = $this->get_fields_info()[$fieldname]->datatype; - if ($datatype == self::FIELD_DATA_TYPE_CHECKBOX) { - $fieldvalue = empty($fieldvalue) ? get_string('no') : get_string('yes'); + $fieldvalue = $this->get_field_value(); + $fieldinfo = $this->get_fields_info(); + + if (!empty($fieldname) && !empty($fieldinfo[$fieldname])) { + switch ($fieldinfo[$fieldname]->datatype) { + case self::FIELD_DATA_TYPE_SELECT: + case self::FIELD_DATA_TYPE_MENU: + case self::FIELD_DATA_TYPE_CHECKBOX: + $fieldvalue = $fieldinfo[$fieldname]->param1[$fieldvalue]; + break; + } } + if (in_array($this->get_operator_value(), [self::TEXT_IS_EMPTY, self::TEXT_IS_NOT_EMPTY])) { + $fieldvalue = null; + } + return $fieldvalue; } @@ -102,7 +130,7 @@ protected function get_operator_value(): int { } /** - * Returns a text for the configured operator based on a field data type. + * Returns a human-readable text for the configured operator based on a field data type. * * @param string $fielddatatype Field data type. * @return string diff --git a/classes/local/tool_dynamic_cohorts/condition/user_profile.php b/classes/local/tool_dynamic_cohorts/condition/user_profile.php index 5142bd1..a4451f5 100644 --- a/classes/local/tool_dynamic_cohorts/condition/user_profile.php +++ b/classes/local/tool_dynamic_cohorts/condition/user_profile.php @@ -174,40 +174,30 @@ protected function get_fields_info(): array { return $fields; } - /** - * Return the field name as a text. - * - * @return string - */ - protected function get_field_text(): string { - return $this->get_fields_info()[$this->get_field_name()]->name ?? '-'; - } - /** * Human-readable description of the configured condition. * * @return string */ public function get_config_description(): string { - $fieldname = $this->get_field_name(); - if (empty($fieldname)) { + $configuredfieldname = $this->get_field_name(); + + if (empty($configuredfieldname)) { return ''; } - $datatype = $this->get_fields_info()[$fieldname]->datatype; + $fieldinfo = $this->get_fields_info()[$configuredfieldname]; + $displayedfieldname = $this->get_field_name_text(); + $fieldoperator = $this->get_operator_text($fieldinfo->datatype); - if (in_array($this->get_operator_value(), [self::TEXT_IS_EMPTY, self::TEXT_IS_NOT_EMPTY])) { - return $this->get_field_text() . ' ' . $this->get_operator_text($datatype); - } else { - $fieldvalue = $this->get_field_value(); - if ($fieldname == 'auth') { - $authplugins = core_plugin_manager::instance()->get_plugins_of_type('auth'); - $fieldvalue = $authplugins[$fieldvalue]->displayname; - } + $fieldvalue = $this->get_field_value_text(); - return $this->get_field_text() . ' '. $this->get_operator_text($datatype) . ' ' . $fieldvalue; - } + return get_string('condition:profile_field_description', 'tool_dynamic_cohorts', (object)[ + 'field' => $displayedfieldname, + 'fieldoperator' => $fieldoperator, + 'fieldvalue' => $fieldvalue, + ]); } /** diff --git a/lang/en/tool_dynamic_cohorts.php b/lang/en/tool_dynamic_cohorts.php index 6854e88..407187e 100644 --- a/lang/en/tool_dynamic_cohorts.php +++ b/lang/en/tool_dynamic_cohorts.php @@ -49,6 +49,7 @@ $string['condition:cohort_membership_broken_description'] = 'Condition is broken. Using the same cohort that the given rule is configured to manage to.'; $string['condition:cohort_field'] = 'Cohort field'; $string['condition:cohort_field_description'] = 'A user {$a->operator} cohorts with field \'{$a->field}\' {$a->fieldoperator} {$a->fieldvalue}'; +$string['condition:profile_field_description'] = '{$a->field} {$a->fieldoperator} {$a->fieldvalue}'; $string['condition:user_profile'] = 'User standard profile field'; $string['condition:user_custom_profile'] = 'User custom profile field'; $string['cf_include_missing_data'] = 'Include cohorts with missing data.'; diff --git a/tests/local/tool_dynamic_cohorts/condition/cohort_field_test.php b/tests/local/tool_dynamic_cohorts/condition/cohort_field_test.php index 94192fa..931e315 100644 --- a/tests/local/tool_dynamic_cohorts/condition/cohort_field_test.php +++ b/tests/local/tool_dynamic_cohorts/condition/cohort_field_test.php @@ -272,7 +272,17 @@ public function test_get_sql_data_standard_fields() { * * @return \core_customfield\field_controller */ - protected function create_cohort_custom_field(): \core_customfield\field_controller { + + /** + * Create cohort custom field for testing. + * + * @param string $shortname Field shortname + * @param string $datatype $field data type. + * + * @return \core_customfield\field_controller + */ + protected function create_cohort_custom_field(string $shortname = 'testfield1', + string $datatype = 'text'): \core_customfield\field_controller { $fieldcategory = self::getDataGenerator()->create_custom_field_category([ 'component' => 'core_cohort', 'area' => 'cohort', @@ -280,9 +290,9 @@ protected function create_cohort_custom_field(): \core_customfield\field_control ]); return self::getDataGenerator()->create_custom_field([ - 'shortname' => 'testfield1', + 'shortname' => $shortname, 'name' => 'Custom field', - 'type' => 'text', + 'type' => $datatype, 'categoryid' => $fieldcategory->get('id'), ]); } @@ -309,6 +319,32 @@ public function test_config_description_custom_field() { 'A user is member of cohorts with field \'Custom field\' is equal to Test value', $condition->get_config_description() ); + + $checkboxfield = $this->create_cohort_custom_field('checkboxfield', 'checkbox'); + $checkboxfieldname = cohort_field::CUSTOM_FIELD_PREFIX . $checkboxfield->get('shortname'); + $condition = $this->get_condition([ + 'cohort_field_operator' => cohort_field::OPERATOR_IS_MEMBER_OF, + 'cohort_field_field' => $checkboxfieldname, + $checkboxfieldname . '_operator' => condition_base::TEXT_IS_EQUAL_TO, + $checkboxfieldname . '_value' => 1, + ]); + + $this->assertSame( + 'A user is member of cohorts with field \'Custom field\' is equal to Yes', + $condition->get_config_description() + ); + + $condition = $this->get_condition([ + 'cohort_field_operator' => cohort_field::OPERATOR_IS_MEMBER_OF, + 'cohort_field_field' => $checkboxfieldname, + $checkboxfieldname . '_operator' => condition_base::TEXT_IS_EQUAL_TO, + $checkboxfieldname . '_value' => 0, + ]); + + $this->assertSame( + 'A user is member of cohorts with field \'Custom field\' is equal to No', + $condition->get_config_description() + ); } /** @@ -326,9 +362,13 @@ public function test_get_sql_data_custom_fields() { // We need admin to be able to add custom fields data for cohorts. $this->setAdminUser(); - $this->create_cohort_custom_field(); + $textfield = $this->create_cohort_custom_field(); + $checkboxfield = $this->create_cohort_custom_field('checkboxfield', 'checkbox'); - $cohort1 = $this->getDataGenerator()->create_cohort(['customfield_testfield1' => 'Test value 1']); + $cohort1 = $this->getDataGenerator()->create_cohort([ + 'customfield_' . $textfield->get('shortname') => 'Test value 1', + 'customfield_' . $checkboxfield->get('shortname') => '1', + ]); $cohort2 = $this->getDataGenerator()->create_cohort(); $user1 = $this->getDataGenerator()->create_user(); @@ -340,13 +380,15 @@ public function test_get_sql_data_custom_fields() { cohort_add_member($cohort2->id, $user3->id); $totalusers = $DB->count_records('user'); + $textfieldname = cohort_field::CUSTOM_FIELD_PREFIX . $textfield->get('shortname'); + $checkboxfieldname = cohort_field::CUSTOM_FIELD_PREFIX . $checkboxfield->get('shortname'); // User 1 and user 2 as they are members of cohort 1. $condition = $this->get_condition([ 'cohort_field_operator' => cohort_field::OPERATOR_IS_MEMBER_OF, - 'cohort_field_field' => cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1', - cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1_operator' => condition_base::TEXT_IS_EQUAL_TO, - cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1_value' => 'Test value 1', + 'cohort_field_field' => $textfieldname, + $textfieldname . '_operator' => condition_base::TEXT_IS_EQUAL_TO, + $textfieldname . '_value' => 'Test value 1', ]); $result = $condition->get_sql(); @@ -356,9 +398,9 @@ public function test_get_sql_data_custom_fields() { // Everyone except user 1 and user 2 as they are member of cohort 1. $condition = $this->get_condition([ 'cohort_field_operator' => cohort_field::OPERATOR_IS_NOT_MEMBER_OF, - 'cohort_field_field' => cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1', - cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1_operator' => condition_base::TEXT_IS_EQUAL_TO, - cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1_value' => 'Test value 1', + 'cohort_field_field' => $textfieldname, + $textfieldname . '_operator' => condition_base::TEXT_IS_EQUAL_TO, + $textfieldname . '_value' => 'Test value 1', ]); $result = $condition->get_sql(); @@ -368,9 +410,9 @@ public function test_get_sql_data_custom_fields() { // Everyone as cohort is empty. $condition = $this->get_condition([ 'cohort_field_operator' => cohort_field::OPERATOR_IS_NOT_MEMBER_OF, - 'cohort_field_field' => cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1', - cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1_operator' => condition_base::TEXT_IS_EQUAL_TO, - cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1_value' => 'Test value 2', + 'cohort_field_field' => $textfieldname, + $textfieldname . '_operator' => condition_base::TEXT_IS_EQUAL_TO, + $textfieldname . '_value' => 'Test value 2', ]); $result = $condition->get_sql(); @@ -380,15 +422,27 @@ public function test_get_sql_data_custom_fields() { // User 1, user 2 and user 3 as they are members of cohort 1 and cohort 2 (this one is with missing custom field data). $condition = $this->get_condition([ 'cohort_field_operator' => cohort_field::OPERATOR_IS_MEMBER_OF, - 'cohort_field_field' => cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1', - cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1_operator' => condition_base::TEXT_IS_EQUAL_TO, - cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1_value' => 'Test value 1', - cohort_field::CUSTOM_FIELD_PREFIX . 'testfield1_include_missing_data' => '1', + 'cohort_field_field' => $textfieldname, + $textfieldname . '_operator' => condition_base::TEXT_IS_EQUAL_TO, + $textfieldname . '_value' => 'Test value 1', + $textfieldname . '_include_missing_data' => '1', ]); $result = $condition->get_sql(); $sql = "SELECT u.id FROM {user} u {$result->get_join()} WHERE {$result->get_where()}"; $this->assertCount(3, $DB->get_records_sql($sql, $result->get_params())); + + // User 1 and user 2 as they are members of cohort 1. + $condition = $this->get_condition([ + 'cohort_field_operator' => cohort_field::OPERATOR_IS_MEMBER_OF, + 'cohort_field_field' => $checkboxfieldname, + $checkboxfieldname . '_operator' => condition_base::TEXT_IS_EQUAL_TO, + $checkboxfieldname . '_value' => 1, + ]); + + $result = $condition->get_sql(); + $sql = "SELECT u.id FROM {user} u {$result->get_join()} WHERE {$result->get_where()}"; + $this->assertCount(2, $DB->get_records_sql($sql, $result->get_params())); } /** diff --git a/tests/local/tool_dynamic_cohorts/condition/user_custom_profile_test.php b/tests/local/tool_dynamic_cohorts/condition/user_custom_profile_test.php index 564297d..f30bc60 100644 --- a/tests/local/tool_dynamic_cohorts/condition/user_custom_profile_test.php +++ b/tests/local/tool_dynamic_cohorts/condition/user_custom_profile_test.php @@ -150,14 +150,14 @@ public function test_set_and_get_configdata() { */ public function config_description_data_provider(): array { return [ - [user_profile::TEXT_CONTAINS, 'Test field1 contains 123', true], - [user_profile::TEXT_DOES_NOT_CONTAIN, 'Test field1 doesn\'t contain 123', true], - [user_profile::TEXT_IS_EQUAL_TO, 'Test field1 is equal to 123', true], - [user_profile::TEXT_IS_NOT_EQUAL_TO, 'Test field1 isn\'t equal to 123', true], - [user_profile::TEXT_STARTS_WITH, 'Test field1 starts with 123', true], - [user_profile::TEXT_ENDS_WITH, 'Test field1 ends with 123', true], - [user_profile::TEXT_IS_EMPTY, 'Test field1 is empty', true], - [user_profile::TEXT_IS_NOT_EMPTY, 'Test field1 is not empty', true], + [condition_base::TEXT_CONTAINS, 'Test field1 contains 123', true], + [condition_base::TEXT_DOES_NOT_CONTAIN, 'Test field1 doesn\'t contain 123', true], + [condition_base::TEXT_IS_EQUAL_TO, 'Test field1 is equal to 123', true], + [condition_base::TEXT_IS_NOT_EQUAL_TO, 'Test field1 isn\'t equal to 123', true], + [condition_base::TEXT_STARTS_WITH, 'Test field1 starts with 123', true], + [condition_base::TEXT_ENDS_WITH, 'Test field1 ends with 123', true], + [condition_base::TEXT_IS_EMPTY, 'Test field1 is empty ', true], + [condition_base::TEXT_IS_NOT_EMPTY, 'Test field1 is not empty ', true], ]; } @@ -208,25 +208,28 @@ public function test_get_sql_data() { $this->resetAfterTest(); - $field1 = $this->add_user_profile_field('field1', 'text'); - $field2 = $this->add_user_profile_field('field2', 'text', ['param1' => "Opt 1\nOpt 2\nOpt 3"]); + $fieldtext1 = $this->add_user_profile_field('field1', 'text'); + $fieldtext2 = $this->add_user_profile_field('field2', 'text', ['param1' => "Opt 1\nOpt 2\nOpt 3"]); + $fieldcheckbox = $this->add_user_profile_field('field3', 'checkbox'); $user1 = $this->getDataGenerator()->create_user(['username' => 'user1']); - profile_save_data((object)['id' => $user1->id, 'profile_field_' . $field1->shortname => 'User 1 Field 1']); - profile_save_data((object)['id' => $user1->id, 'profile_field_' . $field2->shortname => 'Opt 1']); + profile_save_data((object)['id' => $user1->id, 'profile_field_' . $fieldtext1->shortname => 'User 1 Field 1']); + profile_save_data((object)['id' => $user1->id, 'profile_field_' . $fieldtext2->shortname => 'Opt 1']); + profile_save_data((object)['id' => $user1->id, 'profile_field_' . $fieldcheckbox->shortname => '1']); $user2 = $this->getDataGenerator()->create_user(['username' => 'user2']); - profile_save_data((object)['id' => $user2->id, 'profile_field_' . $field1->shortname => 'User 2 Field 1']); - profile_save_data((object)['id' => $user2->id, 'profile_field_' . $field2->shortname => 'Opt 2']); + profile_save_data((object)['id' => $user2->id, 'profile_field_' . $fieldtext1->shortname => 'User 2 Field 1']); + profile_save_data((object)['id' => $user2->id, 'profile_field_' . $fieldtext2->shortname => 'Opt 2']); + profile_save_data((object)['id' => $user2->id, 'profile_field_' . $fieldcheckbox->shortname => '0']); $totalusers = $DB->count_records('user'); $condition = $this->get_condition(); - $fieldname = 'profile_field_' . $field1->shortname; + $fieldname = 'profile_field_' . $fieldtext1->shortname; $condition->set_config_data([ 'profilefield' => $fieldname, - $fieldname . '_operator' => user_profile::TEXT_ENDS_WITH, + $fieldname . '_operator' => condition_base::TEXT_ENDS_WITH, $fieldname . '_value' => 'Field 1', ]); @@ -234,10 +237,10 @@ public function test_get_sql_data() { $sql = "SELECT u.id FROM {user} u {$result->get_join()} WHERE {$result->get_where()}"; $this->assertCount(2, $DB->get_records_sql($sql, $result->get_params())); - $fieldname = 'profile_field_' . $field2->shortname; + $fieldname = 'profile_field_' . $fieldtext2->shortname; $condition->set_config_data([ 'profilefield' => $fieldname, - $fieldname . '_operator' => user_profile::TEXT_IS_NOT_EQUAL_TO, + $fieldname . '_operator' => condition_base::TEXT_IS_NOT_EQUAL_TO, $fieldname . '_value' => 'Opt 1', ]); @@ -245,10 +248,10 @@ public function test_get_sql_data() { $sql = "SELECT u.id FROM {user} u {$result->get_join()} WHERE {$result->get_where()}"; $this->assertCount(1, $DB->get_records_sql($sql, $result->get_params())); - $fieldname = 'profile_field_' . $field2->shortname; + $fieldname = 'profile_field_' . $fieldtext2->shortname; $condition->set_config_data([ 'profilefield' => $fieldname, - $fieldname . '_operator' => user_profile::TEXT_IS_NOT_EQUAL_TO, + $fieldname . '_operator' => condition_base::TEXT_IS_NOT_EQUAL_TO, $fieldname . '_value' => 'Opt 1', 'include_missing_data' => 1, ]); @@ -257,10 +260,10 @@ public function test_get_sql_data() { $sql = "SELECT u.id FROM {user} u {$result->get_join()} WHERE {$result->get_where()}"; $this->assertCount($totalusers - 1, $DB->get_records_sql($sql, $result->get_params())); - $fieldname = 'profile_field_' . $field2->shortname; + $fieldname = 'profile_field_' . $fieldtext2->shortname; $condition->set_config_data([ 'profilefield' => $fieldname, - $fieldname . '_operator' => user_profile::TEXT_IS_NOT_EQUAL_TO, + $fieldname . '_operator' => condition_base::TEXT_IS_NOT_EQUAL_TO, $fieldname . '_value' => 'Opt 1', 'include_missing_data' => 1, ]); @@ -268,6 +271,18 @@ public function test_get_sql_data() { $result = $condition->get_sql(); $sql = "SELECT u.id FROM {user} u {$result->get_join()} WHERE {$result->get_where()}"; $this->assertCount($totalusers - 1, $DB->get_records_sql($sql, $result->get_params())); + + $fieldname = 'profile_field_' . $fieldcheckbox->shortname; + $condition->set_config_data([ + 'profilefield' => $fieldname, + $fieldname . '_operator' => condition_base::TEXT_IS_EQUAL_TO, + $fieldname . '_value' => '1', + 'include_missing_data' => 0, + ]); + + $result = $condition->get_sql(); + $sql = "SELECT u.id FROM {user} u {$result->get_join()} WHERE {$result->get_where()}"; + $this->assertCount(1, $DB->get_records_sql($sql, $result->get_params())); } /** @@ -297,14 +312,14 @@ public function test_is_broken() { $condition->set_config_data([ 'profilefield' => $fieldname, - $fieldname . '_operator' => user_profile::TEXT_IS_EMPTY, + $fieldname . '_operator' => condition_base::TEXT_IS_EMPTY, $fieldname . '_value' => '', ]); $this->assertFalse($condition->is_broken()); $condition->set_config_data([ 'profilefield' => $fieldname, - $fieldname . '_operator' => user_profile::TEXT_IS_NOT_EMPTY, + $fieldname . '_operator' => condition_base::TEXT_IS_NOT_EMPTY, $fieldname . '_value' => '', ]); $this->assertFalse($condition->is_broken()); @@ -312,7 +327,7 @@ public function test_is_broken() { // Break condition. $condition->set_config_data([ 'profilefield' => $fieldname, - $fieldname . '_operator' => user_profile::TEXT_IS_EQUAL_TO, + $fieldname . '_operator' => condition_base::TEXT_IS_EQUAL_TO, $fieldname . '_value' => '', ]); $this->assertTrue($condition->is_broken()); @@ -320,7 +335,7 @@ public function test_is_broken() { // Break condition. $condition->set_config_data([ 'profilefield' => 'notexisting', - $fieldname . '_operator' => user_profile::TEXT_IS_EQUAL_TO, + $fieldname . '_operator' => condition_base::TEXT_IS_EQUAL_TO, $fieldname . '_value' => '123', ]); $this->assertTrue($condition->is_broken()); diff --git a/tests/local/tool_dynamic_cohorts/condition/user_profile_test.php b/tests/local/tool_dynamic_cohorts/condition/user_profile_test.php index 3971fc8..9cf0c88 100644 --- a/tests/local/tool_dynamic_cohorts/condition/user_profile_test.php +++ b/tests/local/tool_dynamic_cohorts/condition/user_profile_test.php @@ -90,14 +90,14 @@ public function test_set_and_get_configdata() { */ public function config_description_data_provider(): array { return [ - [user_profile::TEXT_CONTAINS, 'First name contains 123'], - [user_profile::TEXT_DOES_NOT_CONTAIN, 'First name doesn\'t contain 123'], - [user_profile::TEXT_IS_EQUAL_TO, 'First name is equal to 123'], - [user_profile::TEXT_IS_NOT_EQUAL_TO, 'First name isn\'t equal to 123'], - [user_profile::TEXT_STARTS_WITH, 'First name starts with 123'], - [user_profile::TEXT_ENDS_WITH, 'First name ends with 123'], - [user_profile::TEXT_IS_EMPTY, 'First name is empty'], - [user_profile::TEXT_IS_NOT_EMPTY, 'First name is not empty'], + [condition_base::TEXT_CONTAINS, 'First name contains 123'], + [condition_base::TEXT_DOES_NOT_CONTAIN, 'First name doesn\'t contain 123'], + [condition_base::TEXT_IS_EQUAL_TO, 'First name is equal to 123'], + [condition_base::TEXT_IS_NOT_EQUAL_TO, 'First name isn\'t equal to 123'], + [condition_base::TEXT_STARTS_WITH, 'First name starts with 123'], + [condition_base::TEXT_ENDS_WITH, 'First name ends with 123'], + [condition_base::TEXT_IS_EMPTY, 'First name is empty '], + [condition_base::TEXT_IS_NOT_EMPTY, 'First name is not empty '], ]; } @@ -124,7 +124,7 @@ public function test_config_description(int $operator, string $expected) { public function test_config_description_for_auth_field() { $instance = $this->get_condition([ 'profilefield' => 'auth', - 'auth_operator' => user_profile::TEXT_IS_EQUAL_TO, + 'auth_operator' => condition_base::TEXT_IS_EQUAL_TO, 'auth_value' => 'manual', ]); @@ -144,7 +144,7 @@ public function test_get_sql_data() { $condition = $this->get_condition([ 'profilefield' => 'username', - 'username_operator' => user_profile::TEXT_IS_EQUAL_TO, + 'username_operator' => condition_base::TEXT_IS_EQUAL_TO, 'username_value' => 'user1username', ]); @@ -154,7 +154,7 @@ public function test_get_sql_data() { $condition->set_config_data([ 'profilefield' => 'username', - 'username_operator' => user_profile::TEXT_STARTS_WITH, + 'username_operator' => condition_base::TEXT_STARTS_WITH, 'username_value' => 'user', ]); @@ -164,7 +164,7 @@ public function test_get_sql_data() { $condition->set_config_data([ 'profilefield' => 'username', - 'username_operator' => user_profile::TEXT_ENDS_WITH, + 'username_operator' => condition_base::TEXT_ENDS_WITH, 'username_value' => 'username', ]); @@ -174,7 +174,7 @@ public function test_get_sql_data() { $condition->set_config_data([ 'profilefield' => 'username', - 'username_operator' => user_profile::TEXT_IS_NOT_EQUAL_TO, + 'username_operator' => condition_base::TEXT_IS_NOT_EQUAL_TO, 'username_value' => 'user1username', ]); @@ -205,14 +205,14 @@ public function test_is_broken() { $condition->set_config_data([ 'profilefield' => 'username', - 'username_operator' => user_profile::TEXT_IS_EMPTY, + 'username_operator' => condition_base::TEXT_IS_EMPTY, 'username_value' => '', ]); $this->assertFalse($condition->is_broken()); $condition->set_config_data([ 'profilefield' => 'username', - 'username_operator' => user_profile::TEXT_IS_NOT_EMPTY, + 'username_operator' => condition_base::TEXT_IS_NOT_EMPTY, 'username_value' => '', ]); $this->assertFalse($condition->is_broken()); @@ -220,7 +220,7 @@ public function test_is_broken() { // Break condition. $condition->set_config_data([ 'profilefield' => 'username', - 'username_operator' => user_profile::TEXT_IS_EQUAL_TO, + 'username_operator' => condition_base::TEXT_IS_EQUAL_TO, 'username_value' => '', ]); $this->assertTrue($condition->is_broken()); @@ -228,7 +228,7 @@ public function test_is_broken() { // Break condition. $condition->set_config_data([ 'profilefield' => 'notexisting', - 'username_operator' => user_profile::TEXT_IS_EQUAL_TO, + 'username_operator' => condition_base::TEXT_IS_EQUAL_TO, 'username_value' => '123', ]); $this->assertTrue($condition->is_broken()); From 5d7d60f8f716125864c59b1dfa947fe181467b80 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Fri, 22 Mar 2024 12:54:50 +1100 Subject: [PATCH 2/2] issue #55: version bump --- version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.php b/version.php index 17a8ecf..7ecb9ae 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'tool_dynamic_cohorts'; -$plugin->release = 2024030801; -$plugin->version = 2024030801; +$plugin->release = 2024032200; +$plugin->version = 2024032200; $plugin->requires = 2022112800; $plugin->supported = [401, 403]; $plugin->maturity = MATURITY_ALPHA;