Import from SVN (r45945, r596)
[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() {
36 // This is the path where our testing install resides.
37 // The rest of URL is defined in CiviSeleniumTestCase base class, in
38 // class attributes.
39 $this->open($this->sboxPath);
40
41 // Log in as admin first to verify permissions for CiviGrant
42 $this->webtestLogin(TRUE);
43
44 // Enable CiviGrant module if necessary
45 $this->open($this->sboxPath . 'civicrm/admin/setting/component?reset=1');
46 $this->waitForPageToLoad($this->getTimeoutMsec());
47 $this->waitForElementPresent('_qf_Component_next-bottom');
48 $enabledComponents = $this->getSelectOptions('enableComponents-t');
49 if (!in_array('CiviGrant', $enabledComponents)) {
50 $this->addSelection('enableComponents-f', 'label=CiviGrant');
51 $this->click("//option[@value='CiviGrant']");
52 $this->click('add');
53 $this->click('_qf_Component_next-bottom');
54 $this->waitForPageToLoad($this->getTimeoutMsec());
55 $this->assertElementContainsText("css=#crm-notification-container", 'Changes Saved', 'CiviCRM Message does not indicate the enabled component changes were saved');
56 }
57
58 // let's give full CiviGrant permissions to demo user (registered user).
59 $permission = array('edit-2-access-civigrant', 'edit-2-edit-grants', 'edit-2-delete-in-civigrant');
60 $this->changePermissions($permission);
61
62 // Create unique identifier for names
63 $rand = substr(sha1(rand()), 0, 7);
64
65 // Add new Grant Type
66 $this->open($this->sboxPath . 'civicrm/admin/options/grant_type?group=grant_type&reset=1');
67 $this->waitForPageToLoad($this->getTimeoutMsec());
68 $this->click("css=#grant_type > div.action-link > #new > span");
69 $this->waitForPageToLoad($this->getTimeoutMsec());
70 $grantType = 'GrantType' . $rand;
71 $this->type('id=label', $grantType);
72 $this->click('id=_qf_Options_next-top');
73 $this->waitForPageToLoad($this->getTimeoutMsec());
74 $this->assertTrue($this->isTextPresent("The Grant Type '$grantType' has been saved."));
75
76 // Create new Custom Field Set that extends the grant type
77 $this->open($this->sboxPath . 'civicrm/admin/custom/group?reset=1');
78 $this->waitForPageToLoad($this->getTimeoutMsec());
79 $this->click("css=#newCustomDataGroup > span");
80 $this->waitForElementPresent('_qf_Group_next-bottom');
81 $grantFieldSet = 'Fieldset' . $rand;
82 $this->type('id=title', $grantFieldSet);
83 $this->select('id=extends_0', 'label=Grants');
84 $this->addSelection('id=extends_1', "label=$grantType");
85 $this->click('id=collapse_display');
86 $this->click('id=_qf_Group_next-bottom');
87 $this->waitForElementPresent('_qf_Field_next-bottom');
88 $this->assertTrue($this->isTextPresent("Your custom field set '$grantFieldSet' has been added."));
89
90 // Add field to fieldset
91 $grantField = 'GrantField' . $rand;
92 $this->type('id=label', $grantField);
93 $this->select('id=data_type_0', 'label=Money');
94 $this->click('id=_qf_Field_next-bottom');
95 $this->waitForPageToLoad($this->getTimeoutMsec());
96 $this->assertTrue($this->isTextPresent("Your custom field '$grantField' has been saved."));
97
98 // Create new Grant
99 $this->open($this->sboxPath . 'civicrm/grant/add?reset=1&action=add&context=standalone');
100 $this->waitForElementPresent('_qf_Grant_upload-bottom');
101 $this->select('id=profiles_1', 'label=New Individual');
102 $this->waitForElementPresent('_qf_Edit_next');
103 $firstName = 'First' . $rand;
104 $lastName = 'Last' . $rand;
105 $this->type('id=first_name', $firstName);
106 $this->type('id=last_name', $lastName);
107 $this->click('id=_qf_Edit_next');
108 $this->select('id=status_id', 'label=Approved');
109 $this->select('id=grant_type_id', "label=$grantType");
110 $this->waitForTextPresent($grantField);
111 $this->assertTrue($this->isTextPresent($grantField));
112 $this->type('id=amount_total', '100.00');
113 $this->type("css=div#$grantFieldSet input.form-text", '99.99');
114 $this->click('id=_qf_Grant_upload-bottom');
115 $this->waitForPageToLoad($this->getTimeoutMsec());
116
117 // Verify grant is created with presence of view link
118 $this->waitForElementPresent("xpath=//div[@id='Grants']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
119
120 // Click through to the Grant view screen
121 $this->click("xpath=//div[@id='Grants']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
122 $this->waitForElementPresent('_qf_GrantView_cancel-bottom');
123
124 // verify tabular data for grant view
125 $this->webtestVerifyTabularData(array(
126 'Name' => "$firstName $lastName",
127 'Grant Status' => 'Approved',
128 'Grant Type' => $grantType,
129 $grantField => '$ 99.99',
130 )
131 );
132 }
133}
134