-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Payments Network: Add tests for JPM wires
- Loading branch information
Showing
6 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
public_html/wp-content/plugins/wordcamp-payments-network/tests/bootstrap.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace WordCamp\Budgets_Dashboard\Tests; | ||
|
||
if ( 'cli' !== php_sapi_name() ) { | ||
return; | ||
} | ||
|
||
/** | ||
* Load the plugins that we'll need to be active for the tests. | ||
*/ | ||
function manually_load_plugin() { | ||
// @todo switch to `require_once` once it's accessible in all local environments. | ||
// @link https://github.com/WordPress/wordcamp.org/issues/769 | ||
include_once SUT_WP_CONTENT_DIR . '/mu-plugins-private/wporg-mu-plugins/pub-sync/utilities/class-export-csv.php'; | ||
|
||
require_once WP_PLUGIN_DIR . '/wordcamp-payments/includes/wordcamp-budgets.php'; | ||
require_once WP_PLUGIN_DIR . '/wordcamp-payments/includes/payment-request.php'; | ||
require_once WP_PLUGIN_DIR . '/wordcamp-payments/includes/encryption.php'; | ||
|
||
require_once dirname( __DIR__ ) . '/includes/payment-requests-dashboard.php'; | ||
require_once dirname( __DIR__ ) . '/includes/wordcamp-budgets-dashboard.php'; | ||
} | ||
|
||
tests_add_filter( 'muplugins_loaded', __NAMESPACE__ . '\manually_load_plugin' ); |
161 changes: 161 additions & 0 deletions
161
...ml/wp-content/plugins/wordcamp-payments-network/tests/test-wordcamp-budgets-dashboard.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?php | ||
|
||
namespace WordCamp\Budgets_Dashboard\Tests; | ||
|
||
use Payment_Requests_Dashboard; | ||
use WCP_Encryption; | ||
use WP_UnitTestCase; | ||
use function WordCamp\Budgets_Dashboard\{ generate_payment_report }; | ||
|
||
defined( 'WPINC' ) || die(); | ||
|
||
/** | ||
* Class Test_Budgets_Dashboard | ||
* | ||
* @group budgets-dashboard | ||
*/ | ||
class Test_Budgets_Dashboard extends WP_UnitTestCase { | ||
/** | ||
* Set up shared fixtures for these tests. | ||
* | ||
* @param WP_UnitTest_Factory $factory | ||
*/ | ||
public static function wpSetUpBeforeClass( $factory ) { | ||
define( 'WORDCAMP_PAYMENTS_ENCRYPTION_KEY', 'key' ); | ||
define( 'WORDCAMP_PAYMENTS_HMAC_KEY', 'hmac' ); | ||
|
||
$factory->post->create( array( | ||
'post_type' => 'wcp_payment_request', | ||
'post_status' => 'wcb-approved', | ||
|
||
'meta_input' => array( | ||
'_wcb_updated_timestamp' => strtotime( 'Yesterday 10am' ), | ||
'_camppayments_description' => 'Test Request', | ||
'_camppayments_due_by' => strtotime( 'Next Tuesday' ), | ||
'_camppayments_payment_amount' => '500', | ||
'_camppayments_currency' => 'USD', | ||
'_camppayments_payment_method' => 'Wire', | ||
'_camppayments_invoice_number' => 'Invoice 1234', | ||
'_camppayments_payment_category' => 'audio-visual', | ||
|
||
'_camppayments_bank_name' => WCP_Encryption::encrypt( 'A Bank' ), | ||
'_camppayments_bank_street_address' => WCP_Encryption::encrypt( '1234 Bank St' ), | ||
'_camppayments_bank_city' => WCP_Encryption::encrypt( 'Bankersville' ), | ||
'_camppayments_bank_state' => WCP_Encryption::encrypt( 'New Bankswick' ), | ||
'_camppayments_bank_zip_code' => WCP_Encryption::encrypt( '12345' ), | ||
'_camppayments_bank_country_iso3166' => WCP_Encryption::encrypt( 'US' ), | ||
'_camppayments_bank_bic' => WCP_Encryption::encrypt( '123456' ), | ||
|
||
'_camppayments_beneficiary_name' => WCP_Encryption::encrypt( 'Jane Beneficiary' ), | ||
'_camppayments_beneficiary_street_address' => WCP_Encryption::encrypt( '9876 Beneficiary St' ), | ||
'_camppayments_beneficiary_city' => WCP_Encryption::encrypt( 'Benficiaryville' ), | ||
'_camppayments_beneficiary_state' => WCP_Encryption::encrypt( 'New Bennieswick' ), | ||
'_camppayments_beneficiary_zip_code' => WCP_Encryption::encrypt( '98765' ), | ||
'_camppayments_beneficiary_country_iso3166' => WCP_Encryption::encrypt( 'Test' ), | ||
'_camppayments_beneficiary_account_number' => WCP_Encryption::encrypt( '987654' ), | ||
), | ||
) ); | ||
|
||
Payment_Requests_Dashboard::upgrade(); // Create index table. | ||
Payment_Requests_Dashboard::aggregate(); // Populate index table. | ||
} | ||
|
||
/** | ||
* @covers WordCamp\Budgets_Dashboard\generate_payment_report | ||
* @covers WordCamp\Budgets_Dashboard\_generate_payment_report_jpm_wires | ||
* @covers WCP_Payment_Request::_generate_payment_report_jpm_wires | ||
* | ||
* @dataProvider data_generate_payment_report | ||
*/ | ||
public function test_generate_payment_report( array $args, string $expected ) : void { | ||
if ( ! class_exists( 'WordPressdotorg\MU_Plugins\Utilities\Export_CSV' ) ) { | ||
$this->markTestSkipped( 'Export_CSV class not found.' ); | ||
} | ||
|
||
$actual = generate_payment_report( $args ); | ||
|
||
if ( is_wp_error( $actual ) ) { | ||
$actual = $actual->get_error_message(); | ||
} | ||
|
||
$this->assertSame( $expected, $actual ); | ||
} | ||
|
||
/** | ||
* Test cases for `test_generate_payment_report()`. | ||
*/ | ||
public function data_generate_payment_report() : array { | ||
// This isn't guaranteed to match the value used in `_generate_payment_report_jpm_wires()` due to the time | ||
// between when this case is generated and when the test is ran. It seems to work most of the time though. | ||
$export_date = gmdate( 'YmdHis' ); | ||
|
||
$cases = array( | ||
'vendor payment wire' => array( | ||
'args' => array( | ||
'status' => 'wcb-approved', | ||
'start_date' => strtotime( '3 days ago' ), | ||
'end_date' => time(), | ||
'post_type' => 'wcp_payment_request', | ||
|
||
'export_type' => array( | ||
'label' => 'JP Morgan Access - Wire Payments', | ||
'mime_type' => 'text/csv', | ||
'callback' => 'WordCamp\Budgets_Dashboard\_generate_payment_report_jpm_wires', | ||
'filename' => 'wordcamp-payments-%s-%s-jpm-wires.csv', | ||
), | ||
), | ||
|
||
'expected' => <<<EOD | ||
HEADER,$export_date,1 | ||
P,WIRES,,,N,USD,500.00,,,,,,,ACCT,987654,"Jane Beneficiary","9876 Beneficiary St",,"Benficiaryville New Bennieswick ",,Test,,,SWIFT,123456,"A Bank","1234 Bank St",,"Bankersville New Bankswick 12345",US,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"Invoice 1234",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,OUR,,,wcb-1-4 | ||
TRAILER,1,500 | ||
EOD | ||
, | ||
), | ||
|
||
'no matching posts' => array( | ||
'args' => array( | ||
'status' => 'wcb-approved', | ||
'start_date' => strtotime( '8 days ago' ), | ||
'end_date' => strtotime( '5 days ago' ), | ||
'post_type' => 'wcp_payment_request', | ||
|
||
'export_type' => array( | ||
'label' => 'JP Morgan Access - Wire Payments', | ||
'mime_type' => 'text/csv', | ||
'callback' => 'WordCamp\Budgets_Dashboard\_generate_payment_report_jpm_wires', | ||
'filename' => 'wordcamp-payments-%s-%s-jpm-wires.csv', | ||
), | ||
), | ||
|
||
'expected' => <<<EOD | ||
HEADER,$export_date,1 | ||
TRAILER,0,0 | ||
EOD | ||
, | ||
), | ||
|
||
'Invalid date' => array( | ||
'args' => array( | ||
'status' => 'wcb-approved', | ||
'start_date' => 'invalid date', | ||
'end_date' => strtotime( '5 days ago' ), | ||
'post_type' => 'wcp_payment_request', | ||
|
||
'export_type' => array( | ||
'label' => 'JP Morgan Access - Wire Payments', | ||
'mime_type' => 'text/csv', | ||
'callback' => 'WordCamp\Budgets_Dashboard\_generate_payment_report_jpm_wires', | ||
'filename' => 'wordcamp-payments-%s-%s-jpm-wires.csv', | ||
), | ||
), | ||
|
||
'expected' => 'Invalid start or end date.', | ||
), | ||
); | ||
|
||
return $cases; | ||
} | ||
} |