Merge pull request #5453 from colemanw/CRM-16148
[civicrm-core.git] / tests / phpunit / WebTest / Grant / CustomFieldsetTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Grant_CustomFieldsetTest
31 */
6a488035
TO
32class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testCustomFieldsetTest() {
6a488035 39 // Log in as admin first to verify permissions for CiviGrant
42daf119 40 $this->webtestLogin('admin');
6a488035
TO
41
42 // Enable CiviGrant module if necessary
b9715b8a 43 $this->enableComponents("CiviGrant");
6a488035
TO
44
45 // let's give full CiviGrant permissions to demo user (registered user).
46 $permission = array('edit-2-access-civigrant', 'edit-2-edit-grants', 'edit-2-delete-in-civigrant');
47 $this->changePermissions($permission);
48
42daf119
CW
49 // Log in as normal user
50 $this->webtestLogin();
51
6a488035
TO
52 // Create unique identifier for names
53 $rand = substr(sha1(rand()), 0, 7);
54
55 // Add new Grant Type
118e964e 56 $this->openCiviPage('admin/options/grant_type', 'reset=1');
45fabf8e 57 $this->click("xpath=//*[@id='crm-main-content-wrapper']/div[2]/div[1]/a");
58 $this->waitForElementPresent('_qf_Options_cancel-bottom');
6a488035
TO
59 $grantType = 'GrantType' . $rand;
60 $this->type('id=label', $grantType);
61 $this->click('id=_qf_Options_next-top');
6c5f7368 62 $this->waitForText('crm-notification-container', "The Grant Type '$grantType' has been saved.");
6a488035
TO
63
64 // Create new Custom Field Set that extends the grant type
79d6583c 65 $this->openCiviPage('admin/custom/group', 'reset=1');
6a488035
TO
66 $this->click("css=#newCustomDataGroup > span");
67 $this->waitForElementPresent('_qf_Group_next-bottom');
68 $grantFieldSet = 'Fieldset' . $rand;
69 $this->type('id=title', $grantFieldSet);
70 $this->select('id=extends_0', 'label=Grants');
71 $this->addSelection('id=extends_1', "label=$grantType");
72 $this->click('id=collapse_display');
7df6dc24 73 $this->clickLink('id=_qf_Group_next-bottom');
6c5f7368 74 $this->waitForText('crm-notification-container', "Your custom field set '$grantFieldSet' has been added.");
60f44e0c 75 $this->waitForElementPresent('_qf_Field_done-bottom');
6a488035
TO
76
77 // Add field to fieldset
78 $grantField = 'GrantField' . $rand;
79 $this->type('id=label', $grantField);
80 $this->select('id=data_type_0', 'label=Money');
60f44e0c 81 $this->click('id=_qf_Field_done-bottom');
45fabf8e 82 $this->waitForText('crm-notification-container', "Custom field '$grantField' has been saved.");
6a488035
TO
83
84 // Create new Grant
79d6583c 85 $this->openCiviPage('grant/add', 'reset=1&action=add&context=standalone', '_qf_Grant_upload-bottom');
80f3b91d 86 $contact = $this->createDialogContact();
8cc4f1ab 87 $this->select('id=status_id', 'label=Approved for Payment');
6a488035
TO
88 $this->select('id=grant_type_id', "label=$grantType");
89 $this->waitForTextPresent($grantField);
45fabf8e 90 $this->assertElementContainsText("xpath=//div[@id='customData']/div[@class='custom-group custom-group-$grantFieldSet crm-accordion-wrapper ']", $grantField);
6a488035 91 $this->type('id=amount_total', '100.00');
45fabf8e 92 $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');
93 $this->clickLink('id=_qf_Grant_upload-bottom', "xpath=//div[@class='view-content']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
94
95 // Click through to the Grant view screen
45fabf8e 96 $this->click("xpath=//div[@class='view-content']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
97 $this->waitForElementPresent('_qf_GrantView_cancel-bottom');
98
99 // verify tabular data for grant view
100 $this->webtestVerifyTabularData(array(
92915c55
TO
101 'Name' => $contact['display_name'],
102 'Grant Status' => 'Approved',
103 'Grant Type' => $grantType,
104 $grantField => '$ 99.99',
105 )
6a488035
TO
106 );
107 }
6a488035 108
00be9182 109 public function testAjaxCustomGroupLoad() {
c4e6d4e8
PJ
110 $this->webtestLogin();
111
112 // Enable CiviGrant module if necessary
113 $this->enableComponents("CiviGrant");
114
115 $triggerElement = array('name' => 'grant_type_id', 'type' => 'select');
116 $customSets = array(
117 array('entity' => 'Grant', 'subEntity' => 'Emergency', 'triggerElement' => $triggerElement),
21dfd5f5 118 array('entity' => 'Grant', 'subEntity' => 'Family Support', 'triggerElement' => $triggerElement),
c4e6d4e8
PJ
119 );
120
121 $pageUrl = array('url' => 'grant/add', 'args' => 'reset=1&action=add&context=standalone');
122 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
123 }
96025800 124
232624b1 125}