1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kitodo\Dlf\Tests\Functional\Repository; |
4
|
|
|
|
5
|
|
|
use Kitodo\Dlf\Domain\Repository\TokenRepository; |
6
|
|
|
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; |
7
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; |
8
|
|
|
|
9
|
|
|
class TokenRepositoryTest extends FunctionalTestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var TokenRepository |
13
|
|
|
*/ |
14
|
|
|
protected $tokenRepository; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var PersistenceManager |
18
|
|
|
*/ |
19
|
|
|
protected $persistenceManager; |
20
|
|
|
|
21
|
|
|
public function setUp(): void |
22
|
|
|
{ |
23
|
|
|
parent::setUp(); |
24
|
|
|
|
25
|
|
|
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class); |
|
|
|
|
26
|
|
|
|
27
|
|
|
$this->tokenRepository = $this->initializeRepository( |
28
|
|
|
TokenRepository::class, |
29
|
|
|
20000 |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function tearDown(): void |
34
|
|
|
{ |
35
|
|
|
parent::tearDown(); |
36
|
|
|
|
37
|
|
|
unlink(__DIR__ . '/../../Fixtures/Repository/tokenTemp.xml'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @test |
42
|
|
|
* @group delete |
43
|
|
|
*/ |
44
|
|
|
public function deleteExpiredTokens(): void |
45
|
|
|
{ |
46
|
|
|
$xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Repository/token.xml'); |
47
|
|
|
|
48
|
|
|
$expireTime = 3600; |
49
|
|
|
$i = 1; |
50
|
|
|
foreach ($xml as $node) { |
51
|
|
|
if ($i % 2 == 0) { |
52
|
|
|
$node->tstamp = time() - $expireTime - random_int(10, 3600); |
|
|
|
|
53
|
|
|
} else { |
54
|
|
|
$node->tstamp = time() - $expireTime + random_int(10, 3600); |
55
|
|
|
} |
56
|
|
|
$i++; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$xml->saveXML(__DIR__ . '/../../Fixtures/Repository/tokenTemp.xml'); |
60
|
|
|
|
61
|
|
|
$this->importDataSet(__DIR__ . '/../../Fixtures/Repository/tokenTemp.xml'); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$this->tokenRepository->deleteExpiredTokens($expireTime); |
64
|
|
|
|
65
|
|
|
$this->persistenceManager->persistAll(); |
66
|
|
|
|
67
|
|
|
$tokens = $this->tokenRepository->findAll(); |
68
|
|
|
|
69
|
|
|
$this->assertEquals(2, $tokens->count()); |
70
|
|
|
|
71
|
|
|
$tokenUids = []; |
72
|
|
|
foreach ($tokens as $token) { |
73
|
|
|
$tokenUids[$token->getUid()] = $token; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$this->assertArrayHasKey('101', $tokenUids); |
77
|
|
|
$this->assertArrayHasKey('103', $tokenUids); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.