3, 'currency' => 'USD', 'status' => 'active', 'target_minor' => 10000, 'close_at_target' => 1, 'counts_fees' => 0, 'starts_at' => null, 'ends_at' => null ), $o ); } public function test_below_equal_and_over_target(): void { $this->assertFalse( GoalTargetPolicy::shouldClose( $this->goal(), 9999 ) ); $this->assertTrue( GoalTargetPolicy::shouldClose( $this->goal(), 10000 ) ); $this->assertTrue( GoalTargetPolicy::shouldClose( $this->goal(), 25000 ) ); } public function test_flag_off_or_missing_never_closes(): void { $this->assertFalse( GoalTargetPolicy::shouldClose( $this->goal( array( 'close_at_target' => 0 ) ), 99999 ) ); $g = $this->goal(); unset( $g['close_at_target'] ); $this->assertFalse( GoalTargetPolicy::shouldClose( $g, 99999 ) ); } public function test_only_active_goals_are_closed(): void { $this->assertFalse( GoalTargetPolicy::shouldClose( $this->goal( array( 'status' => 'complete' ) ), 20000 ) ); $this->assertFalse( GoalTargetPolicy::shouldClose( $this->goal( array( 'status' => 'paused' ) ), 20000 ) ); } public function test_target_zero_never_closes(): void { $this->assertFalse( GoalTargetPolicy::shouldClose( $this->goal( array( 'target_minor' => 0 ) ), 0 ) ); $this->assertFalse( GoalTargetPolicy::shouldClose( $this->goal( array( 'target_minor' => 0 ) ), 500 ) ); } public function test_base_vs_total_basis(): void { $this->assertSame( 'base_minor', GoalTargetPolicy::amountColumn( $this->goal() ) ); $this->assertSame( 'total_minor', GoalTargetPolicy::amountColumn( $this->goal( array( 'counts_fees' => 1 ) ) ) ); } public function test_closed_at_target_detection_and_pause_is_not_closed(): void { $this->assertTrue( GoalTargetPolicy::isClosedAtTarget( $this->goal( array( 'status' => 'complete' ) ) ) ); $this->assertFalse( GoalTargetPolicy::isClosedAtTarget( $this->goal( array( 'status' => 'paused' ) ) ) ); $this->assertFalse( GoalTargetPolicy::isClosedAtTarget( $this->goal( array( 'status' => 'complete', 'close_at_target' => 0 ) ) ) ); } public function test_checkbox_parsing(): void { $this->assertSame( 1, GoalTargetPolicy::flagFromPost( '1' ) ); $this->assertSame( 1, GoalTargetPolicy::flagFromPost( 'on' ) ); $this->assertSame( 0, GoalTargetPolicy::flagFromPost( null ) ); $this->assertSame( 0, GoalTargetPolicy::flagFromPost( '' ) ); $this->assertSame( 0, GoalTargetPolicy::flagFromPost( '0' ) ); $this->assertSame( 0, GoalTargetPolicy::flagFromPost( array( '1' ) ) ); } public function test_new_orders_for_a_closed_goal_get_a_friendly_409(): void { try { OrderValidator::validate( array( 'amount' => '5.00' ), $this->goal( array( 'status' => 'complete' ) ), Settings::defaults(), new FeeCalculator( 349, 49 ), 1800000000 ); $this->fail( 'expected refusal' ); } catch ( ValidationException $e ) { $this->assertSame( 'goal_inactive', $e->errorCode ); $this->assertSame( 409, $e->status ); $this->assertStringContainsString( 'Thank you', $e->getMessage() ); } } public function test_paused_goal_keeps_generic_message(): void { try { OrderValidator::quote( array( 'amount' => '5.00' ), $this->goal( array( 'status' => 'paused' ) ), Settings::defaults(), new FeeCalculator( 349, 49 ), 1800000000 ); $this->fail( 'expected refusal' ); } catch ( ValidationException $e ) { $this->assertSame( 'This goal is not accepting donations.', $e->getMessage() ); } } public function test_goal_open_for_active_flagged_goal(): void { $this->assertTrue( OrderValidator::goalIsOpen( $this->goal(), 1800000000 ) ); $this->assertFalse( OrderValidator::goalIsOpen( $this->goal( array( 'status' => 'complete' ) ), 1800000000 ) ); } }