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.
This commit is contained in:
@@ -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 ) {
|
||||
|
||||
@@ -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( '<p>Content</p>', $this->idea, $this->review, 'run_link_test' );
|
||||
$publisher->publish( '<p>Content</p>', $idea, $this->review, 'run_link_test' );
|
||||
|
||||
// Should use run_id-based query, not timestamp-based.
|
||||
$this->assertStringContainsString( 'run_id', $captured_query );
|
||||
|
||||
Reference in New Issue
Block a user