upskill-event-manager/wordpress-dev/tests/basic/test-utils.php
bengizmo d6211ee364 feat(testing): Implement HVAC_Test_User_Factory and update .gitignore
- Add HVAC_Test_User_Factory class with:
  * User creation with specific roles
  * Multiple role support
  * Persona management system
  * Account cleanup integration
- Create comprehensive test suite in HVAC_Test_User_Factory_Test.php
- Update testing improvement plan documentation
- Add implementation decisions to project memory bank
- Restructure .gitignore with:
  * Whitelist approach for better file management
  * Explicit backup exclusions
  * Specific bin directory inclusions

Part of the Account Management component from the testing framework improvement plan.
2025-04-14 17:41:36 -03:00

99 lines
No EOL
2.7 KiB
PHP

<?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'
);
}
}