Merge pull request #4198 from sunilpawar/CRM-15332
[civicrm-core.git] / tests / phpunit / WebTest / Event / PricesetMaxCountTest.php
index 5d7845cfa11ff0755db44178d38fea468f0d3eb4..02e8afe874132273fdc53b9cce3feda9d388e2f1 100644 (file)
@@ -39,8 +39,8 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
     // Log in using webtestLogin() method
     $this->webtestLogin();
 
-    // We need a payment processor
-    $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
+    // Use default payment processor
+    $processorName = 'Test Processor';
     $this->webtestAddPaymentProcessor($processorName);
 
     // create priceset
@@ -117,35 +117,28 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
     $pricesetLoc = $this->getLocation();
 
     // get text field Id.
-    $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
-    $textFieldId = explode('&', $textFieldId[0]);
-    $textFieldId = explode('=', $textFieldId[3]);
-    $textFieldId = $textFieldId[1];
+    $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div/a[1]");
+    $textFieldIdURL = $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr[1]/td[9]/span[1]/a[2]@href");
+    $textFieldId = $this->urlArg('fid', $textFieldIdURL);
 
     $this->open($pricesetLoc);
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     // get select field id
     $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]");
     $selectFieldLoc = $this->getLocation();
-    $selectFieldId = $this->urlArg('fid');
+    $selectFieldURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[9]/span[1]/a[2]@href");
+    $selectFieldId = $this->urlArg('fid', $selectFieldURL);
 
     // get select field ids
     // get select field option1
-    $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
-    $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
-    $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
-    $selectFieldOp1 = $selectFieldOp1[1];
-
-    $this->open($selectFieldLoc);
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $selectFieldOp1URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href");
+    $selectFieldOp1 = $this->urlArg('oid', $selectFieldOp1URL);
 
     // get select field option2
-    $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
-    $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
-    $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
-    $selectFieldOp2 = $selectFieldOp2[1];
+    $selectFieldOp2URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href");
+    $selectFieldOp2 = $this->urlArg('oid', $selectFieldOp2URL);
 
     // create event.
     $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
@@ -237,8 +230,8 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
     // Log in using webtestLogin() method
     $this->webtestLogin();
 
-    // We need a payment processor
-    $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
+    // Use default payment processor
+    $processorName = 'Test Processor';
     $this->webtestAddPaymentProcessor($processorName);
 
     // create priceset
@@ -322,35 +315,28 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
     $pricesetLoc = $this->getLocation();
 
     // get text field Id.
-    $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
-    $textFieldId = explode('&', $textFieldId[0]);
-    $textFieldId = explode('=', $textFieldId[3]);
-    $textFieldId = $textFieldId[1];
+    $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div/a[1]");
+    $textFieldIdURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href");
+    $textFieldId = $this->urlArg('fid', $textFieldIdURL);
 
     $this->open($pricesetLoc);
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     // get select field id
     $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]");
     $selectFieldLoc = $this->getLocation();
-    $selectFieldId = $this->urlArg('fid');
+    $selectFieldURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[9]/span[1]/a[2]@href");
+    $selectFieldId = $this->urlArg('fid', $selectFieldURL);
 
     // get select field ids
     // get select field option1
-    $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
-    $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
-    $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
-    $selectFieldOp1 = $selectFieldOp1[1];
-
-    $this->open($selectFieldLoc);
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $selectFieldOp1URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href");
+    $selectFieldOp1 = $this->urlArg('oid', $selectFieldOp1URL);
 
     // get select field option2
-    $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
-    $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
-    $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
-    $selectFieldOp2 = $selectFieldOp2[1];
+    $selectFieldOp2URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href");
+    $selectFieldOp2 = $this->urlArg('oid', $selectFieldOp2URL);
 
     // create event.
     $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
@@ -443,8 +429,8 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
     // Log in using webtestLogin() method
     $this->webtestLogin();
 
-    // We need a payment processor
-    $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
+    // Use default payment processor
+    $processorName = 'Test Processor';
     $this->webtestAddPaymentProcessor($processorName);
 
     // create priceset
@@ -521,35 +507,28 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
     $pricesetLoc = $this->getLocation();
 
     // get text field Id.
-    $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
-    $textFieldId = explode('&', $textFieldId[0]);
-    $textFieldId = explode('=', $textFieldId[3]);
-    $textFieldId = $textFieldId[1];
+    $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div/a[1]");
+    $textFieldURL = $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr[1]/td[9]/span[1]/a[2]@href");
+    $textFieldId = $this->urlArg('fid', $textFieldURL);
 
     $this->open($pricesetLoc);
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     // get select field id
     $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]");
     $selectFieldLoc = $this->getLocation();
-    $selectFieldId = $this->urlArg('fid');
+    $selectFieldURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[9]/span[1]/a[2]@href");
+    $selectFieldId = $this->urlArg('fid', $selectFieldURL);
 
     // get select field ids
     // get select field option1
-    $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
-    $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
-    $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
-    $selectFieldOp1 = $selectFieldOp1[1];
-
-    $this->open($selectFieldLoc);
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $selectFieldOp1URL = $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr[1]/td[7]/span[1]/a[1]@href");
+    $selectFieldOp1 = $this->urlArg('oid', $selectFieldOp1URL);
 
     // get select field option2
-    $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
-    $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
-    $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
-    $selectFieldOp2 = $selectFieldOp2[1];
+    $selectFieldOp2URL = $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr[2]/td[7]/span[1]/a[1]@href");
+    $selectFieldOp2 = $this->urlArg('oid', $selectFieldOp2URL);
 
     // create event.
     $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
@@ -735,8 +714,8 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
     // Log in using webtestLogin() method
     $this->webtestLogin();
 
-    // We need a payment processor
-    $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
+    // Use default payment processor
+    $processorName = 'Test Processor';
     $this->webtestAddPaymentProcessor($processorName);
 
     // create priceset
@@ -820,35 +799,28 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
     $pricesetLoc = $this->getLocation();
 
     // get text field Id.
-    $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
-    $textFieldId = explode('&', $textFieldId[0]);
-    $textFieldId = explode('=', $textFieldId[3]);
-    $textFieldId = $textFieldId[1];
+    $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div/a[1]");
+    $textFieldIdURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href");
+    $textFieldId = $this->urlArg('fid', $textFieldIdURL);
 
     $this->open($pricesetLoc);
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     // get select field id
     $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]");
     $selectFieldLoc = $this->getLocation();
-    $selectFieldId = $this->urlArg('fid');
+    $selectFieldURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[9]/span[1]/a[2]@href");
+    $selectFieldId = $this->urlArg('fid', $selectFieldURL);
 
     // get select field ids
     // get select field option1
-    $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
-    $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
-    $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
-    $selectFieldOp1 = $selectFieldOp1[1];
-
-    $this->open($selectFieldLoc);
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $selectFieldOp1URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href");
+    $selectFieldOp1 = $this->urlArg('oid', $selectFieldOp1URL);
 
     // get select field option2
-    $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
-    $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
-    $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
-    $selectFieldOp2 = $selectFieldOp2[1];
+    $selectFieldOp2URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href");
+    $selectFieldOp2 = $this->urlArg('oid', $selectFieldOp2URL);
 
     // create event.
     $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
@@ -1049,7 +1021,7 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
     $this->type('help_pre', 'This is test priceset.');
 
     $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
-    $this->clickLink('_qf_Set_next-bottom', 'newPriceField');
+    $this->clickLink('_qf_Set_next-bottom');
   }
 
   /**
@@ -1058,9 +1030,9 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
   function _testAddPriceFields($fields) {
     $fieldCount = count($fields);
     $count = 1;
-    $this->click('newPriceField');
     $this->waitForElementPresent('label');
     foreach ($fields as $label => $field) {
+      $this->waitForElementPresent('label');
       $this->type('label', $label);
       $this->select('html_type', "value={$field['type']}");
 
@@ -1102,6 +1074,7 @@ class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
       else {
         $this->click('_qf_Field_next-bottom');
       }
+      $this->waitForAjaxContent();
       $this->waitForText('crm-notification-container', "Price Field '$label' has been saved.");
 
       $count++;