1<?php
2
3namespace dokuwiki\plugin\gdpr\test;
4
5/**
6 * Media IP cleaning tests for the gdpr plugin
7 *
8 * @group plugin_gdpr
9 * @group plugins
10 */
11class CleanMediaTest extends \DokuWikiTest
12{
13    protected $pluginsEnabled = ['gdpr'];
14
15    protected $yesterday;
16
17    protected $mediaID = 'galaxy:andromeda.jpg';
18
19    public function setUp()
20    {
21        parent::setUp();
22
23        $changelogFN = mediaMetaFN($this->mediaID, '.changes');
24        io_makeFileDir($changelogFN);
25        $this->yesterday = time() - 60 * 60 * 24;
26        file_put_contents($changelogFN, '1522767335	192.168.0.105	C	galaxy:andromeda.jpg		created		36
271522767349	192.168.0.105	E	galaxy:andromeda.jpg				12
281523956708	192.168.0.105	E	galaxy:andromeda.jpg	admin			23
291524145287	192.168.0.105	E	galaxy:andromeda.jpg	admin			19
301524464616	192.168.0.105	E	galaxy:andromeda.jpg	admin	ok		0
31');
32        $handle = fopen($changelogFN, 'ab');
33        $recentChangelogLine = $this->yesterday . "	192.168.0.105	E	galaxy:andromeda.jpg	admin	ok		0\n";
34        fwrite($handle, $recentChangelogLine);
35        fclose($handle);
36    }
37
38    public function testCleaningChangelog()
39    {
40        $eventData = [
41            'isMedia' => true,
42            'trimmedChangelogLines' => [],
43            'removedChangelogLines' => ['1526477811	192.168.0.105	C	galaxy:andromeda.jpg	admin	created		1689508'],
44        ];
45
46        trigger_event('TASK_RECENTCHANGES_TRIM', $eventData);
47        $actualChangelogContent = file_get_contents(mediaMetaFN($this->mediaID, '.changes'));
48
49        $expectedChangelogContent = '1522767335	             	C	galaxy:andromeda.jpg		created		36
501522767349	             	E	galaxy:andromeda.jpg				12
511523956708	             	E	galaxy:andromeda.jpg	admin			23
521524145287	             	E	galaxy:andromeda.jpg	admin			19
531524464616	             	E	galaxy:andromeda.jpg	admin	ok		0
54' . $this->yesterday . "	192.168.0.105	E	galaxy:andromeda.jpg	admin	ok		0\n";
55        $this->assertEquals($expectedChangelogContent, $actualChangelogContent);
56
57    }
58}
59