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" ); } } }