Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stripe/controllers/FrmTransLiteActionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public static function trigger_payment_status_change( $atts ) {
$atts = array(
'trigger' => $atts['status'],
'entry_id' => $entry_id,
'payment' => $atts['payment'] ?? null,
);

if ( ! isset( $atts['payment'] ) ) {
Expand Down
88 changes: 88 additions & 0 deletions tests/phpunit/stripe/test_FrmTransLiteActionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,94 @@ public function test_maybe_use_decimal() {
$this->assertSame( '111.500', $amount );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @covers FrmTransLiteActionsController::trigger_payment_status_change
*/
public function test_trigger_payment_status_change_keeps_passed_payment() {
$entry = $this->create_entry_with_payments( array( 'complete', 'pending' ) );
$older_id = $entry['payment_ids'][0];
$older = ( new FrmTransLitePayment() )->get_one( $older_id );

$atts = $this->trigger_payment_status_change(
array(
'status' => 'refunded',
'payment' => $older,
)
);

$this->assertNotNull( $atts );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertNotNull()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertEquals( $older_id, $atts['payment']->id );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertEquals()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertEquals( $entry['id'], $atts['entry_id'] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertEquals()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @covers FrmTransLiteActionsController::trigger_payment_status_change
*/
public function test_trigger_payment_status_change_loads_payment_for_entry() {
$entry = $this->create_entry_with_payments( array( 'complete' ) );

$atts = $this->trigger_payment_status_change(
array(
'status' => 'refunded',
'entry' => (object) array( 'id' => $entry['id'] ),
)
);

$this->assertNotNull( $atts );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertNotNull()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertEquals( $entry['payment_ids'][0], $atts['payment']->id );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertEquals()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @param array $atts
*
* @return array|null The atts passed to the frm_payment_status_refunded hook.
*/
private function trigger_payment_status_change( $atts ) {
$received = null;
$callback = function ( $hook_atts ) use ( &$received ) {
$received = $hook_atts;
};

add_action( 'frm_payment_status_refunded', $callback );
FrmTransLiteActionsController::trigger_payment_status_change( $atts );
remove_action( 'frm_payment_status_refunded', $callback );

return $received;
}

/**
* @param string[] $statuses One payment is created per status, oldest first.
*
* @return array{id: int, payment_ids: int[]}
*/
private function create_entry_with_payments( $statuses ) {
( new FrmTransLiteDb() )->upgrade();

$form = $this->factory->form->create_and_get();
$entry = $this->factory->entry->create_and_get( $this->factory->field->generate_entry_array( $form ) );
$frm_payment = new FrmTransLitePayment();
$payment_ids = array();

foreach ( $statuses as $index => $status ) {
$payment_ids[] = $frm_payment->create(
array(
'item_id' => $entry->id,
'action_id' => 1,
'amount' => '10.00',
'paysys' => 'stripe',
'receipt_id' => 'pi_test_' . $index,
'status' => $status,
'created_at' => gmdate( 'Y-m-d H:i:s', strtotime( '+' . $index . ' day' ) ),
)
);
}

return array(
'id' => $entry->id,
'payment_ids' => $payment_ids,
);
}

/**
* @param string $amount
* @param array $currency
Expand Down
Loading