- 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.
73 lines
No EOL
2.7 KiB
PHP
73 lines
No EOL
2.7 KiB
PHP
<?php
|
|
/**
|
|
* Tests for HVAC_Test_User_Factory class
|
|
*/
|
|
|
|
require_once __DIR__ . '/includes/class-hvac-test-user-factory.php';
|
|
require_once __DIR__ . '/includes/class-hvac-base-test-case.php';
|
|
|
|
class HVAC_Test_User_Factory_Test extends HVAC_Base_Test_Case {
|
|
/** @var HVAC_Test_User_Factory */
|
|
private $factory;
|
|
|
|
public function setUp(): void {
|
|
parent::setUp();
|
|
$this->factory = new HVAC_Test_User_Factory();
|
|
}
|
|
|
|
public function tearDown(): void {
|
|
$this->factory->cleanup();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_create_user_with_single_role() {
|
|
$user_id = $this->factory->create_user('testuser1', ['hvac_trainer']);
|
|
$this->assertNotWPError($user_id);
|
|
$this->assertTrue($this->factory->validate_user_roles($user_id, ['hvac_trainer']));
|
|
}
|
|
|
|
public function test_create_user_with_multiple_roles() {
|
|
$user_id = $this->factory->create_user('testuser2', ['hvac_trainer', 'subscriber']);
|
|
$this->assertNotWPError($user_id);
|
|
$this->assertTrue($this->factory->validate_user_roles($user_id, ['hvac_trainer', 'subscriber']));
|
|
}
|
|
|
|
public function test_create_user_with_persona() {
|
|
$user_id = $this->factory->create_user_with_persona('testuser3', 'basic_trainer');
|
|
$this->assertNotWPError($user_id);
|
|
|
|
$this->assertTrue($this->factory->validate_user_roles($user_id, ['hvac_trainer']));
|
|
$this->assertEquals('Test HVAC Training Co.', get_user_meta($user_id, 'company_name', true));
|
|
}
|
|
|
|
public function test_cleanup_removes_all_created_users() {
|
|
$user1 = $this->factory->create_user('testuser4', ['hvac_trainer']);
|
|
$user2 = $this->factory->create_user('testuser5', ['hvac_trainer']);
|
|
|
|
$this->assertNotWPError($user1);
|
|
$this->assertNotWPError($user2);
|
|
|
|
$this->factory->cleanup();
|
|
|
|
$this->assertFalse(get_user_by('ID', $user1));
|
|
$this->assertFalse(get_user_by('ID', $user2));
|
|
}
|
|
|
|
public function test_get_available_personas() {
|
|
$personas = $this->factory->get_available_personas();
|
|
$this->assertContains('basic_trainer', $personas);
|
|
$this->assertContains('advanced_trainer', $personas);
|
|
$this->assertContains('admin_trainer', $personas);
|
|
}
|
|
|
|
public function test_add_custom_persona() {
|
|
$result = $this->factory->add_persona('custom_trainer', [
|
|
'roles' => ['hvac_trainer'],
|
|
'capabilities' => ['custom_cap'],
|
|
'meta' => ['custom_field' => 'value']
|
|
]);
|
|
|
|
$this->assertTrue($result);
|
|
$this->assertNotNull($this->factory->get_persona_config('custom_trainer'));
|
|
}
|
|
} |