Skip to content

🧪 [testing improvement] Add tests for sample-page plugin functions#227

Merged
projectedanx merged 1 commit into
masterfrom
jules-1264757939922729620-83610f99
Jun 6, 2026
Merged

🧪 [testing improvement] Add tests for sample-page plugin functions#227
projectedanx merged 1 commit into
masterfrom
jules-1264757939922729620-83610f99

Conversation

@projectedanx

Copy link
Copy Markdown
Owner

💡 What: 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

🎯 Why: To improve the reliability and test coverage of the sample plugin provided with the codebase, which previously had 0% coverage.

📊 Coverage: The new SamplePagePluginTest class in tests/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

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>
@google-labs-jules

Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines +14 to +17
protected function tearDown(): void {
yourls_get_db()->set_plugin_pages(array());
parent::tearDown();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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();
    }

Comment on lines +47 to +54
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);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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);
    }

@projectedanx
projectedanx merged commit 2243ba5 into master Jun 6, 2026
15 of 16 checks passed
@projectedanx
projectedanx deleted the jules-1264757939922729620-83610f99 branch June 6, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant