test_env = new HVAC_Test_Environment(); // Verify environment is ready if (!$this->test_env->is_ready()) { $this->markTestSkipped('Test environment is not properly configured'); } // Set up test environment $this->test_env->setUp(); } /** * Clean up after each test */ public function tearDown(): void { // Clean up test environment if ($this->test_env) { $this->test_env->tearDown(); } parent::tearDown(); } /** * Create a test user with specified role * * @param string $role The role to assign to the user * @param array $args Optional. Additional user arguments * @return int|WP_Error The user ID or WP_Error on failure */ protected function create_test_user($role = 'subscriber', $args = array()) { $default_args = array( 'role' => $role, 'user_login' => 'testuser_' . wp_rand(), 'user_pass' => 'password', 'user_email' => 'testuser_' . wp_rand() . '@example.com' ); $args = wp_parse_args($args, $default_args); $user_id = wp_insert_user($args); if (!is_wp_error($user_id)) { // Register user for cleanup $this->test_env->register_test_user($user_id); } return $user_id; } /** * Create a test event * * @param array $args Optional. Event arguments * @return int|WP_Error The event ID or WP_Error on failure */ protected function create_test_event($args = array()) { $default_args = array( 'post_type' => 'tribe_events', 'post_title' => 'Test Event ' . wp_rand(), 'post_status' => 'publish', 'post_content' => 'Test event content' ); $args = wp_parse_args($args, $default_args); return wp_insert_post($args); } /** * Assert that a user has specific capabilities * * @param int|WP_User $user User ID or WP_User object * @param array $capabilities Array of capabilities to check */ protected function assertUserCan($user, $capabilities) { $user = is_numeric($user) ? get_user_by('id', $user) : $user; foreach ($capabilities as $cap) { $this->assertTrue( user_can($user, $cap), sprintf('User does not have expected capability: %s', $cap) ); } } /** * Assert that a user does not have specific capabilities * * @param int|WP_User $user User ID or WP_User object * @param array $capabilities Array of capabilities to check */ protected function assertUserCannot($user, $capabilities) { $user = is_numeric($user) ? get_user_by('id', $user) : $user; foreach ($capabilities as $cap) { $this->assertFalse( user_can($user, $cap), sprintf('User has unexpected capability: %s', $cap) ); } } }