1<?php 2 3namespace dokuwiki\plugin\gdpr\test; 4 5/** 6 * User cleaning tests for the gdpr plugin 7 * 8 * @group plugin_gdpr 9 * @group plugins 10 */ 11class CleanUserTest extends \DokuWikiTest 12{ 13 14 protected $pluginsEnabled = ['gdpr']; 15 16 public function setUp() 17 { 18 parent::setUp(); 19 20 $changelogFN = metaFN('some:page', '.changes'); 21 io_makeFileDir($changelogFN); 22 23 file_put_contents($changelogFN, '1522767335 192.168.0.105 C sidebar created 36 241522767349 192.168.0.105 E sidebar pubcie 12 251523956708 192.168.0.105 E sidebar admin 23 261524145287 192.168.0.105 E sidebar user 19 271524464616 192.168.0.105 E sidebar admin ok 0'); 28 } 29 30 public function tearDown() 31 { 32 parent::tearDown(); 33 unlink(getCacheName('_cleandeletedusernames_counter', '.counter.gdpr')); 34 } 35 36 public function testCleaningOneUser() 37 { 38 $deleteEventData = [ 39 'type' => 'delete', 40 'params' => [ 41 [ 42 'admin' 43 ] 44 ] 45 ]; 46 47 trigger_event('AUTH_USER_CHANGE', $deleteEventData); 48 trigger_event('INDEXER_TASKS_RUN', $data); 49 50 $actualChangelogContent = file_get_contents(metaFN('some:page', '.changes')); 51 $expectedChangelogContent = '1522767335 192.168.0.105 C sidebar created 36 521522767349 192.168.0.105 E sidebar pubcie 12 531523956708 192.168.0.105 E sidebar _deletedUser0_ 23 541524145287 192.168.0.105 E sidebar user 19 551524464616 192.168.0.105 E sidebar _deletedUser0_ ok 0'; 56 $this->assertEquals($expectedChangelogContent, $actualChangelogContent); 57 } 58 59 public function testCleaningTwoUsers() 60 { 61 $deleteEventDataAdmin = [ 62 'type' => 'delete', 63 'params' => [ 64 [ 65 'admin' 66 ] 67 ] 68 ]; 69 $deleteEventDataPubcie = [ 70 'type' => 'delete', 71 'params' => [ 72 [ 73 'pubcie' 74 ] 75 ] 76 ]; 77 78 trigger_event('AUTH_USER_CHANGE', $deleteEventDataAdmin); 79 trigger_event('AUTH_USER_CHANGE', $deleteEventDataPubcie); 80 trigger_event('INDEXER_TASKS_RUN', $data); 81 trigger_event('INDEXER_TASKS_RUN', $data); 82 trigger_event('INDEXER_TASKS_RUN', $data); 83 trigger_event('INDEXER_TASKS_RUN', $data); 84 85 $actualChangelogContentFile1 = file_get_contents(metaFN('some:page', '.changes')); 86 $expectedChangelogContentFile1 = '1522767335 192.168.0.105 C sidebar created 36 871522767349 192.168.0.105 E sidebar _deletedUser1_ 12 881523956708 192.168.0.105 E sidebar _deletedUser0_ 23 891524145287 192.168.0.105 E sidebar user 19 901524464616 192.168.0.105 E sidebar _deletedUser0_ ok 0'; 91 $this->assertEquals($expectedChangelogContentFile1, $actualChangelogContentFile1); 92 93 $actualChangelogContentFile2 = file_get_contents(metaFN('mailinglist', '.changes')); 94 $expectedChangelogContentFile2 = '1360110636 127.0.0.1 C mailinglist _deletedUser1_ aangemaakt 951361901536 127.0.0.1 E mailinglist _deletedUser1_ 961362524799 127.0.0.1 E mailinglist _deletedUser1_ 971362525145 127.0.0.1 E mailinglist _deletedUser1_ 981362525359 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 991362525899 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1001362525926 127.0.0.1 E mailinglist _deletedUser1_ 1011362526039 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1021362526119 127.0.0.1 E mailinglist _deletedUser1_ 1031362526167 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1041362526767 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1051362526861 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1061362527046 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1071362527164 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1081363436892 127.0.0.1 E mailinglist _deletedUser1_ 1091368575634 127.0.0.1 E mailinglist _deletedUser1_ 1101368609772 127.0.0.1 E mailinglist _deletedUser1_ 1111368612506 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1121368612599 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1131368622152 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1141368622195 127.0.0.1 E mailinglist _deletedUser1_ 1151368622240 127.0.0.1 E mailinglist _deletedUser1_ [Data entry] 1161371579614 127.0.0.1 E mailinglist _deletedUser1_ 1171374261194 127.0.0.1 E mailinglist _deletedUser1_ 118'; 119 $this->assertEquals($expectedChangelogContentFile2, $actualChangelogContentFile2); 120 } 121} 122