Skip to content

Commit

Permalink
[NFC] Fix PHPUnit8 deprecation warnings in the CRM_AllTests suite
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslee001 committed May 21, 2021
1 parent ddca0de commit 73b3529
Show file tree
Hide file tree
Showing 29 changed files with 96 additions and 97 deletions.
9 changes: 4 additions & 5 deletions tests/phpunit/CRM/Activity/BAO/ActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public function testActivityFilters() {
$this->checkArrayEquals($expectedFilters, $activityFilter);
// This should include activities of type Meeting only.
foreach ($activities['data'] as $value) {
$this->assertContains('Meeting', $value['activity_type']);
$this->assertStringContainsString('Meeting', $value['activity_type']);
}
unset($_GET['activity_type_id']);

Expand All @@ -525,7 +525,7 @@ public function testActivityFilters() {
$this->assertEquals(['activity_type_exclude_filter_id' => 1], $activityFilter);
// None of the activities should be of type Meeting.
foreach ($activities['data'] as $value) {
$this->assertNotContains('Meeting', $value['activity_type']);
$this->assertStringNotContainsString('Meeting', $value['activity_type']);
}
}

Expand Down Expand Up @@ -1299,14 +1299,13 @@ public function testSendEmailWithCampaign() {
}

/**
* @expectedException CRM_Core_Exception
* @expectedExceptionMessage You do not have the 'send SMS' permission
*/
public function testSendSMSWithoutPermission() {
$dummy = NULL;
$session = CRM_Core_Session::singleton();
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];

$this->expectException(CRM_Core_Exception::class);
$this->expectExceptionMessage('You do not have the \'send SMS\' permission');
CRM_Activity_BAO_Activity::sendSMS(
$dummy,
$dummy,
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Activity/Form/ActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public function testInboundEmailDisplaysWithLinebreaks() {

// This kind of suffers from the same problem as the old webtests. It's
// a bit brittle and tied to the UI.
$this->assertContains("Hi,<br />\n<br />\nWassup!?!?<br />\n<br />\nLet's check if the output when viewing the form has legible line breaks in the output.<br />\n<br />\nThanks!", $output);
$this->assertStringContainsString("Hi,<br />\n<br />\nWassup!?!?<br />\n<br />\nLet's check if the output when viewing the form has legible line breaks in the output.<br />\n<br />\nThanks!", $output);

// Put label back
$this->callAPISuccess('OptionValue', 'create', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testCreateDocumentBasicTokens(): void {

// Check some basic fields
foreach ($data as $line) {
$this->assertContains("\n" . $line[1] . "\n", $output[0]);
$this->assertStringContainsString("\n" . $line[1] . "\n", $output[0]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Case/BAO/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function testSortByCaseContact() {
];
$sortedActualContactNames = CRM_Utils_Array::collect('sort_name', $cases);
foreach ($sortedExpectedContactNames as $key => $name) {
$this->assertContains($name, $sortedActualContactNames[$key]);
$this->assertStringContainsString($name, $sortedActualContactNames[$key]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Case/Form/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testOpeningFindCaseForm() {
// as webtests. Mostly what we're doing in this test is checking that it
// doesn't generate any E_NOTICES/WARNINGS or other errors. But let's do
// one check.
$this->assertContains('<label for="case_id">', $contents);
$this->assertStringContainsString('<label for="case_id">', $contents);
}

}
8 changes: 4 additions & 4 deletions tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function testSmartGroupSearchBuilder() {
);
$key = $query->getGroupCacheTableKeys()[0];
$expectedWhere = "civicrm_group_contact_cache_{$key}.group_id IN (\"{$group2->id}\")";
$this->assertContains($expectedWhere, $query->_whereClause);
$this->assertStringContainsString($expectedWhere, $query->_whereClause);
$this->_assertContactIds($query, "group_id = {$group2->id}");

$params = [['group', '!=', $group->id, 1, 0]];
Expand Down Expand Up @@ -502,11 +502,11 @@ public function testMultipleGroupWhereClause() {
$this->assertContains($expectedWhere, $query->_whereClause);
// Check that we have 3 joins to the group contact cache 1 for each of the group where clauses and 1 for the fact we are returning groups in the select.
$expectedFrom1 = 'LEFT JOIN civicrm_group_contact_cache civicrm_group_contact_cache_' . $key1 . ' ON contact_a.id = civicrm_group_contact_cache_' . $key1 . '.contact_id';
$this->assertContains($expectedFrom1, $query->_fromClause);
$this->assertStringContainsString($expectedFrom1, $query->_fromClause);
$expectedFrom2 = 'LEFT JOIN civicrm_group_contact_cache civicrm_group_contact_cache_' . $key2 . ' ON contact_a.id = civicrm_group_contact_cache_' . $key2 . '.contact_id';
$this->assertContains($expectedFrom2, $query->_fromClause);
$this->assertStringContainsString($expectedFrom2, $query->_fromClause);
$expectedFrom3 = 'LEFT JOIN civicrm_group_contact_cache ON contact_a.id = civicrm_group_contact_cache.contact_id';
$this->assertContains($expectedFrom3, $query->_fromClause);
$this->assertStringContainsString($expectedFrom3, $query->_fromClause);
}

/**
Expand Down
22 changes: 11 additions & 11 deletions tests/phpunit/CRM/Contact/BAO/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,39 +445,39 @@ public function getSearchProfileData() {
*/
public function testSearchBuilderActivityType() {
$queryObj = new CRM_Contact_BAO_Query([['activity_type', '=', '3', 1, 0]]);
$this->assertContains('WHERE ( ( civicrm_activity.activity_type_id = 3 )', $queryObj->getSearchSQL());
$this->assertStringContainsString('WHERE ( ( civicrm_activity.activity_type_id = 3 )', $queryObj->getSearchSQL());
$this->assertEquals('Activity Type = Email', $queryObj->_qill[1][0]);

$queryObj = new CRM_Contact_BAO_Query([['activity_type_id', '=', '3', 1, 0]]);
$this->assertContains('WHERE ( ( civicrm_activity.activity_type_id = 3 )', $queryObj->getSearchSQL());
$this->assertStringContainsString('WHERE ( ( civicrm_activity.activity_type_id = 3 )', $queryObj->getSearchSQL());
$this->assertEquals('Activity Type ID = Email', $queryObj->_qill[1][0]);

$queryObj = new CRM_Contact_BAO_Query([['activity_status', '=', '3', 1, 0]]);
$this->assertContains('WHERE ( ( civicrm_activity.status_id = 3 )', $queryObj->getSearchSQL());
$this->assertStringContainsString('WHERE ( ( civicrm_activity.status_id = 3 )', $queryObj->getSearchSQL());
$this->assertEquals('Activity Status = Cancelled', $queryObj->_qill[1][0]);

$queryObj = new CRM_Contact_BAO_Query([['activity_status_id', '=', '3', 1, 0]]);
$this->assertContains('WHERE ( ( civicrm_activity.status_id = 3 )', $queryObj->getSearchSQL());
$this->assertStringContainsString('WHERE ( ( civicrm_activity.status_id = 3 )', $queryObj->getSearchSQL());
$this->assertEquals('Activity Status = Cancelled', $queryObj->_qill[1][0]);

$queryObj = new CRM_Contact_BAO_Query([['activity_engagement_level', '=', '3', 1, 0]]);
$this->assertContains('WHERE ( ( civicrm_activity.engagement_level = 3 )', $queryObj->getSearchSQL());
$this->assertStringContainsString('WHERE ( ( civicrm_activity.engagement_level = 3 )', $queryObj->getSearchSQL());
$this->assertEquals('Engagement Index = 3', $queryObj->_qill[1][0]);

$queryObj = new CRM_Contact_BAO_Query([['activity_id', '=', '3', 1, 0]]);
$this->assertContains('WHERE ( ( civicrm_activity.id = 3 )', $queryObj->getSearchSQL());
$this->assertStringContainsString('WHERE ( ( civicrm_activity.id = 3 )', $queryObj->getSearchSQL());
$this->assertEquals('Activity ID = 3', $queryObj->_qill[1][0]);

$queryObj = new CRM_Contact_BAO_Query([['activity_campaign_id', '=', '3', 1, 0]]);
$this->assertContains('WHERE ( ( civicrm_activity.campaign_id = 3 )', $queryObj->getSearchSQL());
$this->assertStringContainsString('WHERE ( ( civicrm_activity.campaign_id = 3 )', $queryObj->getSearchSQL());
$this->assertEquals('Campaign ID = 3', $queryObj->_qill[1][0]);

$queryObj = new CRM_Contact_BAO_Query([['activity_priority_id', '=', '3', 1, 0]]);
$this->assertContains('WHERE ( ( civicrm_activity.priority_id = 3 )', $queryObj->getSearchSQL());
$this->assertStringContainsString('WHERE ( ( civicrm_activity.priority_id = 3 )', $queryObj->getSearchSQL());
$this->assertEquals('Priority = Low', $queryObj->_qill[1][0]);

$queryObj = new CRM_Contact_BAO_Query([['activity_subject', '=', '3', 1, 0]]);
$this->assertContains("WHERE ( ( civicrm_activity.subject = '3' )", $queryObj->getSearchSQL());
$this->assertStringContainsString("WHERE ( ( civicrm_activity.subject = '3' )", $queryObj->getSearchSQL());
$this->assertEquals("Subject = '3'", $queryObj->_qill[1][0]);
}

Expand Down Expand Up @@ -834,7 +834,7 @@ public function testReciprocalRelationshipTargetGroupUsesTempTable() {
],
];
$sql = CRM_Contact_BAO_Query::getQuery($params);
$this->assertContains('INNER JOIN civicrm_tmp_e', $sql, 'Query appears to use temporary table of compiled relationships?', TRUE);
$this->assertStringContainsStringIgnoringCase('INNER JOIN civicrm_tmp_e', $sql, 'Query appears to use temporary table of compiled relationships?');
}

/**
Expand All @@ -845,7 +845,7 @@ public function testReciprocalRelationshipTargetGroupUsesTempTable() {
public function testRelationshipPermissionClause() {
$params = [['relation_type_id', 'IN', ['1_b_a'], 0, 0], ['relation_permission', 'IN', [2], 0, 0]];
$sql = CRM_Contact_BAO_Query::getQuery($params);
$this->assertContains('(civicrm_relationship.is_permission_a_b IN (2))', $sql);
$this->assertStringContainsString('(civicrm_relationship.is_permission_a_b IN (2))', $sql);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testRunSearch() {
$form = new CRM_Contact_Form_Search_Custom_PriceSet($formValues);
$sql = $form->all();
// Assert that we have created a standard temp table
$this->assertContains('civicrm_tmp_e_priceset', $sql);
$this->assertStringContainsString('civicrm_tmp_e_priceset', $sql);
// Check that the temp table has been populated.
$result = CRM_Core_DAO::executeQuery($sql)->fetchAll();
$this->assertTrue(!empty($result));
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testPostProcessWithSignature() {
$activity = Activity::get(FALSE)->setSelect(['details'])->execute()->first();
$bccUrl1 = CRM_Utils_System::url('civicrm/contact/view', ['reset' => 1, 'cid' => $bcc1], TRUE);
$bccUrl2 = CRM_Utils_System::url('civicrm/contact/view', ['reset' => 1, 'cid' => $bcc2], TRUE);
$this->assertContains("bcc : <a href='" . $bccUrl1 . "'>Mr. Anthony Anderson II</a>, <a href='" . $bccUrl2 . "'>Mr. Anthony Anderson II</a>", $activity['details']);
$this->assertStringContainsString("bcc : <a href='" . $bccUrl1 . "'>Mr. Anthony Anderson II</a>, <a href='" . $bccUrl2 . "'>Mr. Anthony Anderson II</a>", $activity['details']);
$this->assertEquals([
[
'text' => '27 messages were sent successfully. ',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testMailingLabel() {

foreach ($this->_contactIds as $contactID) {
// ensure that the address printed in the mailing labe is always primary if 'location_type_id' - none (as Primary) is chosen
$this->assertContains($addresses[$contactID]['primary']['street_address'], $rows[$contactID][0]);
$this->assertStringContainsString($addresses[$contactID]['primary']['street_address'], $rows[$contactID][0]);
}

// restore setting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public function testBrowseDisplaysCorrectListOfAddedGroups() {

$groupIn = CRM_Core_Smarty::singleton()->get_template_vars('groupIn');
$groupInTitles = CRM_Utils_Array::collect('title', $groupIn);
$this->assertContains($publicSmartGroupTitle, $groupInTitles, "Group '$publicSmartGroupTitle' should be in listed groups, but is not.");
$this->assertContains($publicStdGroupTitle, $groupInTitles, "Group '$publicStdGroupTitle' should be in listed groups, but is not.");
$this->assertNotContains($adminSmartGroupTitle, $groupInTitles, "Group '$adminSmartGroupTitle' should not be in listed groups, but is.");
$this->assertNotContains($adminStdGroupTitle, $groupInTitles, "Group '$adminStdGroupTitle' should not be in listed groups, but is.");
$this->assertStringContainsString($publicSmartGroupTitle, $groupInTitles, "Group '$publicSmartGroupTitle' should be in listed groups, but is not.");
$this->assertStringContainsString($publicStdGroupTitle, $groupInTitles, "Group '$publicStdGroupTitle' should be in listed groups, but is not.");
$this->assertStringNotContainsString($adminSmartGroupTitle, $groupInTitles, "Group '$adminSmartGroupTitle' should not be in listed groups, but is.");
$this->assertStringNotContainsString($adminStdGroupTitle, $groupInTitles, "Group '$adminStdGroupTitle' should not be in listed groups, but is.");
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Contact/SelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testSelectorQuery($dataSet) {
$this->assertLike($this->strWrangle($queryString), $this->strWrangle($sql[$index]));
}
if (!empty($dataSet['where_contains'])) {
$this->assertContains($this->strWrangle(str_replace('@tagid', $tag['id'], $dataSet['where_contains'])), $this->strWrangle($sql[2]));
$this->assertStringContainsString($this->strWrangle(str_replace('@tagid', $tag['id'], $dataSet['where_contains'])), $this->strWrangle($sql[2]));
}
// Ensure that search builder return individual contact as per criteria
if ($dataSet['context'] === 'builder') {
Expand Down Expand Up @@ -175,7 +175,7 @@ public function testSearchByProfile() {
//Check if email column contains (On Hold) string.
foreach ($rows[$contactID] as $key => $value) {
if (strpos($key, 'email') !== FALSE) {
$this->assertContains("(On Hold)", (string) $value);
$this->assertStringContainsString("(On Hold)", (string) $value);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testCreate() {
$contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);

$this->assertNotNull($contributionpage->id);
$this->assertType('int', $contributionpage->id);
$this->assertIsInt($contributionpage->id);
$this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
}

Expand Down
20 changes: 10 additions & 10 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ public function testAnnualQueryWithFinancialACLsEnabled() {
$this->createLoggedInUserWithFinancialACL();
$permittedFinancialType = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation');
$sql = CRM_Contribute_BAO_Contribution::getAnnualQuery([1, 2, 3]);
$this->assertContains('SUM(total_amount) as amount,', $sql);
$this->assertContains('WHERE b.contact_id IN (1,2,3)', $sql);
$this->assertContains('b.financial_type_id IN (' . $permittedFinancialType . ')', $sql);
$this->assertStringContainsString('SUM(total_amount) as amount,', $sql);
$this->assertStringContainsString('WHERE b.contact_id IN (1,2,3)', $sql);
$this->assertStringContainsString('b.financial_type_id IN (' . $permittedFinancialType . ')', $sql);

// Run it to make sure it's not bad sql.
CRM_Core_DAO::executeQuery($sql);
Expand Down Expand Up @@ -337,9 +337,9 @@ public function testAnnualWithMultipleLineItems() {
*/
public function testAnnualQueryWithFinancialACLsDisabled() {
$sql = CRM_Contribute_BAO_Contribution::getAnnualQuery([1, 2, 3]);
$this->assertContains('SUM(total_amount) as amount,', $sql);
$this->assertContains('WHERE b.contact_id IN (1,2,3)', $sql);
$this->assertNotContains('b.financial_type_id', $sql);
$this->assertStringContainsString('SUM(total_amount) as amount,', $sql);
$this->assertStringContainsString('WHERE b.contact_id IN (1,2,3)', $sql);
$this->assertStringNotContainsString('b.financial_type_id', $sql);
//$this->assertNotContains('line_item', $sql);
// Run it to make sure it's not bad sql.
CRM_Core_DAO::executeQuery($sql);
Expand All @@ -351,10 +351,10 @@ public function testAnnualQueryWithFinancialACLsDisabled() {
public function testAnnualQueryWithFinancialHook() {
$this->hookClass->setHook('civicrm_selectWhereClause', [$this, 'aclIdNoZero']);
$sql = CRM_Contribute_BAO_Contribution::getAnnualQuery([1, 2, 3]);
$this->assertContains('SUM(total_amount) as amount,', $sql);
$this->assertContains('WHERE b.contact_id IN (1,2,3)', $sql);
$this->assertContains('b.id NOT IN (0)', $sql);
$this->assertNotContains('b.financial_type_id', $sql);
$this->assertStringContainsString('SUM(total_amount) as amount,', $sql);
$this->assertStringContainsString('WHERE b.contact_id IN (1,2,3)', $sql);
$this->assertStringContainsString('b.id NOT IN (0)', $sql);
$this->assertStringNotContainsString('b.financial_type_id', $sql);
CRM_Core_DAO::executeQuery($sql);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contribute/BAO/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testSearchPseudoReturnProperties($sort, $isUseKeySort) {
$queryObj = new CRM_Contact_BAO_Query($params);
$sql = $queryObj->getSearchSQL(0, 0, $sort . ' asc');
if ($isUseKeySort) {
$this->assertContains('field(', $sql);
$this->assertStringContainsString('field(', $sql);
}
try {
$resultDAO = CRM_Core_DAO::executeQuery($sql);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Contribute/Form/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ public function testContributionBasePreProcess() {
$form->preProcess();
}
catch (CRM_Core_Exception $e) {
$this->assertContains("A payment processor configured for this page might be disabled (contact the site administrator for assistance).", $e->getMessage());
$this->assertStringContainsString("A payment processor configured for this page might be disabled (contact the site administrator for assistance).", $e->getMessage());
return;
}
$this->fail('Exception was expected');
Expand Down Expand Up @@ -1776,7 +1776,7 @@ public function testOpeningWidgetAdminPage() {

// The page contents load later by ajax, so there's just the surrounding
// html available now, but we can check at least one thing while we're here.
$this->assertContains("mainTabContainer", $contents);
$this->assertStringContainsString("mainTabContainer", $contents);
}

/**
Expand Down
Loading

0 comments on commit 73b3529

Please sign in to comment.