added team permissions (#996)

This commit is contained in:
Kevin Papst
2019-08-16 01:22:33 +02:00
committed by GitHub
parent 9611646bc6
commit 561ec3b1e9
124 changed files with 4122 additions and 362 deletions

View File

@@ -10,38 +10,16 @@
namespace App\Tests\Mocks\Security;
use App\Entity\User;
use App\Entity\UserPreference;
use App\Repository\UserRepository;
use App\Security\CurrentUser;
use App\Tests\Mocks\AbstractMockFactory;
use App\Timesheet\UserDateTimeFactory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
class UserDateTimeFactoryFactory extends AbstractMockFactory
{
public function create(?string $timezone = null): UserDateTimeFactory
{
return new UserDateTimeFactory($this->getCurrentUserMock($timezone));
}
$userFactory = new CurrentUserFactory($this->getTestCase());
$currentUser = $userFactory->create(new User(), $timezone);
protected function getCurrentUserMock(?string $timezone = null)
{
$user = new User();
if (null !== $timezone) {
$pref = new UserPreference();
$pref->setName('timezone');
$pref->setValue($timezone);
$user->addPreference($pref);
}
$repository = $this->getMockBuilder(UserRepository::class)->setMethods(['getUserById'])->disableOriginalConstructor()->getMock();
$repository->expects(TestCase::exactly(1))->method('getUserById')->willReturn($user);
$token = $this->getMockBuilder(UsernamePasswordToken::class)->setMethods(['getUser'])->disableOriginalConstructor()->getMock();
$token->expects(TestCase::exactly(1))->method('getUser')->willReturn($user);
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);
return new CurrentUser($tokenStorage, $repository);
return new UserDateTimeFactory($currentUser);
}
}