Import from SVN (r45945, r596)
[civicrm-core.git] / tests / phpunit / WebTest / Grant / StandaloneAddTest.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_StandaloneAddTest extends CiviSeleniumTestCase {
30
31 protected $captureScreenshotOnFailure = TRUE;
32 protected $screenshotPath = '/tmp/';
33 protected $screenshotUrl = 'http://api.dev.civicrm.org/sc/';
34
35 protected function setUp() {
36 parent::setUp();
37 }
38
39 function testStandaloneGrantAdd() {
40 // This is the path where our testing install resides.
41 // The rest of URL is defined in CiviSeleniumTestCase base class, in
42 // class attributes.
43 $this->open($this->sboxPath);
44
45 // Log in as admin first to verify permissions for CiviGrant
46 $this->webtestLogin(TRUE);
47
48 // Enable CiviGrant module if necessary
49 $this->open($this->sboxPath . "civicrm/admin/setting/component?reset=1");
50 $this->waitForPageToLoad($this->getTimeoutMsec());
51 $this->waitForElementPresent("_qf_Component_next-bottom");
52 $enabledComponents = $this->getSelectOptions("enableComponents-t");
53 if (!in_array("CiviGrant", $enabledComponents)) {
54 $this->addSelection("enableComponents-f", "label=CiviGrant");
55 $this->click("//option[@value='CiviGrant']");
56 $this->click("add");
57 $this->click("_qf_Component_next-bottom");
58 $this->waitForPageToLoad($this->getTimeoutMsec());
59 $this->assertTrue($this->isTextPresent("Your changes have been saved."));
60 }
61
62 // let's give full CiviGrant permissions to demo user (registered user).
63 $permission = array('edit-2-access-civigrant', 'edit-2-edit-grants', 'edit-2-delete-in-civigrant');
64 $this->changePermissions($permission);
65
66 // Go directly to the URL of the screen that you will be testing (New Contribution-standalone).
67 $this->open($this->sboxPath . "civicrm/grant/add?reset=1&context=standalone");
68
69 // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit
70 // button at the end of this page to show up, to make sure it's fully loaded.
71 $this->waitForElementPresent("_qf_Grant_upload");
72
73 // Let's start filling the form with values.
74
75 // create new contact using dialog
76 $firstName = substr(sha1(rand()), 0, 7);
77 $this->webtestNewDialogContact($firstName, "Grantor", $firstName . "@example.com");
78
79 // select grant Status
80 $this->select("status_id", "value=1");
81
82 // select grant type
83 $this->select("grant_type_id", "value=1");
84
85 // total amount
86 $this->type("amount_total", "100");
87
88 // amount requested
89 $this->type("amount_requested", "100");
90
91 // amount granted
92 $this->type("amount_granted", "90");
93
94 // fill in application received Date
95 $this->webtestFillDate('application_received_date');
96
97 // fill in decision Date
98 $this->webtestFillDate('decision_date');
99
100 // fill in money transfered date
101 $this->webtestFillDate('money_transfer_date');
102
103 // fill in grant due Date
104 $this->webtestFillDate('grant_due_date');
105
106 // check grant report recieved.
107 $this->check("grant_report_received");
108
109 // grant note
110 $this->type("note", "Grant Note");
111
112 // Clicking save.
113 $this->click("_qf_Grant_upload");
114 $this->waitForPageToLoad($this->getTimeoutMsec());
115
116 // verify if Grant is created
117 $this->waitForElementPresent("xpath=//div[@id='Grants']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
118
119 //click through to the Grant view screen
120 $this->click("xpath=//div[@id='Grants']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
121
122 $this->waitForElementPresent("_qf_GrantView_cancel-bottom");
123
124 $expected = array(
125 2 => 'Submitted',
126 3 => 'Emergency',
127 8 => '$ 100.00',
128 10 => '$ 90.00',
129 13 => 'Grant Note',
130 );
131
132 foreach ($expected as $label => $value) {
133 $this->verifyText("xpath=id('GrantView')/div[2]/table[1]/tbody/tr[$label]/td[2]", preg_quote($value));
134 }
135 }
136}
137