- 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.
142 lines
No EOL
4.4 KiB
PHP
142 lines
No EOL
4.4 KiB
PHP
<?php
|
|
/**
|
|
* Test HVAC Test Environment
|
|
*
|
|
* @package HVAC_Testing
|
|
*/
|
|
|
|
class Test_HVAC_Test_Environment extends WP_UnitTestCase {
|
|
/**
|
|
* @var HVAC_Test_Environment
|
|
*/
|
|
private $test_env;
|
|
|
|
public function setUp(): void {
|
|
parent::setUp();
|
|
$this->test_env = new HVAC_Test_Environment();
|
|
}
|
|
|
|
public function test_environment_setup() {
|
|
// Verify environment setup works
|
|
$this->test_env->setUp();
|
|
$this->assertTrue($this->test_env->is_ready(), 'Test environment should be ready after setup');
|
|
}
|
|
|
|
public function test_required_plugins_active() {
|
|
$this->assertTrue(
|
|
class_exists('Tribe__Events__Main'),
|
|
'The Events Calendar plugin should be active'
|
|
);
|
|
|
|
$this->assertTrue(
|
|
class_exists('Tribe__Events__Community__Main'),
|
|
'The Events Calendar Community Events plugin should be active'
|
|
);
|
|
}
|
|
|
|
public function test_transaction_management() {
|
|
global $wpdb;
|
|
|
|
// Start environment (which starts transaction)
|
|
$this->test_env->setUp();
|
|
|
|
// Create a test post
|
|
$post_id = wp_insert_post(array(
|
|
'post_title' => 'Test Post',
|
|
'post_content' => 'Test content',
|
|
'post_status' => 'publish'
|
|
));
|
|
|
|
// Verify post exists
|
|
$this->assertNotNull(get_post($post_id), 'Post should exist before rollback');
|
|
|
|
// Tear down (which rolls back transaction)
|
|
$this->test_env->tearDown();
|
|
|
|
// Verify post doesn't exist after rollback
|
|
$this->assertNull(get_post($post_id), 'Post should not exist after rollback');
|
|
}
|
|
|
|
public function test_user_cleanup() {
|
|
// Create test user
|
|
$user_id = wp_create_user('testuser', 'password', 'test@example.com');
|
|
|
|
// Register user for cleanup
|
|
$this->test_env->register_test_user($user_id);
|
|
|
|
// Verify user exists
|
|
$this->assertNotNull(get_user_by('id', $user_id), 'User should exist before cleanup');
|
|
|
|
// Tear down environment (which cleans up users)
|
|
$this->test_env->tearDown();
|
|
|
|
// Verify user was deleted
|
|
$this->assertNull(get_user_by('id', $user_id), 'User should be deleted after cleanup');
|
|
}
|
|
|
|
public function test_environment_reset() {
|
|
// Create test event
|
|
$event_id = wp_insert_post(array(
|
|
'post_type' => 'tribe_events',
|
|
'post_title' => 'Test Event',
|
|
'post_status' => 'publish'
|
|
));
|
|
|
|
// Set up environment (which resets it)
|
|
$this->test_env->setUp();
|
|
|
|
// Verify event was deleted during reset
|
|
$this->assertNull(get_post($event_id), 'Event should be deleted during environment reset');
|
|
}
|
|
|
|
public function test_role_reset() {
|
|
// Create custom role
|
|
add_role('test_role', 'Test Role', array('read' => true));
|
|
|
|
// Reset environment
|
|
$this->test_env->setUp();
|
|
|
|
// Verify custom role still exists after reset (roles should be reset to defaults, not deleted)
|
|
$role = get_role('test_role');
|
|
$this->assertNotNull($role, 'Custom role should exist after environment reset');
|
|
|
|
// Clean up
|
|
remove_role('test_role');
|
|
}
|
|
|
|
public function test_multiple_test_users() {
|
|
// Create multiple test users
|
|
$user_ids = array();
|
|
for ($i = 0; $i < 3; $i++) {
|
|
$user_ids[] = wp_create_user(
|
|
"testuser{$i}",
|
|
'password',
|
|
"test{$i}@example.com"
|
|
);
|
|
}
|
|
|
|
// Register all users for cleanup
|
|
foreach ($user_ids as $user_id) {
|
|
$this->test_env->register_test_user($user_id);
|
|
}
|
|
|
|
// Verify all users exist
|
|
foreach ($user_ids as $user_id) {
|
|
$this->assertNotNull(
|
|
get_user_by('id', $user_id),
|
|
"User {$user_id} should exist before cleanup"
|
|
);
|
|
}
|
|
|
|
// Tear down environment
|
|
$this->test_env->tearDown();
|
|
|
|
// Verify all users were deleted
|
|
foreach ($user_ids as $user_id) {
|
|
$this->assertNull(
|
|
get_user_by('id', $user_id),
|
|
"User {$user_id} should be deleted after cleanup"
|
|
);
|
|
}
|
|
}
|
|
} |