Skip to content

Commit

Permalink
Merge pull request #615 from pratik-joshi/CRM-12378
Browse files Browse the repository at this point in the history
CRM-12378 a new webtest helper function introduction which can help dete...
  • Loading branch information
kurund committed May 2, 2013
2 parents 0ba6e81 + c4e6d4e commit 2e26396
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 9 deletions.
98 changes: 97 additions & 1 deletion tests/phpunit/CiviTest/CiviSeleniumTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1808,5 +1808,101 @@ function getTimeoutMsec() {
$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;
}
}
13 changes: 12 additions & 1 deletion tests/phpunit/WebTest/Activity/StandaloneAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,16 @@ function testStandaloneActivityAdd() {
)
);
}
}

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);
}
}
13 changes: 12 additions & 1 deletion tests/phpunit/WebTest/Campaign/CampaignDescriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,16 @@ function testCreateCampaign() {
$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);
}
}
15 changes: 15 additions & 0 deletions tests/phpunit/WebTest/Case/AddCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ function testStandaloneCaseAdd() {
$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) {
Expand Down
19 changes: 18 additions & 1 deletion tests/phpunit/WebTest/Contact/RelationshipAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,22 @@ function testRelationshipAddNewIndividualTest() {
);
$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);
}
}
13 changes: 12 additions & 1 deletion tests/phpunit/WebTest/Contribute/StandaloneAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,16 @@ function testStandaloneContributeAdd() {
$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);
}
}
12 changes: 12 additions & 0 deletions tests/phpunit/WebTest/Event/AddEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ function testUnpaidPaid() {
$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");

Expand Down
15 changes: 13 additions & 2 deletions tests/phpunit/WebTest/Event/AddParticipationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,18 @@ function testEventAddMultipleParticipants() {
}
}

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');
Expand All @@ -385,5 +397,4 @@ function _fillParticipantDetails($firstName, $lastName, $processorId) {
$this->webtestAddCreditCardDetails();
$this->webtestAddBillingDetails();
}
}

}
17 changes: 16 additions & 1 deletion tests/phpunit/WebTest/Grant/CustomFieldsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,20 @@ function testCustomFieldsetTest() {
)
);
}
}

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);
}
}
13 changes: 12 additions & 1 deletion tests/phpunit/WebTest/Member/StandaloneAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,16 @@ function testStandaloneMemberOverrideAdd() {
);
$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);
}
}

0 comments on commit 2e26396

Please sign in to comment.