From f3388b789c5b30626ee1252d54aaa54478c1fa8e Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 3 May 2021 16:18:06 +1200 Subject: [PATCH] Improve unit test on rendered urls --- tests/phpunit/CRM/Contribute/Page/TabTest.php | 78 ++++++++++++++++--- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/CRM/Contribute/Page/TabTest.php b/tests/phpunit/CRM/Contribute/Page/TabTest.php index 722e6fdc31..f06faf1f5d 100644 --- a/tests/phpunit/CRM/Contribute/Page/TabTest.php +++ b/tests/phpunit/CRM/Contribute/Page/TabTest.php @@ -18,22 +18,77 @@ use Civi\Api4\ContributionRecur; */ class CRM_Contribute_Page_TabTest extends CiviUnitTestCase { + /** + * Clean up after test. + * + * @throws \CRM_Core_Exception + */ + public function tearDown(): void { + $this->quickCleanUpFinancialEntities(); + parent::tearDown(); + } + /** * Test links render correctly for manual processor. * * @throws \API_Exception * @throws \CiviCRM_API3_Exception */ - public function testLinks() { - $contactID = $this->individualCreate(); - $recurID = ContributionRecur::create()->setValues([ + public function testLinksManual(): void { + [$contactID, $recurID] = $this->setupTemplate(); + + $templateVariable = CRM_Core_Smarty::singleton()->get_template_vars(); + $this->assertEquals('Mr. Anthony Anderson II', $templateVariable['displayName']); + $this->assertEquals("ViewEditCancel", + $this->getActionHtml() + ); + } + + /** + * Test links render correctly for manual processor. + * + * @throws \API_Exception + * @throws \CiviCRM_API3_Exception + */ + public function testLinksPaypalStandard(): void { + $this->setupTemplate([ + 'payment_processor_id' => $this->paymentProcessorCreate(['payment_processor_type_id' => 'PayPal_Standard']), + 'contact_id' => $this->createLoggedInUser(), + ]); + $expected = 'ViewEditmore'; + $this->assertEquals($expected, $this->getActionHtml()); + + $page = new CRM_Contribute_Page_UserDashboard(); + $page->run(); + $expected = 'ViewEditmore'; + $this->assertEquals( + $expected, + $this->getActionHtml() + ); + } + + /** + * Set up template for user dashboard. + * + * Create the recurring contribution, contribution and run the dashboard. + * + * @param array $recurParams + * + * @return array + * @throws \API_Exception + * @throws \CiviCRM_API3_Exception + * @throws \Civi\API\Exception\UnauthorizedException + */ + protected function setupTemplate($recurParams = []): array { + $contactID = $recurParams['contact_id'] ?? $this->individualCreate(); + $recurID = ContributionRecur::create()->setValues(array_merge([ 'contact_id' => $contactID, 'amount' => 10, 'frequency_interval' => 'week', 'start_date' => 'now', 'is_active' => TRUE, 'contribution_status_id:name' => 'Pending', - ]) + ], $recurParams)) ->addChain( 'contribution', Contribution::create()->setValues([ @@ -48,12 +103,17 @@ class CRM_Contribute_Page_TabTest extends CiviUnitTestCase { $page->_contactId = $contactID; $page->_action = CRM_Core_Action::VIEW; $page->browse(); + return [$contactID, $recurID]; + } - $templateVariable = CRM_Core_Smarty::singleton()->get_template_vars(); - $this->assertEquals('Mr. Anthony Anderson II', $templateVariable['displayName']); - $this->assertEquals("ViewEditCancel", - $templateVariable['activeRecurRows'][1]['action'] - ); + /** + * Get the html assigned as actions. + * + * @return string + */ + protected function getActionHtml(): string { + return CRM_Core_Smarty::singleton() + ->get_template_vars()['activeRecurRows'][1]['action']; } } -- 2.25.1