🧪 [testing improvement] Add tests for sample-page plugin functions#227
Conversation
Added tests for the previously untested functions in `user/plugins/sample-page/plugin.php`: - `ozh_yourls_samplepage_add_page` - `ozh_yourls_samplepage_update_option` - `ozh_yourls_samplepage_do_page` Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Code Review
This pull request introduces a new PHPUnit test suite SamplePagePluginTest for the Sample Page Plugin, covering page addition, option updates, and page rendering. The review feedback highlights two key issues regarding test isolation: first, the test_option database entry modified during tests should be cleaned up in the tearDown method to prevent database pollution; second, test_do_page is currently order-dependent and should be refactored to explicitly set or delete the option state within the test itself to ensure reliable execution in isolation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| protected function tearDown(): void { | ||
| yourls_get_db()->set_plugin_pages(array()); | ||
| parent::tearDown(); | ||
| } |
There was a problem hiding this comment.
The test_option option is modified in the database during test_update_option() but is never cleaned up. This can pollute the database and affect other tests or subsequent test runs. It is best practice to delete any modified options in the tearDown() method to ensure test isolation.
protected function tearDown(): void {
yourls_get_db()->set_plugin_pages(array());
yourls_delete_option('test_option');
parent::tearDown();
}| public function test_do_page() { | ||
| ob_start(); | ||
| ozh_yourls_samplepage_do_page(); | ||
| $output = ob_get_clean(); | ||
|
|
||
| $this->assertStringContainsString('<h2>Sample Plugin Administration Page</h2>', $output); | ||
| $this->assertStringContainsString('<input type="text" id="test_option" name="test_option" value="0" />', $output); | ||
| } |
There was a problem hiding this comment.
This test is currently order-dependent. If test_do_page() is run in isolation (or before test_update_option()), yourls_get_option('test_option') will return false (since the option is not set in the database), resulting in an empty string value="" in the HTML output instead of value="0". This causes the test to fail.
To ensure test isolation and reliability, we should explicitly set or delete the option within the test, and verify both the default (empty) and set states.
public function test_do_page() {
// Test with option not set
yourls_delete_option('test_option');
ob_start();
ozh_yourls_samplepage_do_page();
$output = ob_get_clean();
$this->assertStringContainsString('<h2>Sample Plugin Administration Page</h2>', $output);
$this->assertStringContainsString('<input type="text" id="test_option" name="test_option" value="" />', $output);
// Test with option set
yourls_update_option('test_option', 42);
ob_start();
ozh_yourls_samplepage_do_page();
$output = ob_get_clean();
$this->assertStringContainsString('<input type="text" id="test_option" name="test_option" value="42" />', $output);
}
💡 What: Added tests for the previously untested functions in
user/plugins/sample-page/plugin.php:ozh_yourls_samplepage_add_pageozh_yourls_samplepage_update_optionozh_yourls_samplepage_do_page🎯 Why: To improve the reliability and test coverage of the sample plugin provided with the codebase, which previously had 0% coverage.
📊 Coverage: The new
SamplePagePluginTestclass intests/tests/plugins/ensures these core functions operate correctly, handle option updates, interact with nonces, and output the correct HTML form elements.✨ Result: Increased test coverage for the Sample Admin Page plugin.
PR created automatically by Jules for task 1264757939922729620 started by @projectedanx