Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion .phpunit.result.cache

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
52 changes: 52 additions & 0 deletions tests/test-data-storage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Tests for data storage functions.
*
* @package Rsscloud
*/

class DataStorageTest extends WP_UnitTestCase {

public function test_get_hub_notifications_returns_false_when_not_set() {
$this->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() );
}
}
35 changes: 35 additions & 0 deletions tests/test-rsscloud.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Tests for main plugin functions.
*
* @package Rsscloud
*/

class RsscloudTest extends WP_UnitTestCase {

public function test_generate_challenge_returns_string_of_expected_length() {
$challenge = rsscloud_generate_challenge();

$this->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 );
}
}
Loading