Skip to content

Commit

Permalink
[NFC] Minor test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Mar 20, 2021
1 parent ffde748 commit bf4918a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 46 deletions.
18 changes: 11 additions & 7 deletions tests/phpunit/CRM/Activity/Form/ActivityViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/
class CRM_Activity_Form_ActivityViewTest extends CiviUnitTestCase {

public function setUp() {
parent::setUp();
}

public function tearDown() {
/**
* Cleanup after class.
*
* @throws \CRM_Core_Exception
*/
public function tearDown(): void {
$tablesToTruncate = [
'civicrm_activity',
'civicrm_activity_contact',
Expand All @@ -20,8 +21,11 @@ public function tearDown() {
/**
* Test that the smarty template for ActivityView contains what we expect
* after preProcess().
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testActivityViewPreProcess() {
public function testActivityViewPreProcess(): void {
// create activity
$activity = $this->activityCreate();

Expand All @@ -38,7 +42,7 @@ public function testActivityViewPreProcess() {

// check one of the smarty template vars
// not checking EVERYTHING
$templateVar = $activityViewForm->getTemplate()->get_template_vars('values');
$templateVar = CRM_Activity_Form_ActivityView::getTemplate()->get_template_vars('values');
$expected = [
'assignee_contact' => [0 => $activity['target_contact_id']],
// it's always Julia
Expand Down
57 changes: 32 additions & 25 deletions tests/phpunit/CRM/Activity/Form/Task/PDFLetterCommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@
*/
class CRM_Activity_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase {

public function setUp() {
$this->useTransaction(TRUE);
/**
* Set up for tests.
*/
public function setUp(): void {
$this->useTransaction();
parent::setUp();
}

public function tearDown() {
parent::tearDown();
}

/**
* Test create a document with basic tokens.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testCreateDocumentBasicTokens() {
public function testCreateDocumentBasicTokens(): void {
$activity = $this->activityCreate();
$data = [
['Subject: {activity.subject}', 'Subject: Discussion on warm beer'],
['Date: {activity.activity_date_time}', 'Date: ' . \CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM'],
['Date: {activity.activity_date_time}', 'Date: ' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM'],
['Duration: {activity.duration}', 'Duration: 90'],
['Location: {activity.location}', 'Location: Baker Street'],
['Details: {activity.details}', 'Details: Lets schedule a meeting'],
Expand Down Expand Up @@ -61,29 +60,33 @@ public function testCreateDocumentCustomFieldTokens() {
$activityIds = CRM_Utils_Array::collect('id', $activities);
$output = CRM_Activity_Form_Task_PDFLetterCommon::createDocument($activityIds, $html_message, ['is_unit_test' => TRUE]);
// Should have one row of output per activity
$this->assertEquals(count($activities), count($output));
$this->assertCount(count($activities), $output);

// Check each line has the correct substitution
foreach ($output as $key => $line) {
$this->assertEquals($line, "Custom: " . $cg['custom_field_group_options'][$activities[$key]['option']]);
$this->assertEquals($line, 'Custom: ' . $cg['custom_field_group_options'][$activities[$key]['option']]);
}
}

public function testCreateDocumentSpecialTokens() {
/**
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testCreateDocumentSpecialTokens(): void {
$this->markTestIncomplete('special tokens not yet merged - see https://github.com/civicrm/civicrm-core/pull/12012');
$activity = $this->activityCreate();
$data = [
["Source First Name: {activity.source_first_name}", "Source First Name: Anthony"],
["Target N First Name: {activity.target_N_first_name}", "Target N First Name: Julia"],
["Target 0 First Name: {activity.target_0_first_name}", "Target 0 First Name: Julia"],
["Target 1 First Name: {activity.target_1_first_name}", "Target 1 First Name: Julia"],
["Target 2 First Name: {activity.target_2_first_name}", "Target 2 First Name: "],
["Assignee N First Name: {activity.target_N_first_name}", "Assignee N First Name: Julia"],
["Assignee 0 First Name: {activity.target_0_first_name}", "Assignee 0 First Name: Julia"],
["Assignee 1 First Name: {activity.target_1_first_name}", "Assignee 1 First Name: Julia"],
["Assignee 2 First Name: {activity.target_2_first_name}", "Assignee 2 First Name: "],
["Assignee Count: {activity.assignees_count}", "Assignee Count: 1"],
["Target Count: {activity.targets_count}", "Target Count: 1"],
['Source First Name: {activity.source_first_name}', "Source First Name: Anthony"],
['Target N First Name: {activity.target_N_first_name}', "Target N First Name: Julia"],
['Target 0 First Name: {activity.target_0_first_name}', "Target 0 First Name: Julia"],
['Target 1 First Name: {activity.target_1_first_name}', "Target 1 First Name: Julia"],
['Target 2 First Name: {activity.target_2_first_name}', "Target 2 First Name: "],
['Assignee N First Name: {activity.target_N_first_name}', "Assignee N First Name: Julia"],
['Assignee 0 First Name: {activity.target_0_first_name}', "Assignee 0 First Name: Julia"],
['Assignee 1 First Name: {activity.target_1_first_name}', "Assignee 1 First Name: Julia"],
['Assignee 2 First Name: {activity.target_2_first_name}', "Assignee 2 First Name: "],
['Assignee Count: {activity.assignees_count}', "Assignee Count: 1"],
['Target Count: {activity.targets_count}', "Target Count: 1"],
];
$html_message = "\n" . implode("\n", CRM_Utils_Array::collect('0', $data)) . "\n";
$output = CRM_Activity_Form_Task_PDFLetterCommon::createDocument([$activity['id']], $html_message, ['is_unit_test' => TRUE]);
Expand All @@ -93,12 +96,16 @@ public function testCreateDocumentSpecialTokens() {
}
}

public function testCreateDocumentUnknownTokens() {
/**
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testCreateDocumentUnknownTokens(): void {
$activity = $this->activityCreate();
$html_message = "Unknown token: {activity.something_unknown}";
$html_message = 'Unknown token: {activity.something_unknown}';
$output = CRM_Activity_Form_Task_PDFLetterCommon::createDocument([$activity['id']], $html_message, ['is_unit_test' => TRUE]);
// Unknown tokens should be left alone
$this->assertEquals($output[0], $html_message);
$this->assertEquals($html_message, $output[0]);
}

}
5 changes: 3 additions & 2 deletions tests/phpunit/CRM/Core/ResourcesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CRM_Core_ResourcesTest extends CiviUnitTestCase {
protected $originalRequest;
protected $originalGet;

public function setUp() {
public function setUp(): void {
parent::setUp();

list ($this->basedir, $this->container, $this->mapper) = $this->_createMapper();
Expand All @@ -55,9 +55,10 @@ public function setUp() {
/**
* Restore globals so this test doesn't interfere with others.
*/
public function tearDown() {
public function tearDown(): void {
$_REQUEST = $this->originalRequest;
$_GET = $this->originalGet;
parent::tearDown();
}

public function testCreateBasicBundle() {
Expand Down
16 changes: 4 additions & 12 deletions tests/phpunit/HelloTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ class HelloTest extends PHPUnit\Framework\TestCase {
*/
public $abc;

/**
* @param string|null $name
*/
public function __construct($name = NULL) {
parent::__construct($name);
}

/**
* Called before the test functions will be executed.
* this function is defined in PHPUnit_TestCase and overwritten
Expand All @@ -48,26 +41,25 @@ public function __construct($name = NULL) {
public function setUp() {
// create a new instance of String with the
// string 'abc'
$this->abc = "hello";
$this->abc = 'hello';
}

/**
* Called after the test functions are executed.
* this function is defined in PHPUnit_TestCase and overwritten
* here.
*/
public function tearDown() {
public function tearDown(): void {
// delete your instance
unset($this->abc);
}

/**
* test the toString function.
*/
public function testHello() {
public function testHello(): void {
$result = $this->abc;
$expected = 'hello';
$this->assertEquals($result, $expected);
$this->assertEquals('hello', $result);
}

}

0 comments on commit bf4918a

Please sign in to comment.