- 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.
123 lines
No EOL
3.5 KiB
PHP
123 lines
No EOL
3.5 KiB
PHP
<?php
|
|
/**
|
|
* Base Test Case Class
|
|
*
|
|
* Provides common functionality for all HVAC test cases.
|
|
*/
|
|
|
|
class HVAC_Base_Test_Case extends WP_UnitTestCase {
|
|
/**
|
|
* @var HVAC_Test_Environment
|
|
*/
|
|
protected $test_env;
|
|
|
|
/**
|
|
* Set up the test environment before each test
|
|
*/
|
|
public function setUp(): void {
|
|
parent::setUp();
|
|
|
|
// Initialize test environment
|
|
$this->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)
|
|
);
|
|
}
|
|
}
|
|
} |