Files

36 lines
1.7 KiB
PHP
Raw Permalink Normal View History

<?php
declare( strict_types=1 );
namespace StreamGoals\Tests\Unit;
use PHPUnit\Framework\TestCase;
use StreamGoals\Admin\Input;
use StreamGoals\Core\Settings;
final class DonationNoticeTest extends TestCase {
public function test_default_notice_says_donations_are_non_refundable(): void {
$d = Settings::defaults();
$this->assertArrayHasKey( 'donation_notice', $d );
$this->assertStringContainsString( 'non-refundable', strtolower( (string) $d['donation_notice'] ) );
}
public function test_admin_input_is_plain_text_and_length_capped(): void {
$this->assertSame( 'No refunds, sorry.', Input::text( ' No refunds, sorry. ', 200 ) );
$this->assertStringNotContainsString( '<', Input::text( '<script>alert(1)</script><b>Hi</b>', 200 ), 'no markup survives (and it is rendered as text anyway)' );
$this->assertStringNotContainsString( '<', Input::text( '<b>Bold</b> <i>text</i>', 200 ) );
$this->assertSame( 200, strlen( Input::text( str_repeat( 'a', 500 ), 200 ) ) );
$this->assertSame( '', Input::text( "\x00\x1F", 200 ) );
}
public function test_form_script_renders_the_notice_with_textcontent_only(): void {
$js = (string) file_get_contents( dirname( __DIR__, 2 ) . '/assets/donate/donate.js' );
$this->assertMatchesRegularExpression( '/if \(C\.notice\).*sg-notice.*text: String\(C\.notice\)/s', $js, 'notice must be rendered as text, never HTML' );
$this->assertStringNotContainsString( 'innerHTML', $js );
}
public function test_form_config_passes_the_notice_through(): void {
$php = (string) file_get_contents( dirname( __DIR__, 2 ) . '/includes/Rest/DonateController.php' );
$this->assertStringContainsString( "'notice' => (string) ( \$s['donation_notice'] ?? '' )", $php );
}
}