<?php

namespace AuthStack\Driver\System\tests\units;

use mageekguy\atoum;
use AuthStack\Driver\Model\User as UserModel;
use AuthStack\Driver\System\User as SystemUser;
use AuthStack\Driver\System\Driver as SystemDriver;

class User extends atoum
{
    public function testRetrieveByPrimaryKey()
    {
        $this
            ->given($driver = SystemDriver::initialize('', 1))
            ->then
                ->object($user = $driver->getUserByPrimaryKey(1))->isInstanceOf(SystemUser::class)
                ->boolean($user->removeSecurityKey(15))->isFalse()
                ->integer($user->getAuthstackID())->isEqualTo(1)
                ->array($user->toArray())->isNotEmpty()->hasSize(5)
        ;
    }

    public function testRetrieveDatetimeFormat()
    {
        $this->given($user = $this->getUser())
            ->then
                ->string($user->getDateTimeFormat())->isEqualTo('DD.MM.YYYY')
            ;
    }

    public function testRetrieveTimeZone()
    {
        $this->given($user = $this->getUser())
            ->then
                ->string($user->getTimeZone())->isEqualTo('Europe/Zagreb')
                ->object($user->getTimeZone(true))->isInstanceOf(\DateTimeZone::class)

            ;
    }

    public function testRetrieveProfileImage()
    {
        $this->given($user = $this->getUser())
            ->then
            ->string($user->getProfileImage())->isEqualTo('')

        ;
    }

    /**
     * @return SystemUser
     */
    protected function getUser()
    {
        $driver = SystemDriver::initialize('', 1);

        return $driver->getUserByPrimaryKey(1);
    }
}
