Merge pull request #95 from ravishnair/webtest-improvement
[civicrm-core.git] / tests / phpunit / WebTest / Grant / CustomFieldsetTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testCustomFieldsetTest() {
36 // Log in as admin first to verify permissions for CiviGrant
37 $this->webtestLogin(TRUE);
38
39 // Enable CiviGrant module if necessary
40 $this->enableComponents("CiviGrant");
41
42 // let's give full CiviGrant permissions to demo user (registered user).
43 $permission = array('edit-2-access-civigrant', 'edit-2-edit-grants', 'edit-2-delete-in-civigrant');
44 $this->changePermissions($permission);
45
46 // Create unique identifier for names
47 $rand = substr(sha1(rand()), 0, 7);
48
49 // Add new Grant Type
50 $this->openCiviPage('admin/options/grant_type', 'group=grant_type&reset=1');
51 $this->click("css=#grant_type > div.action-link > #new > span");
52 $this->waitForPageToLoad($this->getTimeoutMsec());
53 $grantType = 'GrantType' . $rand;
54 $this->type('id=label', $grantType);
55 $this->click('id=_qf_Options_next-top');
56 $this->waitForPageToLoad($this->getTimeoutMsec());
57 $this->assertElementContainsText('crm-notification-container', "The Grant Type '$grantType' has been saved.");
58
59 // Create new Custom Field Set that extends the grant type
60 $this->openCiviPage('admin/custom/group', 'reset=1');
61 $this->click("css=#newCustomDataGroup > span");
62 $this->waitForElementPresent('_qf_Group_next-bottom');
63 $grantFieldSet = 'Fieldset' . $rand;
64 $this->type('id=title', $grantFieldSet);
65 $this->select('id=extends_0', 'label=Grants');
66 $this->addSelection('id=extends_1', "label=$grantType");
67 $this->click('id=collapse_display');
68 $this->click('id=_qf_Group_next-bottom');
69 $this->waitForElementPresent('_qf_Field_next-bottom');
70 $this->assertElementContainsText('crm-notification-container', "Your custom field set '$grantFieldSet' has been added.");
71
72 // Add field to fieldset
73 $grantField = 'GrantField' . $rand;
74 $this->type('id=label', $grantField);
75 $this->select('id=data_type_0', 'label=Money');
76 $this->click('id=_qf_Field_next-bottom');
77 $this->waitForPageToLoad($this->getTimeoutMsec());
78 $this->assertElementContainsText('crm-notification-container', "Your custom field '$grantField' has been saved.");
79
80 // Create new Grant
81 $this->openCiviPage('grant/add', 'reset=1&action=add&context=standalone', '_qf_Grant_upload-bottom');
82 $this->select('id=profiles_1', 'label=New Individual');
83 $this->waitForElementPresent('_qf_Edit_next');
84 $firstName = 'First' . $rand;
85 $lastName = 'Last' . $rand;
86 $this->type('id=first_name', $firstName);
87 $this->type('id=last_name', $lastName);
88 $this->click('id=_qf_Edit_next');
89 $this->select('id=status_id', 'label=Approved');
90 $this->select('id=grant_type_id', "label=$grantType");
91 $this->waitForTextPresent($grantField);
92 $this->assertElementContainsText($grantFieldSet, $grantField);
93 $this->type('id=amount_total', '100.00');
94 $this->type("css=div#$grantFieldSet input.form-text", '99.99');
95 $this->click('id=_qf_Grant_upload-bottom');
96 $this->waitForPageToLoad($this->getTimeoutMsec());
97
98 // Verify grant is created with presence of view link
99 $this->waitForElementPresent("xpath=//div[@id='Grants']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
100
101 // Click through to the Grant view screen
102 $this->click("xpath=//div[@id='Grants']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
103 $this->waitForElementPresent('_qf_GrantView_cancel-bottom');
104
105 // verify tabular data for grant view
106 $this->webtestVerifyTabularData(array(
107 'Name' => "$firstName $lastName",
108 'Grant Status' => 'Approved',
109 'Grant Type' => $grantType,
110 $grantField => '$ 99.99',
111 )
112 );
113 }
114 }
115