Merge pull request #2564 from jaapjansma/CRM-14276
[civicrm-core.git] / tests / phpunit / WebTest / Grant / CustomFieldsetTest.php
index 369dee37364a6f7936266d4ce1a984233cbebfec..fb46ed31601e7c67b2bb83424a2caadd569291f9 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -24,7 +24,6 @@
  +--------------------------------------------------------------------+
 */
 
-
 require_once 'CiviTest/CiviSeleniumTestCase.php';
 class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
 
@@ -34,7 +33,7 @@ class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
 
   function testCustomFieldsetTest() {
     // Log in as admin first to verify permissions for CiviGrant
-    $this->webtestLogin(TRUE);
+    $this->webtestLogin('admin');
 
     // Enable CiviGrant module if necessary
     $this->enableComponents("CiviGrant");
@@ -43,18 +42,20 @@ class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
     $permission = array('edit-2-access-civigrant', 'edit-2-edit-grants', 'edit-2-delete-in-civigrant');
     $this->changePermissions($permission);
 
+    // Log in as normal user
+    $this->webtestLogin();
+
     // Create unique identifier for names
     $rand = substr(sha1(rand()), 0, 7);
 
     // Add new Grant Type
-    $this->openCiviPage('admin/options/grant_type', 'group=grant_type&reset=1');
-    $this->click("css=#grant_type > div.action-link > #new > span");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage('admin/options/grant_type', 'reset=1');
+    $this->click("xpath=//*[@id='crm-main-content-wrapper']/div[2]/div[1]/a");
+    $this->waitForElementPresent('_qf_Options_cancel-bottom');
     $grantType = 'GrantType' . $rand;
     $this->type('id=label', $grantType);
     $this->click('id=_qf_Options_next-top');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->assertElementContainsText('crm-notification-container', "The Grant Type '$grantType' has been saved.");
+    $this->waitForText('crm-notification-container', "The Grant Type '$grantType' has been saved.");
 
     // Create new Custom Field Set that extends the grant type
     $this->openCiviPage('admin/custom/group', 'reset=1');
@@ -67,7 +68,7 @@ class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
     $this->click('id=collapse_display');
     $this->click('id=_qf_Group_next-bottom');
     $this->waitForElementPresent('_qf_Field_next-bottom');
-    $this->assertElementContainsText('crm-notification-container', "Your custom field set '$grantFieldSet' has been added.");
+    $this->waitForText('crm-notification-container', "Your custom field set '$grantFieldSet' has been added.");
 
     // Add field to fieldset
     $grantField = 'GrantField' . $rand;
@@ -75,31 +76,23 @@ class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
     $this->select('id=data_type_0', 'label=Money');
     $this->click('id=_qf_Field_next-bottom');
     $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->assertElementContainsText('crm-notification-container', "Your custom field '$grantField' has been saved.");
+    $this->waitForText('crm-notification-container', "Custom field '$grantField' has been saved.");
 
     // Create new Grant
     $this->openCiviPage('grant/add', 'reset=1&action=add&context=standalone', '_qf_Grant_upload-bottom');
-    $this->select('id=profiles_1', 'label=New Individual');
-    $this->waitForElementPresent('_qf_Edit_next');
     $firstName = 'First' . $rand;
     $lastName = 'Last' . $rand;
-    $this->type('id=first_name', $firstName);
-    $this->type('id=last_name', $lastName);
-    $this->click('id=_qf_Edit_next');
+    $this->webtestNewDialogContact($firstName, $lastName);
     $this->select('id=status_id', 'label=Approved');
     $this->select('id=grant_type_id', "label=$grantType");
     $this->waitForTextPresent($grantField);
-    $this->assertElementContainsText($grantFieldSet, $grantField);
+    $this->assertElementContainsText("xpath=//div[@id='customData']/div[@class='custom-group custom-group-$grantFieldSet crm-accordion-wrapper ']", $grantField);
     $this->type('id=amount_total', '100.00');
-    $this->type("css=div#$grantFieldSet input.form-text", '99.99');
-    $this->click('id=_qf_Grant_upload-bottom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-
-    // Verify grant is created with presence of view link
-    $this->waitForElementPresent("xpath=//div[@id='Grants']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
+    $this->type("xpath=//div[@id='customData']/div[@class='custom-group custom-group-$grantFieldSet crm-accordion-wrapper ']/div[@class='crm-accordion-body']/table/tbody/tr/td[2]/input[@class='crm-form-text']", '99.99');
+    $this->clickLink('id=_qf_Grant_upload-bottom', "xpath=//div[@class='view-content']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
 
     // Click through to the Grant view screen
-    $this->click("xpath=//div[@id='Grants']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
+    $this->click("xpath=//div[@class='view-content']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
     $this->waitForElementPresent('_qf_GrantView_cancel-bottom');
 
     // verify tabular data for grant view
@@ -111,5 +104,20 @@ class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
      )
     );
   }
-}
 
+  function testAjaxCustomGroupLoad() {
+    $this->webtestLogin();
+
+    // Enable CiviGrant module if necessary
+    $this->enableComponents("CiviGrant");
+
+    $triggerElement = array('name' => 'grant_type_id', 'type' => 'select');
+    $customSets = array(
+      array('entity' => 'Grant', 'subEntity' => 'Emergency', 'triggerElement' => $triggerElement),
+      array('entity' => 'Grant', 'subEntity' => 'Family Support', 'triggerElement' => $triggerElement)
+    );
+
+    $pageUrl = array('url' => 'grant/add', 'args' => 'reset=1&action=add&context=standalone');
+    $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
+  }
+}