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