Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/tests/plugins/HyphensInUrlsPluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

#[\PHPUnit\Framework\Attributes\Group('plugins')]
class HyphensInUrlsPluginTest extends PHPUnit\Framework\TestCase {

protected function setUp(): void {
parent::setUp();
require_once dirname( dirname( dirname( __DIR__ ) ) ) . '/user/plugins/hyphens-in-urls/plugin.php';
}
Comment on lines +6 to +9

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

Loading the plugin file via require_once registers the ozh_hyphen_in_charset filter globally. Since PHPUnit runs tests in the same process, this filter will persist and affect subsequent tests, leading to potential test pollution and unexpected failures in other test suites.

To ensure proper test isolation, we should clean up and remove the registered filter in the tearDown() method.

    protected function setUp(): void {
        parent::setUp();
        require_once dirname( dirname( dirname( __DIR__ ) ) ) . '/user/plugins/hyphens-in-urls/plugin.php';
    }

    protected function tearDown(): void {
        yourls_remove_filter( 'get_shorturl_charset', 'ozh_hyphen_in_charset' );
        parent::tearDown();
    }


public function test_ozh_hyphen_in_charset() {
$this->assertTrue( function_exists( 'ozh_hyphen_in_charset' ) );

$this->assertSame( '-', ozh_hyphen_in_charset( '' ) );
$this->assertSame( 'abc-', ozh_hyphen_in_charset( 'abc' ) );
$this->assertSame( '0123456789-', ozh_hyphen_in_charset( '0123456789' ) );
}
}
Loading