<?php

namespace Concrete\TestHelpers\User;

use Concrete\Core\Attribute\Key\Category;
use Concrete\Core\User\UserInfo;
use Concrete\TestHelpers\Database\ConcreteDatabaseTestCase;

abstract class UserTestCase extends ConcreteDatabaseTestCase
{
    protected $fixtures = [];
    protected $tables = [
        'UserGroups', 'Groups', 'GroupTypes',
        'TreeTypes', 'TreeNodes', 'TreeNodePermissionAssignments',
        'PermissionKeyCategories', 'PermissionKeys', 'TreeNodeTypes', 'Trees',
        'TreeGroupNodes',
    ]; // so brutal

    protected $entityClassNames = [
        'Concrete\Core\Entity\User\User',
        'Concrete\Core\Entity\User\UserSignup',
        'Concrete\Core\Entity\Attribute\Category',
        'Concrete\Core\Entity\Attribute\Key\Key',
        'Concrete\Core\Entity\Attribute\Key\UserKey',
    ];

    protected static $users = [];

    public static function setUpBeforeClass():void
    {
        parent::setUpBeforeClass(); // TODO: Change the autogenerated stub
        Category::add('user');
    }

    public static function tearDownAfterClass():void
    {
        parent::tearDownAfterClass();
        static::$users = [];
    }

    protected static function createUser($uName, $uEmail)
    {
        $key = "{$uName}.{$uEmail}";
        if (!isset(static::$users[$key])) {
            static::$users[$key] = UserInfo::add(
                ['uName' => $uName, 'uEmail' => $uEmail]
            );
        }

        return static::$users[$key];
    }
}
