From 7510fc9fb6bf2821e8a098b389495542f44a8821 Mon Sep 17 00:00:00 2001 From: Andrew Shell Date: Sat, 28 Mar 2026 10:53:00 -0500 Subject: [PATCH] Added some initial tests to verify configuration --- .github/workflows/testing.yml | 7 +++-- .phpunit.result.cache | 1 - package.json | 2 +- tests/test-data-storage.php | 52 +++++++++++++++++++++++++++++++++++ tests/test-rsscloud.php | 35 +++++++++++++++++++++++ 5 files changed, 93 insertions(+), 4 deletions(-) delete mode 100644 .phpunit.result.cache create mode 100644 tests/test-data-storage.php create mode 100644 tests/test-rsscloud.php diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index e75d91b..53ce5e6 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['8.2', '8.0', '7.4'] + php-version: ["8.2", "8.0", "7.4"] services: database: image: mysql:latest @@ -25,10 +25,13 @@ jobs: - name: Check out source code uses: actions/checkout@v4 + - name: Install SVN + run: sudo apt-get update && sudo apt-get install -y subversion + - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: $ + php-version: ${{ matrix.php-version }} tools: phpunit-polyfills:1.1 - name: Setup tests diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index fe82402..0000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":[],"times":{"SampleTest::test_sample":0.003}} \ No newline at end of file diff --git a/package.json b/package.json index c40c9b7..6bdfd70 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "test:php": "npm-run-all lint:php test:unit:php", "test:unit:php:setup": "wp-env --config .wp-env.test.json start", "test:unit:php:setup:debug": "wp-env --config .wp-env.test.json start --xdebug", - "test:unit:php:base": "wp-env --config .wp-env.test.json run --env-cwd='wp-content/plugins/rsscloud' wordpress vendor/bin/phpunit -c phpunit.xml.dist --verbose", + "test:unit:php:base": "wp-env --config .wp-env.test.json run --env-cwd='wp-content/plugins/rsscloud' wordpress vendor/bin/phpunit -c phpunit.xml.dist --verbose --testdox", "test:unit:php": "npm-run-all test:unit:php:setup test:unit:php:base", "test:unit:php:debug": "npm-run-all test:unit:php:setup:debug test:unit:php:base" } diff --git a/tests/test-data-storage.php b/tests/test-data-storage.php new file mode 100644 index 0000000..2288ad0 --- /dev/null +++ b/tests/test-data-storage.php @@ -0,0 +1,52 @@ +assertFalse( rsscloud_get_hub_notifications() ); + } + + public function test_update_hub_notifications_stores_data() { + $data = array( + 'http://example.com/feed' => array( + 'http://example.com/rpc' => array( + 'protocol' => 'http-post', + 'status' => 'active', + 'failure_count' => 0, + ), + ), + ); + + $this->assertTrue( rsscloud_update_hub_notifications( $data ) ); + $this->assertSame( $data, rsscloud_get_hub_notifications() ); + } + + public function test_update_hub_notifications_casts_to_array() { + rsscloud_update_hub_notifications( 'not-an-array' ); + $this->assertSame( array( 'not-an-array' ), rsscloud_get_hub_notifications() ); + } + + public function test_update_hub_notifications_overwrites_previous() { + $first = array( 'first' => 'value' ); + $second = array( 'second' => 'value' ); + + rsscloud_update_hub_notifications( $first ); + rsscloud_update_hub_notifications( $second ); + + $this->assertSame( $second, rsscloud_get_hub_notifications() ); + } + + /** + * This test must run after tests that write data. + * It verifies that WP_UnitTestCase database isolation is working + * (each test gets a clean slate via transaction rollback). + */ + public function test_database_isolation_between_tests() { + $this->assertFalse( rsscloud_get_hub_notifications() ); + } +} diff --git a/tests/test-rsscloud.php b/tests/test-rsscloud.php new file mode 100644 index 0000000..91af374 --- /dev/null +++ b/tests/test-rsscloud.php @@ -0,0 +1,35 @@ +assertIsString( $challenge ); + $this->assertSame( 30, strlen( $challenge ) ); + } + + public function test_generate_challenge_respects_custom_length() { + $this->assertSame( 50, strlen( rsscloud_generate_challenge( 50 ) ) ); + } + + public function test_generate_challenge_returns_unique_values() { + $first = rsscloud_generate_challenge(); + $second = rsscloud_generate_challenge(); + + $this->assertNotSame( $first, $second ); + } + + public function test_query_vars_adds_rsscloud() { + $vars = array( 'existing_var' ); + $result = rsscloud_query_vars( $vars ); + + $this->assertContains( 'existing_var', $result ); + $this->assertContains( 'rsscloud', $result ); + } +}