From: Pratik Joshi Date: Tue, 30 Apr 2013 13:13:43 +0000 (+0530) Subject: CRM-12378 a new webtest helper function introduction which can help detect break... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c4e6d4e890820913f538dc4e1663dfad2885d75e;p=civicrm-core.git CRM-12378 a new webtest helper function introduction which can help detect break mentioned in CRM-12331 --- diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index 9caeec4d77..fac1e087cb 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -1808,5 +1808,101 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $timeout = ($this->settings && @$this->settings->timeout) ? ($this->settings->timeout * 1000) : 30000; return (string) $timeout; // don't know why, but all our old code used a string } -} + /** + * CRM-12378 + * checks custom fields rendering / loading properly on the fly WRT entity passed as parameter + * + * + * @param array $customSets custom sets i.e entity wise sets want to be created and checked + e.g $customSets = array(array('entity' => 'Contribution', 'subEntity' => 'Donation', + 'triggerElement' => $triggerElement)) + array $triggerElement: the element which is responsible for custom group to load + + which uses the entity info as its selection value + * @param array $pageUrl the url which on which the ajax custom group load takes place + * @return void + */ + function customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl) { + //add the custom set + $return = $this->addCustomGroupField($customSets); + + $this->openCiviPage($pageUrl['url'], $pageUrl['args']); + + foreach($return as $values) { + foreach ($values as $entityType => $customData) { + //initiate necessary variables + list($entity, $entityData) = explode('_', $entityType); + $elementType = CRM_Utils_Array::value('type', $customData['triggerElement'], 'select'); + $elementName = CRM_Utils_Array::value('name', $customData['triggerElement']); + if ($elementType == 'select') { + //reset the select box, so triggering of ajax only happens + //WRT input of value in this function + $this->select($elementName, "index=0"); + } + if (!empty($entityData)) { + if ($elementType == 'select') { + $this->select($elementName, "label=regexp:{$entityData}"); + } + elseif ($elementType == 'checkbox') { + $val = explode(',', $entityData); + foreach($val as $v) { + $checkId = $this->getAttribute("xpath=//label[text()='{$v}']/@for"); + $this->check($checkId); + } + } + } + + //sleep method is used as to wait for custom field div to load - + //we cant use wait for the div element as we are asserting for the same, + //so wait for some time till the div loads + sleep(1); + + //checking for proper custom data which is loading through ajax + $this->assertElementPresent("xpath=//div[@id='{$customData['cgtitle']}'][@class='crm-accordion-body']", + "The on the fly custom group has not been rendered for entity : {$entity} => {$entityData}"); + $this->assertElementPresent("xpath=//div[@id='{$customData['cgtitle']}'][@class='crm-accordion-body']/table/tbody/tr/td[2]/input", + "The on the fly custom group field is not present for entity : {$entity} => {$entityData}"); + } + } + } + + function addCustomGroupField($customSets) { + foreach ($customSets as $customSet) { + $this->openCiviPage("admin/custom/group", "action=add&reset=1"); + + //fill custom group title + $customGroupTitle = "webtest_for_ajax_cd" . substr(sha1(rand()), 0, 4); + $this->click("title"); + $this->type("title", $customGroupTitle); + + //custom group extends + $this->click("extends_0"); + $this->select("extends_0", "value={$customSet['entity']}"); + if (!empty($customSet['subEntity'])) { + $this->addSelection("extends_1", "label={$customSet['subEntity']}"); + } + + // Don't collapse + $this->uncheck('collapse_display'); + + // Save + $this->click('_qf_Group_next-bottom'); + $this->waitForElementPresent('_qf_Field_cancel-bottom'); + + //Is custom group created? + $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added."); + $gid = $this->urlArg('gid'); + + $fieldLabel = "custom_field_for_{$customSet['entity']}_{$customSet['subEntity']}" . substr(sha1(rand()), 0, 4); + $this->type('label', $fieldLabel); + $this->click('_qf_Field_next-bottom'); + $this->waitForPageToLoad($this->getTimeoutMsec()); + $customGroupTitle = preg_replace('/\s/', '_', trim($customGroupTitle)); + + $return[] = array( + "{$customSet['entity']}_{$customSet['subEntity']}" => array('cgtitle' => $customGroupTitle, 'gid' => $gid, 'triggerElement' => $customSet['triggerElement'])); + } + return $return; + } +} \ No newline at end of file diff --git a/tests/phpunit/WebTest/Activity/StandaloneAddTest.php b/tests/phpunit/WebTest/Activity/StandaloneAddTest.php index de875dd7bd..5d4b87e4d2 100644 --- a/tests/phpunit/WebTest/Activity/StandaloneAddTest.php +++ b/tests/phpunit/WebTest/Activity/StandaloneAddTest.php @@ -162,5 +162,16 @@ class WebTest_Activity_StandaloneAddTest extends CiviSeleniumTestCase { ) ); } -} + function testAjaxCustomGroupLoad() { + $this->webtestLogin(); + $triggerElement = array('name' => 'activity_type_id', 'type' => 'select'); + $customSets = array( + array('entity' => 'Activity', 'subEntity' => 'Interview', 'triggerElement' => $triggerElement), + array('entity' => 'Activity', 'subEntity' => 'Meeting', 'triggerElement' => $triggerElement) + ); + + $pageUrl = array('url' => 'activity', 'args' => 'reset=1&action=add&context=standalone'); + $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); + } +} \ No newline at end of file diff --git a/tests/phpunit/WebTest/Campaign/CampaignDescriptionTest.php b/tests/phpunit/WebTest/Campaign/CampaignDescriptionTest.php index a12087da18..76b977f1bf 100644 --- a/tests/phpunit/WebTest/Campaign/CampaignDescriptionTest.php +++ b/tests/phpunit/WebTest/Campaign/CampaignDescriptionTest.php @@ -82,5 +82,16 @@ class WebTest_Campaign_CampaignDescriptionTest extends CiviSeleniumTestCase { $fetchedVaue = $this->getValue('description'); $this->assertEquals($campaignDescription, $fetchedVaue); } -} + function testAjaxCustomGroupLoad() { + $this->webtestLogin(); + $triggerElement = array('name' => 'campaign_type_id', 'type' => 'select'); + $customSets = array( + array('entity' => 'Campaign', 'subEntity' => 'Referral Program', 'triggerElement' => $triggerElement), + array('entity' => 'Campaign', 'subEntity' => 'Constituent Engagement', 'triggerElement' => $triggerElement) + ); + + $pageUrl = array('url' => 'campaign/add', 'args' => 'reset=1'); + $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); + } +} \ No newline at end of file diff --git a/tests/phpunit/WebTest/Case/AddCaseTest.php b/tests/phpunit/WebTest/Case/AddCaseTest.php index 13350f1ff3..b548ea3d06 100644 --- a/tests/phpunit/WebTest/Case/AddCaseTest.php +++ b/tests/phpunit/WebTest/Case/AddCaseTest.php @@ -140,6 +140,21 @@ class WebTest_Case_AddCaseTest extends CiviSeleniumTestCase { $this->_testSearchbyDate($firstName, $lastName, "this.year"); } + function testAjaxCustomGroupLoad() { + $this->webtestLogin(); + + // Enable CiviCase module if necessary + $this->enableComponents("CiviCase"); + + $triggerElement = array('name' => 'case_type_id', 'type' => 'select'); + $customSets = array( + array('entity' => 'Case', 'subEntity' => 'Housing Support', 'triggerElement' => $triggerElement), + ); + + $pageUrl = array('url' => 'case/add', 'args' => "reset=1&action=add&atype=13&context=standalone"); + $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); + } + function _testVerifyCaseSummary($validateStrings, $activityTypes) { $this->assertStringsPresent($validateStrings); foreach ($activityTypes as $aType) { diff --git a/tests/phpunit/WebTest/Contact/RelationshipAddTest.php b/tests/phpunit/WebTest/Contact/RelationshipAddTest.php index 6f63cc55d6..7039416d5c 100644 --- a/tests/phpunit/WebTest/Contact/RelationshipAddTest.php +++ b/tests/phpunit/WebTest/Contact/RelationshipAddTest.php @@ -352,5 +352,22 @@ class WebTest_Contact_RelationshipAddTest extends CiviSeleniumTestCase { ); $this->assertTrue($this->isTextPresent($params['label_a_b'])); } -} + function testAjaxCustomGroupLoad() { + $this->webtestLogin(); + + //create a New Individual + $firstName = substr(sha1(rand()), 0, 7); + $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name"); + $contactId = explode('cid=', $this->getLocation()); + + $triggerElement = array('name' => 'relationship_type_id', 'type' => 'select'); + $customSets = array( + array('entity' => 'Relationship', 'subEntity' => 'Partner of', 'triggerElement' => $triggerElement), + array('entity' => 'Relationship', 'subEntity' => 'Spouse of', 'triggerElement' => $triggerElement) + ); + + $pageUrl = array('url' => 'contact/view/rel', 'args' => "cid={$contactId[1]}&action=add&reset=1"); + $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); + } +} \ No newline at end of file diff --git a/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php b/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php index e7e5a57102..89f4fa99dd 100644 --- a/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php +++ b/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php @@ -177,5 +177,16 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase { $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label)); } } -} + function testAjaxCustomGroupLoad() { + $this->webtestLogin(); + $triggerElement = array('name' => 'financial_type_id', 'type' => 'select'); + $customSets = array( + array('entity' => 'Contribution', 'subEntity' => 'Donation', 'triggerElement' => $triggerElement), + array('entity' => 'Contribution', 'subEntity' => 'Member Dues', 'triggerElement' => $triggerElement) + ); + + $pageUrl = array('url' => 'contribute/add', 'args' => 'reset=1&action=add&context=standalone'); + $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); + } +} \ No newline at end of file diff --git a/tests/phpunit/WebTest/Event/AddEventTest.php b/tests/phpunit/WebTest/Event/AddEventTest.php index 67dd5ea5db..8feae5d7e9 100644 --- a/tests/phpunit/WebTest/Event/AddEventTest.php +++ b/tests/phpunit/WebTest/Event/AddEventTest.php @@ -310,6 +310,18 @@ class WebTest_Event_AddEventTest extends CiviSeleniumTestCase { $this->assertNotChecked('is_pay_later'); } + function testAjaxCustomGroupLoad() { + $this->webtestLogin(); + + $triggerElement = array('name' => 'event_type_id', 'type' => 'select'); + $customSets = array( + array('entity' => 'Event', 'subEntity' => 'Conference', 'triggerElement' => $triggerElement), + ); + + $pageUrl = array('url' => 'event/add', 'args' => "reset=1&action=add"); + $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); + } + function _testAddEventInfo($eventTitle, $eventDescription) { $this->waitForElementPresent("_qf_EventInfo_upload-bottom"); diff --git a/tests/phpunit/WebTest/Event/AddParticipationTest.php b/tests/phpunit/WebTest/Event/AddParticipationTest.php index 792de9a2d7..a5cda779ff 100644 --- a/tests/phpunit/WebTest/Event/AddParticipationTest.php +++ b/tests/phpunit/WebTest/Event/AddParticipationTest.php @@ -372,6 +372,18 @@ class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase { } } + function testAjaxCustomGroupLoad() { + $this->webtestLogin(); + + $customSets = array( + array('entity' => 'ParticipantEventName', 'subEntity' => 'Fall Fundraiser Dinner', + 'triggerElement' => array('name' => "event_id", 'type' => "select")), + array('entity' => 'ParticipantRole', 'subEntity' => 'Attendee','triggerElement' => array('type' => "checkbox")) + ); + $pageUrl = array('url' => "participant/add", 'args' => "reset=1&action=add&context=standalone"); + $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); + } + function _fillParticipantDetails($firstName, $lastName, $processorId) { $this->select("id=profiles_1", "label=New Individual"); $this->waitForElementPresent('_qf_Edit_next'); @@ -385,5 +397,4 @@ class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase { $this->webtestAddCreditCardDetails(); $this->webtestAddBillingDetails(); } -} - +} \ No newline at end of file diff --git a/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php b/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php index fbb602d29a..65390ffece 100644 --- a/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php +++ b/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php @@ -109,5 +109,20 @@ class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase { ) ); } -} + function testAjaxCustomGroupLoad() { + $this->webtestLogin(); + + // Enable CiviGrant module if necessary + $this->enableComponents("CiviGrant"); + + $triggerElement = array('name' => 'grant_type_id', 'type' => 'select'); + $customSets = array( + array('entity' => 'Grant', 'subEntity' => 'Emergency', 'triggerElement' => $triggerElement), + array('entity' => 'Grant', 'subEntity' => 'Family Support', 'triggerElement' => $triggerElement) + ); + + $pageUrl = array('url' => 'grant/add', 'args' => 'reset=1&action=add&context=standalone'); + $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); + } +} \ No newline at end of file diff --git a/tests/phpunit/WebTest/Member/StandaloneAddTest.php b/tests/phpunit/WebTest/Member/StandaloneAddTest.php index 0e16c2b451..fab7c651e3 100644 --- a/tests/phpunit/WebTest/Member/StandaloneAddTest.php +++ b/tests/phpunit/WebTest/Member/StandaloneAddTest.php @@ -161,5 +161,16 @@ class WebTest_Member_StandaloneAddTest extends CiviSeleniumTestCase { ); $this->webtestVerifyTabularData($expected); } -} + function testAjaxCustomGroupLoad() { + $this->webtestLogin(); + $triggerElement = array('name' => 'membership_type_id_1', 'type' => 'select'); + $customSets = array( + array('entity' => 'Membership', 'subEntity' => 'General', 'triggerElement' => $triggerElement), + array('entity' => 'Membership', 'subEntity' => 'Student', 'triggerElement' => $triggerElement) + ); + + $pageUrl = array('url' => 'member/add', 'args' => 'reset=1&action=add&context=standalone'); + $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); + } +} \ No newline at end of file