Skip to content

Commit

Permalink
Merge pull request #7 from pratik-joshi/webtests-cleanup-and-fixes
Browse files Browse the repository at this point in the history
more webtest cleanup and code improvement
  • Loading branch information
kurund committed Mar 1, 2013
2 parents b00ad09 + b255257 commit 6610dbb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 57 deletions.
60 changes: 23 additions & 37 deletions tests/phpunit/WebTest/Profile/BatchUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ function testBatchUpdateWithContactSubtypes() {

// Log in using webtestLogin() method
$this->webtestLogin();

// Add new individual using Quick Add block on the main page
$firstName1 = "John_" . substr(sha1(rand()), 0, 7);
$lastName1 = "Smiths_x" . substr(sha1(rand()), 0, 7);
$Name1 = $lastName1 . ', ' . $firstName1;
$this->webtestAddContact($firstName1, $lastName1, "$firstName1.$lastName1@example.com");
$this->waitForPageToLoad($this->getTimeoutMsec());

// Add new individual using Quick Add block on the main page
$firstName2 = "James_" . substr(sha1(rand()), 0, 7);
$lastName2 = "Smiths_x" . substr(sha1(rand()), 0, 7);
$Name2 = $lastName2 . ', ' . $firstName2;

$firstName3 = "James_" . substr(sha1(rand()), 0, 7);
$lastName3 = "Smiths_x" . substr(sha1(rand()), 0, 7);
$Name3 = $lastName3 . ', ' . $firstName3;
Expand All @@ -73,9 +73,7 @@ function testBatchUpdateWithContactSubtypes() {
'label' => 'Last Name'
));
$this->addProfile($profileTitle, $profileFields);

$this->open($this->sboxPath . "civicrm/contact/search?reset=1");
$this->waitForElementPresent('_qf_Basic_refresh');
$this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh');
$this->type('sort_name', "Smiths_x");
$this->click('_qf_Basic_refresh');
$this->waitForElementPresent('_qf_Basic_next_print');
Expand All @@ -96,9 +94,9 @@ function testBatchUpdateWithContactSubtypes() {
$this->isElementPresent("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name2}']");
$this->isElementPresent("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name1}']");
$this->isElementPresent("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name3}']");
// selecting first check of profile
// selecting first check of profile
$this->click("xpath=//form[@id='Batch']/div[2]/table/tbody/tr/td[2]/input");

$this->waitForElementPresent('_qf_Batch_next');
$this->click("xpath=//table[@class='crm-copy-fields']/thead/tr/td[2]/img");
sleep(5);
Expand All @@ -108,28 +106,24 @@ function testBatchUpdateWithContactSubtypes() {
$this->waitForElementPresent('_qf_Result_done');
$this->click('_qf_Result_done');

// Find contact and assert for contact sub type
$this->open($this->sboxPath . "civicrm/contact/search?reset=1");
$this->waitForElementPresent('_qf_Basic_refresh');

// Find contact and assert for contact sub type
$this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh');
$this->type('sort_name', $firstName2);
$this->click('_qf_Basic_refresh');
$this->waitForElementPresent("xpath=//div[@class='crm-search-results']/table/tbody//td/span/a[text()='View']");
$this->click("xpath=//div[@class='crm-search-results']/table/tbody//td/span/a[text()='View']");
$this->waitForPageToLoad($this->getTimeoutMsec());
$this->waitForPageToLoad($this->getTimeoutMsec());

$xpath = "xpath=//div[@id='contact-summary']/div/div[2]/div/div/div[2]/div[@class='crm-content crm-contact_type_label']";
$this->verifyText($xpath, preg_quote("Student"));

$this->open($this->sboxPath . "civicrm/contact/search?reset=1");
$this->waitForElementPresent('_qf_Basic_refresh');

$this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh');
$this->type('sort_name', $firstName3);
$this->click('_qf_Basic_refresh');
$this->waitForElementPresent("xpath=//div[@class='crm-search-results']/table/tbody//td/span/a[text()='View']");
$this->click("xpath=//div[@class='crm-search-results']/table/tbody//td/span/a[text()='View']");
$this->waitForPageToLoad($this->getTimeoutMsec());
$this->waitForPageToLoad($this->getTimeoutMsec());

$xpath = "xpath=//div[@id='contact-summary']/div/div[2]/div/div/div[2]/div[@class='crm-content crm-contact_type_label']";
$this->verifyText($xpath, preg_quote("Staff"));
}
Expand Down Expand Up @@ -161,15 +155,13 @@ function testBatchUpdate() {
$this->_addProfile($profileTitle, $customDataArr, $profileFor);

//setting ckeditor as WYSIWYG
$this->open($this->sboxPath . "civicrm/admin/setting/preferences/display?reset=1");
$this->waitForElementPresent('_qf_Display_next-bottom');
$this->openCiviPage('admin/setting/preferences/display', 'reset=1', '_qf_Display_next-bottom');
$this->select('editor_id', 'CKEditor');
$this->click('_qf_Display_next-bottom');
$this->waitForPageToLoad($this->getTimeoutMsec());

// Find Contact
$this->open($this->sboxPath . "civicrm/contact/search?reset=1");
$this->waitForElementPresent('_qf_Basic_refresh');
$this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh');
$this->type('sort_name', $lastName);
$this->click('_qf_Basic_refresh');
$this->waitForElementPresent('_qf_Basic_next_print');
Expand All @@ -192,7 +184,7 @@ function testBatchUpdate() {

// selecting first check of profile
$this->click("xpath=//form[@id='Batch']/div[2]/table/tbody/tr/td[2]/table/tbody/tr/td/input[2]");

// selecting second check of profile
$this->click("xpath=//form[@id='Batch']/div[2]/table/tbody/tr/td[3]/input[2]");
// clicking copy values to rows of first check and verifying
Expand Down Expand Up @@ -314,15 +306,13 @@ function testBatchUpdate() {
$this->assertTrue($assertCheck, 'copy rows for field two failed[radio button]');

//test with tinymce editor
$this->open($this->sboxPath . "civicrm/admin/setting/preferences/display?reset=1");
$this->waitForElementPresent('_qf_Display_next-bottom');
$this->openCiviPage('admin/setting/preferences/display', 'reset=1', '_qf_Display_next-bottom');
$this->select('editor_id', 'TinyMCE');
$this->click('_qf_Display_next-bottom');
$this->waitForPageToLoad($this->getTimeoutMsec());

// Find Contact
$this->open($this->sboxPath . "civicrm/contact/search?reset=1");
$this->waitForElementPresent('_qf_Basic_refresh');
$this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh');
$this->type('sort_name', $lastName);
$this->click('_qf_Basic_refresh');
$this->waitForElementPresent('_qf_Basic_next_print');
Expand Down Expand Up @@ -361,23 +351,20 @@ function testBatchUpdate() {
$this->assertTrue($assertCheck, 'Rich Text Area coping failed [TinyMCE]');

//campaign test for interview
// Enable CiviCampaign module if necessary
$this->open($this->sboxPath . "civicrm/admin/setting/component?reset=1");
$this->waitForPageToLoad($this->getTimeoutMsec());
$this->waitForElementPresent("_qf_Component_next-bottom");
//enable CiviCampaign module if necessary
$this->openCiviPage('admin/setting/component', 'reset=1', '_qf_Component_next-bottom');
$enabledComponents = $this->getSelectOptions("enableComponents-t");
if (!in_array("CiviCampaign", $enabledComponents)) {
$this->addSelection("enableComponents-f", "label=CiviCampaign");
$this->click("//option[@value='CiviCampaign']");
$this->click("add");
$this->click("_qf_Component_next-bottom");
$this->waitForPageToLoad($this->getTimeoutMsec());
$this->assertTrue($this->isTextPresent("Your changes have been saved."));
$this->assertElementContainsText('crm-notification-container', 'Changes Saved');
}

//Adding a survey
$this->open($this->sboxPath . "civicrm/survey/add?reset=1");
$this->waitForElementPresent('_qf_Main_upload-bottom');
$this->openCiviPage('survey/add', 'reset=1', '_qf_Main_upload-bottom');
$surveyTitle = "BatchUpdateTest Survey" . substr(sha1(rand()), 0, 7);
$this->type("title", $surveyTitle);
$this->select('activity_type_id', 'label=Survey');
Expand Down Expand Up @@ -619,7 +606,7 @@ function _addCustomData($profileFor) {

//setting options per line to check CRM-9938
$this->type("options_per_line", 2);

//clicking save
$this->click('_qf_Field_next');
$this->waitForPageToLoad($this->getTimeoutMsec());
Expand Down Expand Up @@ -772,5 +759,4 @@ function _addCustomData($profileFor) {

return $returnArray;
}
}

}
35 changes: 15 additions & 20 deletions tests/phpunit/WebTest/Profile/MultiRecordProfileAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function testUserAddNewProfile() {
$this->webtestLogin();
$this->_addNewProfile(TRUE, FALSE, TRUE);
}

function testAddNewNonMultiProfile() {
// This is the path where our testing install resides.
// The rest of URL is defined in CiviSeleniumTestCase base class, in
Expand All @@ -75,7 +75,7 @@ function testAddNewNonMultiProfile() {
$this->webtestLogin();
$this->_addNewProfile(FALSE);
}

function testNonSearchableMultiProfile() {
// This is the path where our testing install resides.
// The rest of URL is defined in CiviSeleniumTestCase base class, in
Expand All @@ -90,18 +90,15 @@ function testNonSearchableMultiProfile() {
$this->webtestLogin();
$this->_addNewProfile(TRUE, TRUE);
}

function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $userCheck = FALSE) {

$params = $this->_testCustomAdd($checkSearchable);
// Go directly to the URL of the screen that you will be
// testing (Add new profile ).
$this->open($this->sboxPath . 'civicrm/admin/uf/group?reset=1');

$this->waitForPageToLoad($this->getTimeoutMsec());

$this->click('newCiviCRMProfile-top');

$this->click('newCiviCRMProfile-top');
$this->waitForElementPresent('_qf_Group_next-bottom');

//Name of profile
Expand Down Expand Up @@ -149,7 +146,7 @@ function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $use
$this->waitForElementPresent('field_name[0]');
$this->click('field_name[0]');
$this->select('field_name[0]', 'value=Contact');
$this->click("//option[@value='Contact']");
$this->click("//option[@value='Contact']");
$this->click('field_name_1');
$this->select('field_name_1', 'label='.$params['textFieldLabel'].' :: '.$params['customGroupTitle']);
if ($checkMultiRecord) {
Expand Down Expand Up @@ -186,7 +183,7 @@ function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $use
$this->click('field_name[0]');
$this->select('field_name[0]', 'value=Student');
$this->click("//option[@value='Student']");

$this->click('field_name_1');
$this->select('field_name_1', 'value=first_name');
$this->click('is_multi_summary');
Expand Down Expand Up @@ -224,20 +221,18 @@ function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $use
$recordNew = $this->_addRecords('Create');
$this->waitForPageToLoad($this->getTimeoutMsec());
$elements = $this->parseURL( );

$gid = $elements['queryString']['gid'];
$id = $elements['queryString']['id'];

if ($userCheck) {
// Add Drupal user
$this->open($this->sboxPath . "civicrm/contact/view/useradd?reset=1&action=add&cid=$id");
$this->waitForElementPresent('cms_name');
//add drupal user
$this->openCiviPage('contact/view/useradd', "reset=1&action=add&cid=$id", 'cms_name');
$this->type('cms_name', $recordNew['firstname']);
$this->type('cms_pass', $recordNew['firstname']);
$this->type('cms_confirm_pass', $recordNew['firstname']);
$this->click('_qf_Useradd_next-bottom');
$this->waitForPageToLoad($this->getTimeoutMsec());
$this->open( $this->settings->sandboxPATH . "user/logout");
$this->open($this->sboxPath . "user/logout");
$this->waitForPageToLoad($this->getTimeoutMsec());
$this->open("{$this->sboxPath}user");
// Make sure login form is available
Expand All @@ -264,10 +259,10 @@ function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $use
$record2 = $this->_addRecords();
$this->waitForPageToLoad($this->getTimeoutMsec());
$this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[3]/td[1]", preg_quote($record2['text']));

// Check Max Record Limit
$this->verifyElementNotPresent("//div[@id='crm-profile-block']/a/span");

//Check for edit functionality
sleep(3);
$this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='Edit']");
Expand All @@ -277,14 +272,14 @@ function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $use
$this->click("//div[@id='profile-dialog']/div/form/div[2]/div[2]/span/input[@id='_qf_Edit_next']");
$this->waitForPageToLoad($this->getTimeoutMsec());
$this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[1]/td[1]", preg_quote($recordNew['text'].'edit'));

// Check the delete functionality
$this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='Delete']");
$this->waitForElementPresent("//html/body/div[5]");
sleep(3);
$this->assertTrue($this->isTextPresent('Are you sure you want to delete this record?'));
$this->click('_qf_Edit_upload_delete');

// Check the view functionality
sleep(3);
$this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='View']");
Expand All @@ -295,7 +290,7 @@ function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $use
$this->verifyElementNotPresent("//div[@id='profile-dialog']/div/div/div/div[1]/div[2]/a");
return;
}

// Check Search Functionality
if (!$userCheck) {
$this->click("//div[@id='profile-dialog']/div/div/div/div/div[2]/a");
Expand Down

0 comments on commit 6610dbb

Please sign in to comment.