Merge pull request #3196 from JoeMurray/master
[civicrm-core.git] / tests / phpunit / WebTest / Grant / CustomFieldsetTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testCustomFieldsetTest() {
35 // Log in as admin first to verify permissions for CiviGrant
36 $this->webtestLogin('admin');
37
38 // Enable CiviGrant module if necessary
39 $this->enableComponents("CiviGrant");
40
41 // let's give full CiviGrant permissions to demo user (registered user).
42 $permission = array('edit-2-access-civigrant', 'edit-2-edit-grants', 'edit-2-delete-in-civigrant');
43 $this->changePermissions($permission);
44
45 // Log in as normal user
46 $this->webtestLogin();
47
48 // Create unique identifier for names
49 $rand = substr(sha1(rand()), 0, 7);
50
51 // Add new Grant Type
52 $this->openCiviPage('admin/options/grant_type', 'reset=1');
53 $this->click("xpath=//*[@id='crm-main-content-wrapper']/div[2]/div[1]/a");
54 $this->waitForElementPresent('_qf_Options_cancel-bottom');
55 $grantType = 'GrantType' . $rand;
56 $this->type('id=label', $grantType);
57 $this->click('id=_qf_Options_next-top');
58 $this->waitForText('crm-notification-container', "The Grant Type '$grantType' has been saved.");
59
60 // Create new Custom Field Set that extends the grant type
61 $this->openCiviPage('admin/custom/group', 'reset=1');
62 $this->click("css=#newCustomDataGroup > span");
63 $this->waitForElementPresent('_qf_Group_next-bottom');
64 $grantFieldSet = 'Fieldset' . $rand;
65 $this->type('id=title', $grantFieldSet);
66 $this->select('id=extends_0', 'label=Grants');
67 $this->addSelection('id=extends_1', "label=$grantType");
68 $this->click('id=collapse_display');
69 $this->click('id=_qf_Group_next-bottom');
70 $this->waitForElementPresent('_qf_Field_next-bottom');
71 $this->waitForText('crm-notification-container', "Your custom field set '$grantFieldSet' has been added.");
72
73 // Add field to fieldset
74 $grantField = 'GrantField' . $rand;
75 $this->type('id=label', $grantField);
76 $this->select('id=data_type_0', 'label=Money');
77 $this->click('id=_qf_Field_next-bottom');
78 $this->waitForPageToLoad($this->getTimeoutMsec());
79 $this->waitForText('crm-notification-container', "Custom field '$grantField' has been saved.");
80
81 // Create new Grant
82 $this->openCiviPage('grant/add', 'reset=1&action=add&context=standalone', '_qf_Grant_upload-bottom');
83 $firstName = 'First' . $rand;
84 $lastName = 'Last' . $rand;
85 $this->webtestNewDialogContact($firstName, $lastName);
86 $this->select('id=status_id', 'label=Approved');
87 $this->select('id=grant_type_id', "label=$grantType");
88 $this->waitForTextPresent($grantField);
89 $this->assertElementContainsText("xpath=//div[@id='customData']/div[@class='custom-group custom-group-$grantFieldSet crm-accordion-wrapper ']", $grantField);
90 $this->type('id=amount_total', '100.00');
91 $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');
92 $this->clickLink('id=_qf_Grant_upload-bottom', "xpath=//div[@class='view-content']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
93
94 // Click through to the Grant view screen
95 $this->click("xpath=//div[@class='view-content']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
96 $this->waitForElementPresent('_qf_GrantView_cancel-bottom');
97
98 // verify tabular data for grant view
99 $this->webtestVerifyTabularData(array(
100 'Name' => "$firstName $lastName",
101 'Grant Status' => 'Approved',
102 'Grant Type' => $grantType,
103 $grantField => '$ 99.99',
104 )
105 );
106 }
107
108 function testAjaxCustomGroupLoad() {
109 $this->webtestLogin();
110
111 // Enable CiviGrant module if necessary
112 $this->enableComponents("CiviGrant");
113
114 $triggerElement = array('name' => 'grant_type_id', 'type' => 'select');
115 $customSets = array(
116 array('entity' => 'Grant', 'subEntity' => 'Emergency', 'triggerElement' => $triggerElement),
117 array('entity' => 'Grant', 'subEntity' => 'Family Support', 'triggerElement' => $triggerElement)
118 );
119
120 $pageUrl = array('url' => 'grant/add', 'args' => 'reset=1&action=add&context=standalone');
121 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
122 }
123 }