webtest cleanup and code improvement
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Wed, 6 Mar 2013 15:17:35 +0000 (20:47 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Wed, 6 Mar 2013 16:07:10 +0000 (21:37 +0530)
tests/phpunit/WebTest/Profile/BatchUpdateTest.php
tests/phpunit/WebTest/Profile/DedupeTest.php
tests/phpunit/WebTest/Profile/MultiRecordProfileAddTest.php
tests/phpunit/WebTest/Profile/ProfileAddTest.php

index 396617e9213ccac1ac04f9156ee4f2600ca412fc..71b5505dfb866a926304c6bddd59a08709ce258d 100644 (file)
@@ -67,11 +67,13 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     $profileTitle  = 'Batch Profile test_' . substr(sha1(rand()), 0, 7);
-    $profileFields = array (array (
-                                   'type' => 'Individual',
-                                   'name' => 'Last Name',
-                                   'label' => 'Last Name'
-                                   ));
+    $profileFields = array(
+      array(
+        'type' => 'Individual',
+        'name' => 'Last Name',
+        'label' => 'Last Name'
+      )
+    );
     $this->addProfile($profileTitle, $profileFields);
     $this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh');
     $this->type('sort_name', "Smiths_x");
@@ -382,8 +384,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Reserve and interview responsedents
-    $this->open($this->sboxPath . "civicrm/campaign?reset=1&subPage=survey");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage('campaign', 'reset=1&subPage=survey');
     $this->waitForElementPresent("xpath=//table[@id='surveys']/tbody//tr/td[2]/a[text()='{$surveyTitle}']/../following-sibling::td[@class='crm-campaign-voterLinks']/span/ul/li/a");
     $this->click("xpath=//table[@id='surveys']/tbody//tr/td[2]/a[text()='{$surveyTitle}']/../following-sibling::td[@class='crm-campaign-voterLinks']/span/ul/li/a");
     $this->waitForPageToLoad($this->getTimeoutMsec());
@@ -523,8 +524,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->assertTrue($assertCheck, 'copy rows for field two failed for inteview (campaign)[radio button]');
 
     //change the editor back to ckeditor
-    $this->open($this->sboxPath . "civicrm/admin/setting/preferences/display?reset=1");
-    $this->waitForElementPresent('_qf_Display_next-bottom');
+    $this->openCiviPage('admin/setting/preferences/display', 'reset=1', '_qf_Display_next-bottom');
     $this->select('editor_id', 'CKEditor');
     $this->click('_qf_Display_next-bottom');
     $this->waitForPageToLoad($this->getTimeoutMsec());
@@ -532,9 +532,8 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
 
   function _addProfile($profileTitle, $customDataArr, $profileFor) {
     // Go directly to the URL of the screen that you will be testing (New Profile).
-    $this->open($this->sboxPath . "civicrm/admin/uf/group?reset=1");
+    $this->openCiviPage('admin/uf/group', 'reset=1');
 
-    $this->waitForPageToLoad($this->getTimeoutMsec());
     $this->click('link=Add Profile');
 
     // Add membership custom data field to profile
@@ -543,7 +542,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->click('_qf_Group_next-bottom');
 
     $this->waitForElementPresent('_qf_Field_cancel-bottom');
-    $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."));
+    $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
 
     foreach ($customDataArr as $key => $customDataParams) {
       $this->select('field_name[0]', "label={$profileFor}");
@@ -554,7 +553,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
       // Clicking save and new
       $this->click('_qf_Field_next_new-bottom');
       $this->waitForPageToLoad($this->getTimeoutMsec());
-      $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$customDataParams[1]}' has been saved to '{$profileTitle}'."));
+      $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile Field '{$customDataParams[1]}' has been saved to '{$profileTitle}'.");
     }
   }
 
@@ -562,7 +561,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $returnArray = array();
     $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 4);
     // Go directly to the URL of the screen that you will be testing (New Custom Group).
-    $this->open($this->sboxPath . "civicrm/admin/custom/group?reset=1");
+    $this->openCiviPage('admin/custom/group', 'reset=1');
 
     //add new custom data
     $this->click("//a[@id='newCustomDataGroup']/span");
@@ -583,7 +582,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->waitForElementPresent('_qf_Field_cancel-bottom');
 
     //Is custom group created?
-    $this->assertTrue($this->isTextPresent("Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."));
+    $this->assertElementContainsText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
 
     //for checkbox 1
     $checkLabel1 = 'Custom Check One Text_' . substr(sha1(rand()), 0, 4);
@@ -612,7 +611,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Is custom field created
-    $this->assertTrue($this->isTextPresent("Your custom field '$checkLabel1' has been saved."));
+    $this->assertElementContainsText('crm-notification-container', "Your custom field '$checkLabel1' has been saved.");
     $returnArray[1] = array($customGroupTitle, $checkLabel1);
 
     // create another custom field - Integer Radio
@@ -643,7 +642,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Is custom field created
-    $this->assertTrue($this->isTextPresent("Your custom field '$checkLabel2' has been saved."));
+    $this->assertElementContainsText('crm-notification-container', "Your custom field '$checkLabel2' has been saved.");
     $returnArray[2] = array($customGroupTitle, $checkLabel2);
 
     // create another custom field - Integer Radio
@@ -672,7 +671,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Is custom field created
-    $this->assertTrue($this->isTextPresent("Your custom field '$dateFieldLabel' has been saved."));
+    $this->assertElementContainsText('crm-notification-container', "Your custom field '$dateFieldLabel' has been saved.");
     $returnArray[3] = array($customGroupTitle, $dateFieldLabel);
 
     // create another custom field - Integer Radio
@@ -691,7 +690,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Is custom field created
-    $this->assertTrue($this->isTextPresent("Your custom field '$richTextField' has been saved."));
+    $this->assertElementContainsText('crm-notification-container', "Your custom field '$richTextField' has been saved.");
     $returnArray[4] = array($customGroupTitle, $richTextField);
 
     // create another custom field - Integer Radio
@@ -723,7 +722,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Is custom field created
-    $this->assertTrue($this->isTextPresent("Your custom field '$radioLabel1' has been saved."));
+    $this->assertElementContainsText('crm-container', "Your custom field '$radioLabel1' has been saved.");
     $returnArray[5] = array($customGroupTitle, $radioLabel1);
 
     // create another custom field - Integer Radio
@@ -754,7 +753,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Is custom field created
-    $this->assertTrue($this->isTextPresent("Your custom field '$radioLabel2' has been saved."));
+    $this->assertElementContainsText('crm-notification-container', "Your custom field '$radioLabel2' has been saved.");
     $returnArray[6] = array($customGroupTitle, $radioLabel2);
 
     return $returnArray;
index 22dd109361d627d21a3ec26c7b6000aee44165de..f7356a16d2c76e580f9027268a55ae0fa116dcf1 100644 (file)
@@ -43,7 +43,7 @@ class WebTest_Profile_DedupeTest extends CiviSeleniumTestCase {
     $this->changePermissions($permission);
 
     // Go directly to the URL of the screen that you will beadding New Individual.
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
+    $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
 
     $firstName = "John" . substr(sha1(rand()), 0, 7);
     $lastName  = "Smith" . substr(sha1(rand()), 0, 7);
@@ -61,12 +61,10 @@ class WebTest_Profile_DedupeTest extends CiviSeleniumTestCase {
     $this->click("_qf_Contact_upload_view");
     $this->waitForPageToLoad($this->getTimeoutMsec());
     $individualName = $this->getText("xpath=//div[@class='crm-summary-display_name']");
-    $this->assertTrue($this->isTextPresent("$individualName has been created."));
+    $this->assertElementContainsText('crm-notification-container', "$individualName has been created.");
 
     // submit dupe using profile/create as anonymous
-    $this->open($this->sboxPath . "civicrm/profile/create?gid=4&reset=1");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->waitForElementPresent("_qf_Edit_next");
+    $this->openCiviPage('profile/create', 'gid=4&reset=1', '_qf_Edit_next');
 
     $firstName = "John" . substr(sha1(rand()), 0, 7);
     $lastName = "Smith" . substr(sha1(rand()), 0, 7);
@@ -84,6 +82,4 @@ class WebTest_Profile_DedupeTest extends CiviSeleniumTestCase {
     $this->click("_qf_Edit_next");
     $this->waitForTextPresent("A record already exists with the same information.");
   }
-}
-
-
+}
\ No newline at end of file
index 70cc419f30e93d389f39327bb972923b65a526aa..2be907f2fab5c27a2779e448b29d0771ee5a0f1f 100644 (file)
@@ -95,8 +95,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
     $params = $this->_testCustomAdd($checkSearchable);
     // Go directly to the URL of the screen that you will be
     // testing (Add new profile ).
-    $this->open($this->sboxPath . 'civicrm/admin/uf/group?reset=1');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage('admin/uf/group', 'reset=1');
 
     $this->click('newCiviCRMProfile-top');
     $this->waitForElementPresent('_qf_Group_next-bottom');
@@ -140,7 +139,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //check for  profile create
-    $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '$profileTitle' has been added. You can add fields to this profile now"));
+    $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
 
     //Add field to profile
     $this->waitForElementPresent('field_name[0]');
@@ -221,6 +220,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
     $recordNew = $this->_addRecords('Create');
     $this->waitForPageToLoad($this->getTimeoutMsec());
     $elements = $this->parseURL( );
+
     $gid = $elements['queryString']['gid'];
     $id = $elements['queryString']['id'];
 
@@ -242,9 +242,9 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
       $this->click('edit-submit');
       $this->waitForPageToLoad($this->getTimeoutMsec());
     }
-    $this->open($this->sboxPath . 'civicrm/profile/edit?reset=1&id='.$id.'&gid='.$gid);
+    $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid");
     if (!$checkMultiRecord) {
-      $this->assertTrue($this->isTextPresent('No multi-record entries found'));
+      $this->assertElementContainsText('crm-container', 'No multi-record entries found');
       return;
     }
     $this->waitForElementPresent("//div[@id='crm-profile-block']/a");
@@ -253,8 +253,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
     $this->verifyText("//div[@id='browseValues']/div/div/table/thead/tr/th[1]", preg_quote($params['textFieldLabel']));
     $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[2]/td[1]", preg_quote($record1['text']));
-    $this->open($this->sboxPath . 'civicrm/profile/edit?reset=1&id='.$id.'&gid='.$gid);
-    $this->waitForElementPresent("//div[@id='crm-profile-block']/a");
+    $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", "//div[@id='crm-profile-block']/a");
     $this->click("//div[@id='crm-profile-block']/a");
     $record2 = $this->_addRecords();
     $this->waitForPageToLoad($this->getTimeoutMsec());
@@ -277,15 +276,15 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
     $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='Delete']");
     $this->waitForElementPresent("//html/body/div[5]");
     sleep(3);
-    $this->assertTrue($this->isTextPresent('Are you sure you want to delete this record?'));
+    $this->assertElementContainsText('profile-dialog', 'Are you sure you want to delete this record?');
     $this->click('_qf_Edit_upload_delete');
 
     // Check the view functionality
     sleep(3);
     $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='View']");
     $this->waitForElementPresent("//html/body/div[5]");
-    $this->assertTrue($this->isTextPresent('View '.$params['customGroupTitle']));
-    $this->assertTrue($this->isTextPresent($params['textFieldLabel']));
+    $this->assertElementContainsText('ui-id-1', 'View '.$params['customGroupTitle']);
+    $this->assertElementContainsText('crm-container', $params['textFieldLabel']);
     if ($checkSearchable) {
       $this->verifyElementNotPresent("//div[@id='profile-dialog']/div/div/div/div[1]/div[2]/a");
       return;
@@ -296,8 +295,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
       $this->click("//div[@id='profile-dialog']/div/div/div/div/div[2]/a");
       $this->waitForElementPresent("//form[@id='Search']");
       $this->verifyText("//form[@id='Search']/div[3]/div[2]/table/tbody/tr[2]/td[2]", preg_quote($recordNew['firstname']));
-      $this->open($this->sboxPath . 'civicrm/profile/view?reset=1&id='.$id.'&gid='.$gid);
-      $this->waitForElementPresent("//div[@id='row-first_name']/div[2]/a");
+      $this->openCiviPage('profile/view', "reset=1&id=$id&gid=$gid", "//div[@id='row-first_name']/div[2]/a");
       $this->click("//div[@id='row-first_name']/div[2]/a");
       $this->waitForElementPresent("//form[@id='Search']");
       // Check that Email column is not present in selector results
@@ -310,10 +308,9 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
 
   function _testCustomAdd($checkSearchable) {
     // Go directly to the URL of the screen that you will be testing (Custom data for contacts).
-    $this->open($this->sboxPath . "civicrm/admin/custom/group?action=add&reset=1");
+    $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
     // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit
     // button at the end of this page to show up, to make sure it's fully loaded.
-    $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //fill custom group title
     $params['customGroupTitle'] = 'custom_group' . substr(sha1(rand()), 0, 3);
@@ -331,7 +328,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Is custom group created?
-    $this->assertTrue($this->isTextPresent($params['customGroupTitle']));
+    $this->assertElementContainsText('crm-container', $params['customGroupTitle']);
     //add custom field - alphanumeric text
     $params['textFieldLabel'] = 'test_text_field' . substr(sha1(rand()), 0, 3);
     $this->click("header");
@@ -373,7 +370,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Is custom field created?
-    $this->assertTrue($this->isTextPresent($params['selectFieldLabel']));
+    $this->assertElementContainsText('crm-container', $params['selectFieldLabel']);
     return $params;
   }
 
@@ -389,8 +386,8 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
       $params['email'] =  $params['firstname'].$params['lastname'].'@exa.com';
       $this->type('email-Primary', $params['email']);
     }
-    $this->waitForElementPresent("//div[@id='crm-profile-block']/div/div[3]/div[2]/select");
-    $this->select("//div[@id='crm-profile-block']/div/div[3]/div[2]/select",'value=1');
+    $this->waitForElementPresent("//div[@id='crm-profile-block']/div//div/div[2]/select");
+    $this->select("//div[@id='crm-profile-block']/div//div/div[2]/select",'value=1');
     $this->click('_qf_Edit_next');
     return $params;
   }
index dd539ea8a241e942b9f55b3556f71061402ad901..fb770bfd10d7036377ff47e6ca3dc196dfeb22ed 100644 (file)
@@ -47,9 +47,7 @@ class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase {
 
     // Go directly to the URL of the screen that you will be
     // testing (Add new profile ).
-    $this->open($this->sboxPath . 'civicrm/admin/uf/group?reset=1');
-
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage('admin/uf/group', 'reset=1');
 
     $this->click('newCiviCRMProfile-top');
 
@@ -113,7 +111,7 @@ class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //check for  profile create
-    $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '$profileTitle' has been added. You can add fields to this profile now"));
+    $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
 
     //Add field to profile
     $this->click('field_name[0]');
@@ -127,7 +125,7 @@ class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     // delete the profile
-    $this->open($this->sboxPath . 'civicrm/admin/uf/group?reset=1');
+    $this->openCiviPage('admin/uf/group', 'reset=1');
     $this->_testdeleteProfile($profileTitle);
   }
 
@@ -139,8 +137,6 @@ class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase {
     $this->waitForElementPresent('_qf_Group_next-bottom');
     $this->click('_qf_Group_next-bottom');
     $this->waitForElementPresent('newCiviCRMProfile-bottom');
-    $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '$profileTitle' has been deleted."));
+    $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
   }
-}
-
-
+}
\ No newline at end of file