webtest code improvement(using helper functions of CiviSeleniumTestCase) and cleanup
authorPratik Joshi <pratik@pratik-desktop.(none)>
Mon, 4 Mar 2013 09:58:37 +0000 (15:28 +0530)
committerPratik Joshi <pratik@pratik-desktop.(none)>
Mon, 4 Mar 2013 12:53:57 +0000 (18:23 +0530)
tests/phpunit/WebTest/Member/EditMembershipTest.php
tests/phpunit/WebTest/Member/InheritedMembershipTest.php

index 4416c313e41714b425c6381c557de43b5fb0ce53..16cef0586af19792fdc8b5ab8fc39756c77abcff 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-/* 
+/*
  +--------------------------------------------------------------------+
  | CiviCRM version 4.3                                                |
  +--------------------------------------------------------------------+
@@ -24,7 +24,6 @@
  +--------------------------------------------------------------------+
 */
 
-
 require_once 'CiviTest/CiviSeleniumTestCase.php';
 class WebTest_Member_EditMembershipTest extends CiviSeleniumTestCase {
   protected function setUp() {
@@ -45,9 +44,7 @@ class WebTest_Member_EditMembershipTest extends CiviSeleniumTestCase {
     $membershipTypes = $this->webtestAddMembershipType();
 
     // now add membership
-    $this->open($this->sboxPath . "civicrm/member/add?reset=1&action=add&context=standalone");
-
-    $this->waitForElementPresent("_qf_Membership_upload");
+    $this->openCiviPage("member/add", "reset=1&action=add&context=standalone", "_qf_Membership_upload");
 
     // select contact
     $this->webtestFillAutocomplete($contactName);
@@ -69,13 +66,11 @@ class WebTest_Member_EditMembershipTest extends CiviSeleniumTestCase {
     $this->click("xpath=//div[@id='memberships']//table/tbody/tr[1]/td[9]/span/a[text()='View']");
     $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
     $expected = array(
-      2 => $membershipTypes['membership_type'],
-      3 => 'New',
-      4 => 'Membership StandaloneAddTest Webtest',
+      'Membership Type'  => $membershipTypes['membership_type'],
+      'Status' => 'New',
+      'Source' => 'Membership StandaloneAddTest Webtest',
     );
-    foreach ($expected as $label => $value) {
-      $this->verifyText("xpath=id('MembershipView')/div[2]/div/table[1]/tbody/tr[$label]/td[2]", preg_quote($value));
-    }
+    $this->webtestVerifyTabularData($expected);
 
     // now edit and update type and status
     $this->click("crm-membership-edit-button-top");
@@ -90,8 +85,8 @@ class WebTest_Member_EditMembershipTest extends CiviSeleniumTestCase {
     $this->waitForElementPresent("access");
 
     // Use activity search to find the expected activities
-    $this->open($this->sboxPath . "civicrm/activity/search?reset=1");
-    $this->waitForElementPresent("_qf_Search_refresh");
+    $this->openCiviPage('activity/search', 'reset=1', "_qf_Search_refresh");
+
     $this->type("sort_name", $contactName);
     $this->click('activity_type_id[35]');
     $this->click('activity_type_id[36]');
@@ -105,5 +100,4 @@ class WebTest_Member_EditMembershipTest extends CiviSeleniumTestCase {
     $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr[3]/td[3][text()='Type changed from {$membershipTypes['membership_type']} to General']"));
     $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr[3]/td[5]/a[text()='{$contactName}']"));
   }
-}
-
+}
\ No newline at end of file
index 716574286fc4d4b74f120950e3c22a538a9df3b5..e13cd3647898c1feb784f733e470ff441832ca43 100644 (file)
@@ -24,7 +24,6 @@
  +--------------------------------------------------------------------+
 */
 
-
 require_once 'CiviTest/CiviSeleniumTestCase.php';
 class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase {
   protected function setUp() {
@@ -40,19 +39,17 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase {
     // Log in using webtestLogin() method
     $this->webtestLogin();
 
-    $this->open($this->sboxPath . 'civicrm/contact/add?reset=1&ct=Organization');
-    $this->waitForElementPresent('_qf_Contact_cancel');
+    $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
 
     $title = substr(sha1(rand()), 0, 7);
     $this->type('organization_name', "Organization $title");
     $this->type('email_1_email', "$title@org.com");
     $this->click('_qf_Contact_upload_view');
     $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->assertTrue($this->isTextPresent("Organization $title has been created."));
+    $this->assertElementContainsText('crm-notification-container', "Organization {$title} has been created.");
 
     // Go directly to the URL
-    $this->open($this->sboxPath . 'civicrm/admin/member/membershipType?reset=1&action=browse');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
 
     $this->click('link=Add Membership Type');
     $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
@@ -78,10 +75,9 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase {
 
     $this->click('_qf_MembershipType_upload-bottom');
     $this->waitForElementPresent('link=Add Membership Type');
-    $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
+    $this->assertElementContainsText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
 
-    $this->open($this->sboxPath . 'civicrm/contact/add?reset=1&ct=Organization');
-    $this->waitForElementPresent('_qf_Contact_cancel');
+    $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
 
     // creating another Orgnization
     $title1 = substr(sha1(rand()), 0, 7);
@@ -114,9 +110,8 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase {
     $this->waitForTextPresent($sourceText);
 
     // Is status message correct?
-    $this->assertTrue($this->isTextPresent("Membership Type $title membership for Organization $title1 has been added."),
-      "Status message didn't show up after saving!"
-    );
+    $this->assertElementContainsText('crm-notification-container', "Membership Type $title membership for Organization $title1 has been added.",
+      "Status message didn't show up after saving!");
 
     // click through to the membership view screen
     $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
@@ -130,7 +125,7 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase {
       'joinDate', 'startDate', 'endDate') as $date) {
       $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull);
     }
-        
+
     $this->webtestVerifyTabularData(
       array(
         'Membership Type' => "Membership Type $title",
@@ -211,21 +206,20 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase {
     $this->click('_qf_Relationship_upload');
     $this->waitForElementPresent('inactive-relationships');
     //check the status message
-    $this->assertTrue($this->isTextPresent('Relationship record has been updated.'));
+    $this->assertElementContainsText('crm-notification-container', 'Relationship record has been updated.');
 
     // click through to the membership view screen
     $this->click('css=li#tab_member a');
 
     //verify inherited membership has been removed
-    $this->open($this->sboxPath . "civicrm/contact/view?reset=1&cid=$id&selectedChild=member");
-    $this->waitForElementPresent("xpath=//div[@class='crm-container-snippet']/div/div[3]");
+    $this->openCiviPage("contact/view", "reset=1&cid=$id&selectedChild=member", "xpath=//div[@class='crm-container-snippet']/div/div[3]");
     $this->assertTrue($this->isTextPresent('No memberships have been recorded for this contact.'));
 
     // visit relationship tab and re-enable the relationship
     $this->click('css=li#tab_rel a');
     $this->waitForElementPresent('css=div.action-link');
     $this->click("//li[@id='tab_rel']/a");
+
     $this->waitForElementPresent("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span/a[text()='Edit']");
     $this->click("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span/a[text()='Edit']");
     $this->waitForElementPresent('is_active');
@@ -235,7 +229,7 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase {
     $this->click('_qf_Relationship_upload');
     $this->waitForElementPresent('current-relationships');
     //check the status message
-    $this->assertTrue($this->isTextPresent('Relationship record has been updated.'));
+    $this->assertElementContainsText('crm-notification-container', 'Relationship record has been updated.');
 
     //check for memberships
     $this->click('css=li#tab_member a');
@@ -255,8 +249,7 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase {
     sleep(10);
 
     //verify inherited membership has been removed
-    $this->open($this->sboxPath . "civicrm/contact/view?reset=1&cid=$id&selectedChild=member");
-    $this->waitForElementPresent("xpath=//div[@class='crm-container-snippet']/div/div[3]");
+    $this->openCiviPage("contact/view", "reset=1&cid={$id}&selectedChild=member", "xpath=//div[@class='crm-container-snippet']/div/div[3]");
     $this->assertTrue($this->isTextPresent('No memberships have been recorded for this contact.'));
 
     //enable relationship