| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.5 | |
| 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_Case_AddCaseTest |
| 31 | */ |
| 32 | class WebTest_Case_AddCaseTypeTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | function testAddEditCaseType() { |
| 39 | $caseRoles = array(1 => 'Parent of', 2 => 'Spouse of', 3 => 'Partner of'); |
| 40 | $activityTypes = array(1 => 'Meeting',2 => 'Contribution',3 => 'Event Registration'); |
| 41 | $timelineActivityTypes = array(1 => 'Meeting',2 => 'Phone Call',3 => 'Email'); |
| 42 | // Log in as admin first to verify permissions for CiviCase |
| 43 | $this->webtestLogin('admin'); |
| 44 | |
| 45 | // Enable CiviCase module if necessary |
| 46 | $this->enableComponents("CiviCase"); |
| 47 | |
| 48 | // let's give full CiviCase permissions to demo user (registered user). |
| 49 | $permission = array('edit-2-access-all-cases-and-activities', 'edit-2-access-my-cases-and-activities', 'edit-2-administer-civicase', 'edit-2-delete-in-civicase'); |
| 50 | $this->changePermissions($permission); |
| 51 | |
| 52 | // Log in as normal user |
| 53 | $this->webtestLogin(); |
| 54 | |
| 55 | $this->openCiviPage('a/#/caseType/new'); |
| 56 | |
| 57 | $caseTypeLabel = "Case Type". substr(sha1(rand()), 0, 7); |
| 58 | $this->waitForElementPresent('title'); |
| 59 | $this->type('title', $caseTypeLabel); |
| 60 | |
| 61 | foreach ($caseRoles as $cRoles) { |
| 62 | $this->select2("xpath=//tr[@class='addRow']/td/span/div/a", $cRoles, FALSE, TRUE); |
| 63 | } |
| 64 | |
| 65 | foreach ($activityTypes as $aType) { |
| 66 | $this->select2("xpath=//tr[@class='addRow']/td[contains(text(),'Add activity type:')]/span/div/a", $aType, FALSE, TRUE); |
| 67 | } |
| 68 | |
| 69 | $this->click("xpath=//a[text()='Standard Timeline']"); |
| 70 | foreach ($timelineActivityTypes as $tActivityType) { |
| 71 | $this->select2("xpath=//tr[@class='addRow']/td[contains(text(),'Add activity:')]/span/div/a", $tActivityType, FALSE, TRUE); |
| 72 | } |
| 73 | |
| 74 | $this->clickAjaxLink("xpath=//div[@class='crm-submit-buttons']/span/input[@value='Save']", NULL); |
| 75 | |
| 76 | $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom'); |
| 77 | $client = $this->createDialogContact("client_id"); |
| 78 | |
| 79 | $caseStatusLabel = "Ongoing"; |
| 80 | $subject = "Safe daytime setting - senior female"; |
| 81 | $this->select("medium_id", "value=1"); |
| 82 | $location = "Main offices"; |
| 83 | $this->type("activity_location", $location); |
| 84 | $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented."; |
| 85 | $this->fireEvent('activity_details', 'focus'); |
| 86 | $this->fillRichTextField("activity_details", $details, 'CKEditor'); |
| 87 | $this->type("activity_subject", $subject); |
| 88 | $this->waitForElementPresent('case_type_id'); |
| 89 | $this->select("case_type_id", "label={$caseTypeLabel}"); |
| 90 | $this->waitForElementPresent('status_id'); |
| 91 | $this->select("status_id", "label={$caseStatusLabel}"); |
| 92 | |
| 93 | $this->webtestFillDate('start_date', 'now'); |
| 94 | $today = date('F jS, Y', strtotime('now')); |
| 95 | |
| 96 | $this->type("duration", "20"); |
| 97 | $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom"); |
| 98 | |
| 99 | // Is status message correct? |
| 100 | $this->waitForText('crm-notification-container', "Case opened successfully."); |
| 101 | |
| 102 | foreach ($activityTypes as $aType) { |
| 103 | $this->assertText("add_activity_type_id", $aType); |
| 104 | } |
| 105 | |
| 106 | $this->click("xpath=//div[contains(text(), 'Roles')]"); |
| 107 | |
| 108 | // check that expected roles are listed in the Case Roles pane |
| 109 | foreach ($caseRoles as $key => $role) { |
| 110 | $this->assertText("css=div.crm-case-roles-block", $role); |
| 111 | } |
| 112 | |
| 113 | $id = $this->urlArg('id'); |
| 114 | // check that expected activities are listed in the Case Activities table |
| 115 | foreach ($timelineActivityTypes as $tActivityType) { |
| 116 | $this->assertText("case_id_$id", $tActivityType); |
| 117 | } |
| 118 | |
| 119 | // for edit case type |
| 120 | $this->openCiviPage('a/#/caseType'); |
| 121 | $this->waitForElementPresent("xpath=//*[@id='crm-main-content-wrapper']/div/div/div[2]/a/span[contains(text(),'New Case Type')]"); |
| 122 | |
| 123 | $this->click("xpath=//table/tbody//tr/td[1][text()='{$caseTypeLabel}']/../td[5]/span/a[text()='Edit']"); |
| 124 | $this->waitForElementPresent("xpath=//div[@class='crm-submit-buttons']/span/input[@value='Save']"); |
| 125 | |
| 126 | $editCaseTypeLabel = "Case Type Edit". substr(sha1(rand()), 0, 7); |
| 127 | $this->waitForElementPresent('title'); |
| 128 | $this->type('title', $editCaseTypeLabel); |
| 129 | |
| 130 | $this->select2("xpath=//tr[@class='addRow']/td/span/div/a", 'Sibling of', FALSE, TRUE); |
| 131 | $this->click("xpath=//*[@id='crm-main-content-wrapper']/div/div/form/div/div[3]/table/tbody/tr[4]/td[2]/input[@type='checkbox']"); |
| 132 | |
| 133 | $this->click("xpath=//a[text()='Standard Timeline']"); |
| 134 | $this->select2("xpath=//tr[@class='addRow']/td[contains(text(),'Add activity:')]/span/div/a", 'SMS', FALSE, TRUE); |
| 135 | |
| 136 | $this->click("xpath=//div[@class='crm-submit-buttons']/span/input[@value='Save']"); |
| 137 | $this->waitForElementPresent("xpath=//*[@id='crm-main-content-wrapper']/div/div/div[2]/a/span[contains(text(),'New Case Type')]"); |
| 138 | |
| 139 | $this->verifyText("xpath=//table/tbody//tr/td[contains(text(),'$editCaseTypeLabel')]", $editCaseTypeLabel); |
| 140 | } |
| 141 | } |