Skip to content

Commit 82f7279

Browse files
committed
Add unit test for tested up to update
1 parent facea99 commit 82f7279

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,64 @@ public function test_run_with_errors_upgrade_notice() {
433433
$this->assertArrayHasKey( 'code', $warnings['readme.txt'][0][0][1] );
434434
$this->assertEquals( 'upgrade_notice_limit', $warnings['readme.txt'][0][0][1]['code'] );
435435
}
436+
437+
public function test_run_with_errors_tested_up_to_latest_plus_two_version() {
438+
$version = '5.9'; // Target plugin has "6.1" is readme.
439+
440+
set_transient( 'wp_plugin_check_latest_wp_version', $version );
441+
442+
$readme_check = new Plugin_Readme_Check();
443+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-md-with-errors/load.php' );
444+
$check_result = new Check_Result( $check_context );
445+
446+
$readme_check->run( $check_result );
447+
448+
$errors = $check_result->get_errors();
449+
450+
$this->assertNotEmpty( $errors );
451+
452+
$filtered_items = wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) );
453+
454+
$this->assertCount( 1, $filtered_items );
455+
$this->assertStringContainsString( 'Tested up to: 6.1', $filtered_items[0]['message'] );
456+
$this->assertStringContainsString( 'This version of WordPress does not exist (yet).', $filtered_items[0]['message'] );
457+
458+
delete_transient( 'wp_plugin_check_latest_wp_version' );
459+
}
460+
461+
public function test_run_with_errors_tested_up_to_latest_plus_one_version() {
462+
$version = '6.0'; // Target plugin has "6.1" is readme.
463+
464+
set_transient( 'wp_plugin_check_latest_wp_version', $version );
465+
466+
$readme_check = new Plugin_Readme_Check();
467+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-md-with-errors/load.php' );
468+
$check_result = new Check_Result( $check_context );
469+
470+
$readme_check->run( $check_result );
471+
472+
$errors = $check_result->get_errors();
473+
474+
$this->assertCount( 0, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) );
475+
476+
delete_transient( 'wp_plugin_check_latest_wp_version' );
477+
}
478+
479+
public function test_run_with_errors_tested_up_to_latest_stable_version() {
480+
$version = '6.1'; // Target plugin has "6.1" is readme.
481+
482+
set_transient( 'wp_plugin_check_latest_wp_version', $version );
483+
484+
$readme_check = new Plugin_Readme_Check();
485+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-md-with-errors/load.php' );
486+
$check_result = new Check_Result( $check_context );
487+
488+
$readme_check->run( $check_result );
489+
490+
$errors = $check_result->get_errors();
491+
492+
$this->assertCount( 0, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) );
493+
494+
delete_transient( 'wp_plugin_check_latest_wp_version' );
495+
}
436496
}

0 commit comments

Comments
 (0)