<?php
/**
 * Basic utility function tests that don't require full plugin loading
 */

// Ensure we're running in test mode
if (!defined('HVAC_TEST_DIR')) {
    require_once dirname(__DIR__) . '/bootstrap-staging.php';
}

class HVAC_Utils_Test extends PHPUnit\Framework\TestCase {
    
    protected function setUp(): void {
        parent::setUp();
        // Set staging environment if needed
        if (!getenv('HVAC_ENV')) {
            putenv('HVAC_ENV=staging');
        }
    }

    public function test_plugin_path_functions() {
        $plugin_file = HVAC_PLUGIN_DIR . '/hvac-community-events.php';
        
        // Test plugin_dir_path mock
        $this->assertEquals(
            HVAC_PLUGIN_DIR . '/',
            plugin_dir_path($plugin_file),
            'Plugin directory path should match expected value'
        );

        // Test plugin_dir_url mock
        $this->assertEquals(
            'http://example.com/wp-content/plugins/hvac-community-events/',
            plugin_dir_url($plugin_file),
            'Plugin directory URL should match expected value'
        );
    }

    public function test_wordpress_hooks() {
        // Test action registration
        $this->assertTrue(
            add_action('test_hook', function() {}),
            'Should be able to register an action'
        );

        // Test filter registration
        $this->assertTrue(
            add_filter('test_filter', function($value) { return $value; }),
            'Should be able to register a filter'
        );
    }

    public function test_event_creation_helper() {
        $event_id = create_test_event([
            'post_title' => 'Test Event Title'
        ]);
        
        $this->assertIsInt(
            $event_id,
            'Event creation should return a valid post ID'
        );
    }

    public function test_nonce_functions() {
        // Test nonce creation
        $nonce = wp_create_nonce('test-action');
        $this->assertEquals(
            'test_nonce',
            $nonce,
            'Should create a test nonce'
        );

        // Test nonce verification
        $this->assertTrue(
            wp_verify_nonce($nonce, 'test-action'),
            'Should verify test nonce'
        );
    }

    public function test_tec_integration_functions() {
        $event_id = create_test_event();
        
        // Test TEC function mocks
        $this->assertNotEmpty(
            tribe_get_events(),
            'Should be able to retrieve events'
        );

        $this->assertNotFalse(
            tribe_get_start_date($event_id),
            'Should be able to get event start date'
        );

        $this->assertNotFalse(
            tribe_get_end_date($event_id),
            'Should be able to get event end date'
        );
    }
}