From e106995599005786c73a3f2b9ad20d610740f788 Mon Sep 17 00:00:00 2001 From: yashodha Date: Mon, 25 Mar 2013 18:46:06 +0530 Subject: [PATCH] CRM-7564 --- CRM/Custom/Form/Field.php | 4 +- .../WebTest/Admin/CustomAddTestSameField.php | 166 ++++++++++++++++++ 2 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/WebTest/Admin/CustomAddTestSameField.php diff --git a/CRM/Custom/Form/Field.php b/CRM/Custom/Form/Field.php index 0b1d4bf8e9..567eafc4f7 100644 --- a/CRM/Custom/Form/Field.php +++ b/CRM/Custom/Form/Field.php @@ -549,10 +549,12 @@ class CRM_Custom_Form_Field extends CRM_Core_Form { //validate field label as well as name. $title = $fields['label']; $name = CRM_Utils_String::munge($title, '_', 64); - $query = 'select count(*) from civicrm_custom_field where ( name like %1 OR label like %2 ) and id != %3'; + $gId = $self->_gid; // CRM-7564 + $query = 'select count(*) from civicrm_custom_field where ( name like %1 OR label like %2 ) and id != %3 and custom_group_id = %4'; $fldCnt = CRM_Core_DAO::singleValueQuery($query, array(1 => array($name, 'String'), 2 => array($title, 'String'), 3 => array((int)$self->_id, 'Integer'), + 4 => array($gId, 'Integer'), )); if ($fldCnt) { $errors['label'] = ts('Custom field \'%1\' already exists in Database.', array(1 => $title)); diff --git a/tests/phpunit/WebTest/Admin/CustomAddTestSameField.php b/tests/phpunit/WebTest/Admin/CustomAddTestSameField.php new file mode 100644 index 0000000000..be76e76dd6 --- /dev/null +++ b/tests/phpunit/WebTest/Admin/CustomAddTestSameField.php @@ -0,0 +1,166 @@ +open($this->sboxPath); + $this->webtestLogin(); + + $this->_testCustomAdd(); + $this->_testCustomAdd(); + } + + function _testCustomAdd() { + //CRM-7564 : Different gropus can contain same custom fields + $this->open($this->sboxPath . "civicrm/admin/custom/group?action=add&reset=1"); + $this->waitForPageToLoad($this->getTimeoutMsec()); + + //fill custom group title + $customGroupTitle = 'custom_group' . substr(sha1(rand()), 0, 3); + $this->click("title"); + $this->type("title", $customGroupTitle); + + //custom group extends + $this->click("extends[0]"); + $this->select("extends[0]", "label=Contacts"); + $this->click("//option[@value='Contact']"); + $this->click("//form[@id='Group']/div[2]/div[3]/span[1]/input"); + $this->waitForPageToLoad($this->getTimeoutMsec()); + + //Is custom group created? + $this->assertTrue($this->isTextPresent("Your custom field set '$customGroupTitle' has been added. You can add custom fields now.")); + //add custom field - alphanumeric text + $textFieldLabel = 'test_text_field'; + $this->click("header"); + $this->type("label", $textFieldLabel); + $this->click("_qf_Field_next_new-bottom"); + $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->click("data_type[0]"); + $this->select("data_type[0]", "value=0"); + $this->click("//option[@value='0']"); + $this->click("data_type[1]"); + $this->select("data_type[1]", "label=CheckBox"); + $this->click("//option[@value='CheckBox']"); + + $checkboxFieldLabel = 'test_checkbox'; + $this->type("label", $checkboxFieldLabel); + $checkboxOptionLabel1 = 'check1'; + $this->type("option_label_1", $checkboxOptionLabel1); + $this->type("option_value_1", "1"); + $checkboxOptionLabel2 = 'check2'; + $this->type("option_label_2", $checkboxOptionLabel2); + $this->type("option_value_2", "2"); + $this->click("link=another choice"); + $checkboxOptionLabel3 = 'check3'; + $this->type("option_label_3", $checkboxOptionLabel3); + $this->type("option_value_3", "3"); + $this->click("link=another choice"); + $checkboxOptionLabel4 = 'check4'; + $this->type("option_label_4", $checkboxOptionLabel4); + $this->type("option_value_4", "4"); + + //enter options per line + $this->type("options_per_line", "2"); + + //enter pre help message + $this->type("help_pre", "this is field pre help"); + + //enter post help message + $this->type("help_post", "this field post help"); + + //Is searchable? + $this->click("is_searchable"); + + //clicking save + $this->click("_qf_Field_next_new-bottom"); + $this->waitForPageToLoad($this->getTimeoutMsec()); + + //Is custom field created? + $this->assertTrue($this->isTextPresent("Your custom field '$checkboxFieldLabel' has been saved.")); + + //add custom field - alphanumeric text + $textFieldLabel = 'test_text_field'; + $this->click("header"); + $this->type("label", $textFieldLabel); + $this->click("_qf_Field_next_new-bottom"); + + // Same group will not contain same custome fields so will show error for this field : + $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->click("data_type[0]"); + $this->select("data_type[0]", "value=0"); + $this->click("//option[@value='0']"); + $this->click("data_type[1]"); + $this->select("data_type[1]", "label=CheckBox"); + $this->click("//option[@value='CheckBox']"); + //Is custom field created + $this->assertTrue($this->isTextPresent("Custom field '$textFieldLabel' already exists in Database.")); + + //create another custom field - Number Radio + $this->click("data_type[0]"); + $this->select("data_type[0]", "value=2"); + $this->click("//option[@value='2']"); + $this->click("data_type[1]"); + $this->select("data_type[1]", "value=Radio"); + $this->click("//option[@value='Radio']"); + + $radioFieldLabel = 'test_radio'; + $this->type("label", $radioFieldLabel); + $radioOptionLabel1 = 'radio1'; + $this->type("option_label_1", $radioOptionLabel1); + $this->type("option_value_1", "1"); + $radioOptionLabel2 = 'radio2'; + $this->type("option_label_2", $radioOptionLabel2); + $this->type("option_value_2", "2"); + + //select options per line + $this->type("options_per_line", "3"); + + //enter pre help msg + $this->type("help_pre", "this is field pre help"); + + //enter post help msg + $this->type("help_post", "this is field post help"); + + //Is searchable? + $this->click("is_searchable"); + + //clicking save + $this->click("_qf_Field_next-bottom"); + $this->waitForPageToLoad($this->getTimeoutMsec()); + + //Is custom field created + $this->assertTrue($this->isTextPresent("Your custom field '$radioFieldLabel' has been saved.")); + + } +} + -- 2.25.1