Merge pull request #4150 from jmcclelland/logging-table-exceptions-4.5
[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
29 /**
30 * Class WebTest_Grant_CustomFieldsetTest
31 */
32 class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testCustomFieldsetTest() {
39 // Log in as admin first to verify permissions for CiviGrant
40 $this->webtestLogin('admin');
41
42 // Enable CiviGrant module if necessary
43 $this->enableComponents("CiviGrant");
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
49 // Log in as normal user
50 $this->webtestLogin();
51
52 // Create unique identifier for names
53 $rand = substr(sha1(rand()), 0, 7);
54
55 // Add new Grant Type
56 $this->openCiviPage('admin/options/grant_type', 'reset=1');
57 $this->click("xpath=//*[@id='crm-main-content-wrapper']/div[2]/div[1]/a");
58 $this->waitForElementPresent('_qf_Options_cancel-bottom');
59 $grantType = 'GrantType' . $rand;
60 $this->type('id=label', $grantType);
61 $this->click('id=_qf_Options_next-top');
62 $this->waitForText('crm-notification-container', "The Grant Type '$grantType' has been saved.");
63
64 // Create new Custom Field Set that extends the grant type
65 $this->openCiviPage('admin/custom/group', 'reset=1');
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');
73 $this->clickLink('id=_qf_Group_next-bottom');
74 $this->waitForText('crm-notification-container', "Your custom field set '$grantFieldSet' has been added.");
75 $this->waitForElementPresent('_qf_Field_done-bottom');
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');
81 $this->click('id=_qf_Field_done-bottom');
82 $this->waitForText('crm-notification-container', "Custom field '$grantField' has been saved.");
83
84 // Create new Grant
85 $this->openCiviPage('grant/add', 'reset=1&action=add&context=standalone', '_qf_Grant_upload-bottom');
86 $firstName = 'First' . $rand;
87 $lastName = 'Last' . $rand;
88 $this->webtestNewDialogContact($firstName, $lastName);
89 $this->select('id=status_id', 'label=Approved for Payment');
90 $this->select('id=grant_type_id', "label=$grantType");
91 $this->waitForTextPresent($grantField);
92 $this->assertElementContainsText("xpath=//div[@id='customData']/div[@class='custom-group custom-group-$grantFieldSet crm-accordion-wrapper ']", $grantField);
93 $this->type('id=amount_total', '100.00');
94 $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');
95 $this->clickLink('id=_qf_Grant_upload-bottom', "xpath=//div[@class='view-content']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
96
97 // Click through to the Grant view screen
98 $this->click("xpath=//div[@class='view-content']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
99 $this->waitForElementPresent('_qf_GrantView_cancel-bottom');
100
101 // verify tabular data for grant view
102 $this->webtestVerifyTabularData(array(
103 'Name' => "$firstName $lastName",
104 'Grant Status' => 'Approved',
105 'Grant Type' => $grantType,
106 $grantField => '$ 99.99',
107 )
108 );
109 }
110
111 function testAjaxCustomGroupLoad() {
112 $this->webtestLogin();
113
114 // Enable CiviGrant module if necessary
115 $this->enableComponents("CiviGrant");
116
117 $triggerElement = array('name' => 'grant_type_id', 'type' => 'select');
118 $customSets = array(
119 array('entity' => 'Grant', 'subEntity' => 'Emergency', 'triggerElement' => $triggerElement),
120 array('entity' => 'Grant', 'subEntity' => 'Family Support', 'triggerElement' => $triggerElement)
121 );
122
123 $pageUrl = array('url' => 'grant/add', 'args' => 'reset=1&action=add&context=standalone');
124 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
125 }
126 }