From 5a5b00f73520d77e5aea35b1b01b67a46aed4494 Mon Sep 17 00:00:00 2001 From: peptiderepo Date: Thu, 23 Apr 2026 02:53:58 +0000 Subject: [PATCH] fix(tests): add wp_salt + wp_generate_uuid4 stubs + PublisherTest fixture Adds missing wp_salt() and wp_generate_uuid4() stubs to BaseTestCase::setUp() so tests that call PRAutoBlogger_Encryption (for API key decryption) don't fail. Fixes PublisherTest::test_publish_links_generation_logs_by_run_id() which was capturing the wrong database query (SELECT from SourceCollector) due to test fixture including source_ids. Now creates a fixture override without source_ids to isolate the run_id linking assertion. Related: Failures #1 and #2 from PR #109. --- tests/unit/BaseTestCase.php | 8 ++++++++ tests/unit/Core/PublisherTest.php | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/unit/BaseTestCase.php b/tests/unit/BaseTestCase.php index 07bcbcc..bef09ff 100644 --- a/tests/unit/BaseTestCase.php +++ b/tests/unit/BaseTestCase.php @@ -42,6 +42,14 @@ abstract class BaseTestCase extends TestCase { // Stub returns false to simulate when PR Core is not installed. Functions\when( 'post_type_exists' )->justReturn( false ); + // wp_salt is used by PRAutoBlogger_Encryption to derive encryption keys. + // Used when decrypting stored API keys. Stub returns a deterministic value. + Functions\when( 'wp_salt' )->justReturn( 'test-salt-deterministic-value' ); + + // wp_generate_uuid4 is used by CostTracker, ImageSideloader, and Runware provider. + // Stub returns a deterministic UUID so tests are reproducible. + Functions\when( 'wp_generate_uuid4' )->justReturn( '00000000-0000-0000-0000-000000000000' ); + // current_time is called by Logger on every log write. Stub returns a // deterministic timestamp so tests are reproducible. Functions\when( 'current_time' )->alias( static function ( $type = 'mysql', $gmt = 0 ) { diff --git a/tests/unit/Core/PublisherTest.php b/tests/unit/Core/PublisherTest.php index 96d2723..e598da3 100644 --- a/tests/unit/Core/PublisherTest.php +++ b/tests/unit/Core/PublisherTest.php @@ -228,6 +228,12 @@ class PublisherTest extends BaseTestCase { public function test_publish_links_generation_logs_by_run_id(): void { Functions\when( 'wp_insert_post' )->justReturn( 48 ); + // Create an idea fixture without source_ids to avoid triggering SourceCollector + // queries that would overwrite captured_query in the mock. + $fixture = $this->get_article_idea_fixture(); + $fixture['source_ids'] = []; + $idea = new \PRAutoBlogger_Article_Idea( $fixture ); + $captured_query = null; $wpdb = $this->create_mock_wpdb(); $wpdb->method( 'prepare' )->willReturnCallback( function ( $sql, ...$args ) use ( &$captured_query ) { @@ -238,7 +244,7 @@ class PublisherTest extends BaseTestCase { $GLOBALS['wpdb'] = $wpdb; $publisher = new \PRAutoBlogger_Publisher(); - $publisher->publish( '

Content

', $this->idea, $this->review, 'run_link_test' ); + $publisher->publish( '

Content

', $idea, $this->review, 'run_link_test' ); // Should use run_id-based query, not timestamp-based. $this->assertStringContainsString( 'run_id', $captured_query );