Merge pull request #4865 from eileenmcnaughton/my-first-factory
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / OnBehalfOfOrganization.php
index a4af1e267320b42b2ab90e69ca583bbd12817274..6ee756dbdd89c327e270a2b6d6aad1ef4e6030c0 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
    +--------------------------------------------------------------------+
-   | CiviCRM version 4.5                                                |
+   | CiviCRM version 4.6                                                |
    +--------------------------------------------------------------------+
    | Copyright CiviCRM LLC (c) 2004-2014                                |
    +--------------------------------------------------------------------+
@@ -35,7 +35,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     parent::setUp();
   }
 
-  function testOnBehalfOfOrganization() {
+  public function testOnBehalfOfOrganization() {
     $this->webtestLogin();
 
     // create new individual
@@ -53,8 +53,8 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->webtestAddContact($firstName, $lastName, $email);
     $cid = $this->urlArg('cid');
 
-    // We need a payment processor
-    $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
+    // Use default payment processor
+    $processorName = 'Test Processor';
     $processorType = 'Dummy';
     $pageTitle = substr(sha1(rand()), 0, 7);
     $rand = 100;
@@ -111,7 +111,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->_testUserWithMoreThanOneRelationship($pageId, $cid, $pageTitle);
   }
 
-  function testOnBehalfOfOrganizationWithMembershipData() {
+  public function testOnBehalfOfOrganizationWithMembershipData() {
     $this->webtestLogin();
 
     // create new individual
@@ -182,7 +182,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Is custom field created?
-    $this->assertTrue($this->isTextPresent("Your custom field '$checkboxFieldLabel' has been saved."));
+    $this->assertTrue($this->isTextPresent("Custom field '$checkboxFieldLabel' has been saved."));
 
     //create another custom field - Integer Radio
     $this->click("//a[@id='newCustomField']/span");
@@ -224,7 +224,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //Is custom field created
-    $this->assertTrue($this->isTextPresent("Your custom field '$radioFieldLabel' has been saved."));
+    $this->assertTrue($this->isTextPresent("Custom field '$radioFieldLabel' has been saved."));
 
     //add the above custom data to the On Behalf of Profile
     $this->openCiviPage("admin/uf/group", "reset=1");
@@ -236,14 +236,14 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->click("link=Add Field");
     $this->waitForElementPresent('_qf_Field_next-bottom');
     $this->select('field_name[0]', 'value=Membership');
-    $label = $checkboxFieldLabel.' :: '. $customGroupTitle;
+    $label = $checkboxFieldLabel . ' :: ' . $customGroupTitle;
     $this->select('field_name[1]', "label=$label");
     $this->click('field_name[1]');
     $this->click('_qf_Field_next_new-bottom');
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     $this->select('field_name[0]', 'value=Membership');
-    $label = $radioFieldLabel.' :: '. $customGroupTitle;
+    $label = $radioFieldLabel . ' :: ' . $customGroupTitle;
     $this->select('field_name[1]', "label=$label");
     $this->click('field_name[1]');
     $this->click('_qf_Field_next-bottom');
@@ -251,8 +251,8 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$radioFieldLabel}' has been saved to 'On Behalf Of Organization'."));
 
     //create organisation
-    $orgName = "Org WebAccess ". substr(sha1(rand()), 0, 7);
-    $orgEmail = "org". substr(sha1(rand()), 0, 7) . "@web.com";
+    $orgName = "Org WebAccess " . substr(sha1(rand()), 0, 7);
+    $orgEmail = "org" . substr(sha1(rand()), 0, 7) . "@web.com";
     $this->webtestAddOrganization($orgName, $orgEmail);
 
     $this->waitForPageToLoad($this->getTimeoutMsec());
@@ -315,8 +315,8 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->click("details-save");
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
-    // We need a payment processor
-    $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
+    // Use default payment processor
+    $processorName = 'Test Processor';
     $processorType = 'Dummy';
     $pageTitle = substr(sha1(rand()), 0, 7);
     $rand = 100;
@@ -374,11 +374,13 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     // Add membership custom data field to profile
     $this->waitForElementPresent('_qf_Group_cancel-bottom');
     $this->type('title', $profileTitle);
-    $this->click('_qf_Group_next-bottom');
+    $this->clickLink('_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."));
 
+    $gid = $this->urlArg('gid');
+
+    $this->openCiviPage('admin/uf/group/field/add', array('action' => 'add', 'reset' => 1, 'gid' => $gid), 'field_name[0]');
     $this->select('field_name[0]', "value=Membership");
     $this->select('field_name[1]', "label={$checkboxFieldLabel} :: {$customGroupTitle}");
     $this->click('field_name[1]');
@@ -440,7 +442,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->webtestLogout();
   }
 
-  function testOnBehalfOfOrganizationWithOrgData() {
+  public function testOnBehalfOfOrganizationWithOrgData() {
     $this->webtestLogin();
 
     $this->openCiviPage("profile/edit", "reset=1&gid=4");
@@ -480,8 +482,8 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
     //create organisation
-    $orgName = "Org WebAccess ". substr(sha1(rand()), 0, 7);
-    $orgEmail = "org". substr(sha1(rand()), 0, 7) . "@web.com";
+    $orgName = "Org WebAccess " . substr(sha1(rand()), 0, 7);
+    $orgEmail = "org" . substr(sha1(rand()), 0, 7) . "@web.com";
     $this->webtestAddOrganization($orgName, $orgEmail);
 
     $this->waitForPageToLoad($this->getTimeoutMsec());
@@ -535,7 +537,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $pageId = $this->webtestAddContributionPage($hash,
       $rand,
       $pageTitle,
-      null,
+      NULL,
       $amountSection,
       $payLater,
       $onBehalf,
@@ -555,15 +557,101 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
       $honoreeSection
     );
 
-     $this->_testOrganization($pageId, $cid, $pageTitle);
+    $this->_testOrganization($pageId, $cid, $pageTitle);
+  }
+
+  public function testWithContactSubtypeDupe() {
+    $this->webtestLogin();
+
+    //create organisation
+    $orgName = "Org WebAccess " . substr(sha1(rand()), 0, 7);
+    $orgEmail = "org" . substr(sha1(rand()), 0, 7) . "@web.com";
+    $contactSubType = 'Sponsor';
+    $this->webtestAddOrganization($orgName, $orgEmail, $contactSubType);
+
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $cid = $this->urlArg('cid');
+
+    $pageTitle = substr(sha1(rand()), 0, 7);
+    $rand = 100;
+    $hash = substr(sha1(rand()), 0, 7);
+    $amountSection = TRUE;
+    $payLater = TRUE;
+    $onBehalf = TRUE;
+    $pledges = FALSE;
+    $recurring = FALSE;
+    $memberships = FALSE;
+    $memPriceSetId = NULL;
+    $friend = FALSE;
+    $profilePreId = NULL;
+    $profilePostId = NULL;
+    $premiums = FALSE;
+    $widget = FALSE;
+    $pcp = FALSE;
+    $honoreeSection = FALSE;
+    $isAddPaymentProcessor = FALSE;
+    $isPcpApprovalNeeded = FALSE;
+    $isSeparatePayment = FALSE;
+
+    // create a new online contribution page
+    // create contribution page with randomized title and default params
+    $pageId = $this->webtestAddContributionPage($hash,
+      $rand,
+      $pageTitle,
+      NULL,
+      $amountSection,
+      $payLater,
+      $onBehalf,
+      $pledges,
+      $recurring,
+      $memberships,
+      $memPriceSetId,
+      $friend,
+      $profilePreId,
+      $profilePostId,
+      $premiums,
+      $widget,
+      $pcp,
+      $isAddPaymentProcessor,
+      $isPcpApprovalNeeded,
+      $isSeparatePayment,
+      $honoreeSection
+    );
+
+    //Open Live Contribution Page
+    $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
+    $this->waitForElementPresent("onbehalf_state_province-3");
+
+    $this->type("onbehalf_organization_name", $orgName);
+    $this->waitForElementPresent("onbehalf_phone-3-1");
+    $this->type("onbehalf_phone-3-1", 9999999999);
+    $this->waitForElementPresent("onbehalf_email-3");
+    $this->type("onbehalf_email-3", "org@example.com");
+    $this->type("onbehalf_street_address-3", "Test Street Address");
+    $this->type("onbehalf_city-3", "Test City");
+    $this->type("onbehalf_postal_code-3", substr(sha1(rand()), 0, 6));
+    $this->click("onbehalf_country-3");
+    $this->select("onbehalf_country-3", "label=United States");
+    $this->click("onbehalf_state_province-3");
+    $this->select("onbehalf_state_province-3", "label=Alabama");
+
+    $this->waitForElementPresent("_qf_Main_upload-bottom");
+    $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
+
+    $this->click("_qf_Confirm_next-bottom");
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+
+    $this->openCiviPage("contact/view", "reset=1&cid=$cid", "xpath=//div[@class='crm-content crm-contact_type_label']");
+
+    $this->verifyText("xpath=//div[@class='crm-content crm-contact_type_label']", $contactSubType);
   }
 
   /**
-   * @param $pageId
-   * @param $cid
+   * @param int $pageId
+   * @param int $cid
    * @param $pageTitle
    */
-  function _testOrganization($pageId, $cid, $pageTitle) {
+  public function _testOrganization($pageId, $cid, $pageTitle) {
     //Open Live Contribution Page
     $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
 
@@ -590,11 +678,11 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
   }
 
   /**
-   * @param $pageId
-   * @param $cid
+   * @param int $pageId
+   * @param int $cid
    * @param $pageTitle
    */
-  function _testAnomoyousOganization($pageId, $cid, $pageTitle) {
+  public function _testAnomoyousOganization($pageId, $cid, $pageTitle) {
     //Open Live Contribution Page
     $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
 
@@ -665,11 +753,11 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
   }
 
   /**
-   * @param $pageId
-   * @param $cid
+   * @param int $pageId
+   * @param int $cid
    * @param $pageTitle
    */
-  function _testUserWithOneRelationship($pageId, $cid, $pageTitle) {
+  public function _testUserWithOneRelationship($pageId, $cid, $pageTitle) {
     $this->webtestLogin('admin');
 
     // Create new group
@@ -727,7 +815,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->click('_qf_Field_next-bottom');
 
     $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->assertTrue($this->isTextPresent("Your custom field '$fieldTitle' has been saved."));
+    $this->assertTrue($this->isTextPresent("Custom field '$fieldTitle' has been saved."));
     $fieldId = $this->urlArg('id', $this->getAttribute("xpath=//div[@id='field_page']/div[2]/table/tbody//tr/td[1][text()='$fieldTitle']/../td[8]/span/a@href"));
 
     // Enable CiviCampaign module if necessary
@@ -911,11 +999,11 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
   }
 
   /**
-   * @param $pageId
-   * @param $cid
+   * @param int $pageId
+   * @param int $cid
    * @param $pageTitle
    */
-  function _testUserWithMoreThanOneRelationship($pageId, $cid, $pageTitle) {
+  public function _testUserWithMoreThanOneRelationship($pageId, $cid, $pageTitle) {
     $this->webtestLogin('admin');
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
@@ -977,7 +1065,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->click('_qf_Field_next-bottom');
 
     $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->assertTrue($this->isTextPresent("Your custom field '$fieldTitle' has been saved."));
+    $this->assertTrue($this->isTextPresent("Custom field '$fieldTitle' has been saved."));
     $fieldId = $this->urlArg('id', $this->getAttribute("xpath=//div[@id='field_page']/div[2]/table/tbody//tr/td[1]/span[text()='$fieldTitle']/../td[8]/span/a@href"));
 
     // Enable CiviCampaign module if necessary
@@ -1119,7 +1207,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
 
     $this->type('minimum_fee', '50');
 
-    $this->select( 'financial_type_id', 'value=2' );
+    $this->select('financial_type_id', 'value=2');
 
     $this->type('duration_interval', 1);
     $this->select('duration_unit', "label=year");
@@ -1280,7 +1368,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->click("xpath=//div[@id='current-relationships']/div/table/tbody//tr/td[2]/a[text()='{$orgName1}']/../../td[9]/span[2][text()='more ']/ul/li[2]/a[text()='Delete']");
 
     // Check confirmation alert.
-    $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this relationship?/",
+    $this->assertTrue((bool) preg_match("/^Are you sure you want to delete this relationship?/",
         $this->getConfirmation()
       ));
     $this->chooseOkOnNextConfirmation();
@@ -1290,7 +1378,7 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     );
   }
 
-  function testOnBehalfOfOrganizationWithImage() {
+  public function testOnBehalfOfOrganizationWithImage() {
     $this->webtestLogin();
 
     $this->openCiviPage("profile/edit", "reset=1&gid=4");
@@ -1323,8 +1411,8 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->click('_qf_Field_next-bottom');
     $this->waitForPageToLoad($this->getTimeoutMsec());
 
-    // We need a payment processor
-    $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
+    // Use default payment processor
+    $processorName = 'Test Processor';
     $processorType = 'Dummy';
     $pageTitle = substr(sha1(rand()), 0, 7);
     $rand = 100;
@@ -1387,11 +1475,11 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
   }
 
   /**
-   * @param $pageId
-   * @param $cid
+   * @param int $pageId
+   * @param int $cid
    * @param $pageTitle
    */
-  function _testOrganizationWithImageUpload($pageId, $cid, $pageTitle) {
+  public function _testOrganizationWithImageUpload($pageId, $cid, $pageTitle) {
     //Open Live Contribution Page
     $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", '_qf_Main_upload-bottom');
 
@@ -1420,8 +1508,8 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
       or die("Cannot Initialize new GD image stream");
     $background_color = imagecolorallocate($im, 0, 0, 0);
     $text_color = imagecolorallocate($im, 233, 14, 91);
-    imagestring($im, 1, 5, 5,  "On Behalf-Org Logo", $text_color);
-    imagepng($im,"/tmp/file.png");
+    imagestring($im, 1, 5, 5, "On Behalf-Org Logo", $text_color);
+    imagepng($im, "/tmp/file.png");
 
     $imagePath = "/tmp/file.png";
     $this->webtestAttachFile('onbehalf_image_URL', $imagePath);
@@ -1463,4 +1551,3 @@ class WebTest_Contribute_OnBehalfOfOrganization extends CiviSeleniumTestCase {
     $this->assertTrue($this->isElementPresent("xpath=//div[@id='crm-contact-thumbnail']/div/a/img"));
   }
 }
-