diff --git a/phpunit-bootstrap.php b/phpunit-bootstrap.php
index cfb0be1553..fcc1143267 100644
--- a/phpunit-bootstrap.php
+++ b/phpunit-bootstrap.php
@@ -12,7 +12,8 @@
const SITE_ID_CURRENT_SITE = WORDCAMP_NETWORK_ID;
define( 'WP_PLUGIN_DIR', __DIR__ . '/public_html/wp-content/plugins' );
-define( 'SUT_WPMU_PLUGIN_DIR', __DIR__ . '/public_html/wp-content/mu-plugins' ); // WPMU_PLUGIN_DIR will be in `WP_TESTS_DIR`.
+define( 'SUT_WP_CONTENT_DIR', __DIR__ . '/public_html/wp-content/' ); // WP_CONTENT_DIR will be in `WP_TESTS_DIR`.
+define( 'SUT_WPMU_PLUGIN_DIR', SUT_WP_CONTENT_DIR . '/mu-plugins' ); // WPMU_PLUGIN_DIR will be in `WP_TESTS_DIR`.
$core_tests_directory = getenv( 'WP_TESTS_DIR' );
@@ -46,6 +47,7 @@
require_once WP_PLUGIN_DIR . '/wcpt/tests/bootstrap.php';
require_once( WP_PLUGIN_DIR . '/wordcamp-remote-css/tests/bootstrap.php' );
require_once WP_PLUGIN_DIR . '/wordcamp-speaker-feedback/tests/bootstrap.php';
+require_once WP_PLUGIN_DIR . '/wordcamp-payments-network/tests/bootstrap.php';
require_once SUT_WPMU_PLUGIN_DIR . '/tests/bootstrap.php';
/*
diff --git a/phpunit-watcher.yml.dist b/phpunit-watcher.yml.dist
index e8e38f3a3d..72410dfecb 100644
--- a/phpunit-watcher.yml.dist
+++ b/phpunit-watcher.yml.dist
@@ -3,6 +3,7 @@ watch:
- ./public_html/wp-content/mu-plugins/
- ./public_html/wp-content/plugins/camptix/
- ./public_html/wp-content/plugins/wordcamp-organizer-reminders/
+ - ./public_html/wp-content/plugins/wordcamp-payments-network/
- ./public_html/wp-content/plugins/wc-post-types/
- ./public_html/wp-content/plugins/wcpt/
- ./public_html/wp-content/plugins/wordcamp-remote-css/
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 18cfc73fce..bdd212d86f 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -32,6 +32,12 @@
+
+
+ ./public_html/wp-content/plugins/wordcamp-payments-network/tests/
+
+
+
./public_html/wp-content/plugins/wc-post-types/tests/
@@ -64,6 +70,8 @@
./public_html/wp-content/plugins/wc-post-types
./public_html/wp-content/plugins/wcpt
./public_html/wp-content/plugins/wordcamp-organizer-reminders
+ ./public_html/wp-content/plugins/wordcamp-payments/
+ ./public_html/wp-content/plugins/wordcamp-payments-network/
./public_html/wp-content/plugins/wordcamp-remote-css
./public_html/wp-content/plugins/wordcamp-speaker-feedback
./public_html/wp-content/sunrise.php
diff --git a/public_html/wp-content/plugins/wordcamp-payments-network/includes/wordcamp-budgets-dashboard.php b/public_html/wp-content/plugins/wordcamp-payments-network/includes/wordcamp-budgets-dashboard.php
index 9099d9e0ea..5d320ffc49 100644
--- a/public_html/wp-content/plugins/wordcamp-payments-network/includes/wordcamp-budgets-dashboard.php
+++ b/public_html/wp-content/plugins/wordcamp-payments-network/includes/wordcamp-budgets-dashboard.php
@@ -9,6 +9,7 @@
use WordCamp\Budgets_Dashboard\Reimbursement_Requests as Reimbursements_Dashboard;
use DateTimeInterface;
use WP_CLI;
+use WP_Error;
defined( 'WPINC' ) || die();
@@ -468,7 +469,7 @@ function process_export_request() {
}
}
-/*
+/**
* Generate and return the raw payment report contents
*
* @param array $args
diff --git a/public_html/wp-content/plugins/wordcamp-payments-network/tests/bootstrap.php b/public_html/wp-content/plugins/wordcamp-payments-network/tests/bootstrap.php
new file mode 100755
index 0000000000..e96e1db432
--- /dev/null
+++ b/public_html/wp-content/plugins/wordcamp-payments-network/tests/bootstrap.php
@@ -0,0 +1,25 @@
+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' => << 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' => << 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;
+ }
+}