- 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.
		
			
				
	
	
		
			76 lines
		
	
	
		
			No EOL
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			No EOL
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| class HVAC_Test_User_Factory_Test extends WP_UnitTestCase {
 | |
| 
 | |
|     public function test_user_creation_with_single_role() {
 | |
|         $role = 'test_role_' . uniqid();
 | |
|         HVAC_Role_Manager::create_role($role);
 | |
|         
 | |
|         $user = HVAC_Test_User_Factory::create_user([
 | |
|             'username' => 'testuser_' . uniqid(),
 | |
|             'roles' => [$role]
 | |
|         ]);
 | |
|         
 | |
|         $this->assertInstanceOf('WP_User', $user);
 | |
|         $this->assertTrue(in_array($role, $user->roles));
 | |
|     }
 | |
| 
 | |
|     public function test_user_creation_with_multiple_roles() {
 | |
|         $roles = [
 | |
|             'test_role1_' . uniqid(),
 | |
|             'test_role2_' . uniqid()
 | |
|         ];
 | |
|         
 | |
|         foreach ($roles as $role) {
 | |
|             HVAC_Role_Manager::create_role($role);
 | |
|         }
 | |
|         
 | |
|         $user = HVAC_Test_User_Factory::create_user([
 | |
|             'username' => 'testuser_' . uniqid(),
 | |
|             'roles' => $roles
 | |
|         ]);
 | |
|         
 | |
|         $this->assertInstanceOf('WP_User', $user);
 | |
|         foreach ($roles as $role) {
 | |
|             $this->assertTrue(in_array($role, $user->roles));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public function test_persona_management() {
 | |
|         $persona = 'test_persona_' . uniqid();
 | |
|         $roles = ['test_role1_' . uniqid(), 'test_role2_' . uniqid()];
 | |
|         
 | |
|         HVAC_Test_User_Factory::define_persona($persona, [
 | |
|             'roles' => $roles,
 | |
|             'meta' => [
 | |
|                 'test_meta' => 'value'
 | |
|             ]
 | |
|         ]);
 | |
|         
 | |
|         $user = HVAC_Test_User_Factory::create_user([
 | |
|             'username' => 'testuser_' . uniqid(),
 | |
|             'persona' => $persona
 | |
|         ]);
 | |
|         
 | |
|         $this->assertInstanceOf('WP_User', $user);
 | |
|         foreach ($roles as $role) {
 | |
|             $this->assertTrue(in_array($role, $user->roles));
 | |
|         }
 | |
|         $this->assertEquals('value', get_user_meta($user->ID, 'test_meta', true));
 | |
|     }
 | |
| 
 | |
|     public function test_account_cleanup() {
 | |
|         $role = 'test_cleanup_role_' . uniqid();
 | |
|         HVAC_Role_Manager::create_role($role);
 | |
|         
 | |
|         $user = HVAC_Test_User_Factory::create_user([
 | |
|             'username' => 'testuser_' . uniqid(),
 | |
|             'roles' => [$role]
 | |
|         ]);
 | |
|         
 | |
|         HVAC_Test_User_Factory::cleanup_user($user->ID);
 | |
|         
 | |
|         $this->assertFalse(HVAC_Role_Manager::role_exists($role));
 | |
|         $this->assertFalse(get_user_by('id', $user->ID));
 | |
|     }
 | |
| } |