| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 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 | public 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 | $contact = $this->createDialogContact(); |
| 87 | $this->select('id=status_id', 'label=Approved for Payment'); |
| 88 | $this->select('id=grant_type_id', "label=$grantType"); |
| 89 | $this->waitForTextPresent($grantField); |
| 90 | $this->assertElementContainsText("xpath=//div[@id='customData']/div[@class='custom-group custom-group-$grantFieldSet crm-accordion-wrapper ']", $grantField); |
| 91 | $this->type('id=amount_total', '100.00'); |
| 92 | $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'); |
| 93 | $this->clickLink('id=_qf_Grant_upload-bottom', "xpath=//div[@class='view-content']//table/tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 94 | |
| 95 | // Click through to the Grant view screen |
| 96 | $this->click("xpath=//div[@class='view-content']//table/tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 97 | $this->waitForElementPresent('_qf_GrantView_cancel-bottom'); |
| 98 | |
| 99 | // verify tabular data for grant view |
| 100 | $this->webtestVerifyTabularData(array( |
| 101 | 'Name' => $contact['display_name'], |
| 102 | 'Grant Status' => 'Approved', |
| 103 | 'Grant Type' => $grantType, |
| 104 | $grantField => '$ 99.99', |
| 105 | ) |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | public function testAjaxCustomGroupLoad() { |
| 110 | $this->webtestLogin(); |
| 111 | |
| 112 | // Enable CiviGrant module if necessary |
| 113 | $this->enableComponents("CiviGrant"); |
| 114 | |
| 115 | $triggerElement = array('name' => 'grant_type_id', 'type' => 'select'); |
| 116 | $customSets = array( |
| 117 | array('entity' => 'Grant', 'subEntity' => 'Emergency', 'triggerElement' => $triggerElement), |
| 118 | array('entity' => 'Grant', 'subEntity' => 'Family Support', 'triggerElement' => $triggerElement), |
| 119 | ); |
| 120 | |
| 121 | $pageUrl = array('url' => 'grant/add', 'args' => 'reset=1&action=add&context=standalone'); |
| 122 | $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); |
| 123 | } |
| 124 | } |