CRM-7564
authoryashodha <yashodha.chaku@webaccess.co.in>
Mon, 25 Mar 2013 13:16:06 +0000 (18:46 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Mon, 25 Mar 2013 13:16:43 +0000 (18:46 +0530)
CRM/Custom/Form/Field.php
tests/phpunit/WebTest/Admin/CustomAddTestSameField.php [new file with mode: 0644]

index 0b1d4bf8e9ad4770d7c0b7f409f01cd628719e3a..567eafc4f77f89cdc7d325a14382d2b548907e7e 100644 (file)
@@ -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 (file)
index 0000000..be76e76
--- /dev/null
@@ -0,0 +1,166 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM 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 Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License along with this program; if not, contact CiviCRM LLC       |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+
+require_once 'CiviTest/CiviSeleniumTestCase.php';
+class WebTest_Admin_CustomAddTestSameField extends CiviSeleniumTestCase {
+
+  protected function setUp() {
+    parent::setUp();
+  }
+
+  function testCustomSameFieldAdd() {
+    $this->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.")); 
+    
+  } 
+}
+