1*09527955SAndreas Gohr<?php 2*09527955SAndreas Gohr 3*09527955SAndreas Gohr 4*09527955SAndreas Gohrnamespace dokuwiki\plugin\acknowledge\test; 5*09527955SAndreas Gohr 6*09527955SAndreas Gohruse DokuWikiTest; 7*09527955SAndreas Gohr 8*09527955SAndreas Gohr/** 9*09527955SAndreas Gohr * Helper tests for the acknowledge plugin 10*09527955SAndreas Gohr * 11*09527955SAndreas Gohr * @group plugin_acknowledge 12*09527955SAndreas Gohr * @group plugins 13*09527955SAndreas Gohr */ 14*09527955SAndreas Gohrclass HelperTest extends DokuWikiTest 15*09527955SAndreas Gohr{ 16*09527955SAndreas Gohr /** @var array */ 17*09527955SAndreas Gohr protected $pluginsEnabled = ['acknowledge', 'sqlite']; 18*09527955SAndreas Gohr /** @var \helper_plugin_acknowledge $helper */ 19*09527955SAndreas Gohr protected $helper; 20*09527955SAndreas Gohr /** @var \helper_plugin_sqlite */ 21*09527955SAndreas Gohr protected $db; 22*09527955SAndreas Gohr 23*09527955SAndreas Gohr public static function setUpBeforeClass(): void 24*09527955SAndreas Gohr { 25*09527955SAndreas Gohr parent::setUpBeforeClass(); 26*09527955SAndreas Gohr /** @var \auth_plugin_authplain $auth */ 27*09527955SAndreas Gohr global $auth; 28*09527955SAndreas Gohr $auth->createUser('max', 'none', 'max', 'max@example.com', ['super']); 29*09527955SAndreas Gohr } 30*09527955SAndreas Gohr 31*09527955SAndreas Gohr public function setUp(): void 32*09527955SAndreas Gohr { 33*09527955SAndreas Gohr parent::setUp(); 34*09527955SAndreas Gohr $this->helper = plugin_load('helper', 'acknowledge'); 35*09527955SAndreas Gohr 36*09527955SAndreas Gohr $this->db = $this->helper->getDB(); 37*09527955SAndreas Gohr 38*09527955SAndreas Gohr $pages = "REPLACE INTO pages(page,lastmod) 39*09527955SAndreas Gohr VALUES ('dokuwiki:acktest1', 1560805365), 40*09527955SAndreas Gohr ('dokuwiki:acktest2', 1560805365), 41*09527955SAndreas Gohr ('dokuwiki:acktest3', 1560805365)"; 42*09527955SAndreas Gohr $this->db->query($pages); 43*09527955SAndreas Gohr 44*09527955SAndreas Gohr $assignments = "REPLACE INTO assignments(page,pageassignees) 45*09527955SAndreas Gohr VALUES ('dokuwiki:acktest1', 'regular, @super'), 46*09527955SAndreas Gohr ('dokuwiki:acktest2', '@super'), 47*09527955SAndreas Gohr ('dokuwiki:acktest3', '@user')"; 48*09527955SAndreas Gohr $this->db->query($assignments); 49*09527955SAndreas Gohr 50*09527955SAndreas Gohr $acks = "REPLACE INTO acks(page,user,ack) 51*09527955SAndreas Gohr VALUES ('dokuwiki:acktest3', 'regular', 1550801270), 52*09527955SAndreas Gohr ('dokuwiki:acktest3', 'regular', 1560805555), 53*09527955SAndreas Gohr ('dokuwiki:acktest1', 'max', 1550805770), 54*09527955SAndreas Gohr ('dokuwiki:acktest1', 'max', 1560805770), 55*09527955SAndreas Gohr ('dokuwiki:acktest3', 'max', 1560805000) 56*09527955SAndreas Gohr "; 57*09527955SAndreas Gohr $this->db->query($acks); 58*09527955SAndreas Gohr } 59*09527955SAndreas Gohr 60*09527955SAndreas Gohr /** 61*09527955SAndreas Gohr * test latest acknowledgements 62*09527955SAndreas Gohr */ 63*09527955SAndreas Gohr public function test_getLatestAcknowledgements() 64*09527955SAndreas Gohr { 65*09527955SAndreas Gohr $actual = $this->helper->getAcknowledgements(); 66*09527955SAndreas Gohr $expected = [ 67*09527955SAndreas Gohr [ 68*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest1', 69*09527955SAndreas Gohr 'user' => 'max', 70*09527955SAndreas Gohr 'ack' => '1560805770', 71*09527955SAndreas Gohr 'lastmod' => '1560805365', 72*09527955SAndreas Gohr ], 73*09527955SAndreas Gohr [ 74*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest3', 75*09527955SAndreas Gohr 'user' => 'regular', 76*09527955SAndreas Gohr 'ack' => '1560805555', 77*09527955SAndreas Gohr 'lastmod' => '1560805365', 78*09527955SAndreas Gohr ], 79*09527955SAndreas Gohr [ 80*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest3', 81*09527955SAndreas Gohr 'user' => 'max', 82*09527955SAndreas Gohr 'ack' => '1560805000', 83*09527955SAndreas Gohr 'lastmod' => '1560805365', 84*09527955SAndreas Gohr ], 85*09527955SAndreas Gohr ]; 86*09527955SAndreas Gohr $this->assertEquals($expected, $actual); 87*09527955SAndreas Gohr } 88*09527955SAndreas Gohr 89*09527955SAndreas Gohr /** 90*09527955SAndreas Gohr * test latest acknowledgements limited to 1 91*09527955SAndreas Gohr */ 92*09527955SAndreas Gohr public function test_getLimitedAcknowledgements() 93*09527955SAndreas Gohr { 94*09527955SAndreas Gohr $actual = $this->helper->getAcknowledgements(1); 95*09527955SAndreas Gohr $expected = [ 96*09527955SAndreas Gohr [ 97*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest1', 98*09527955SAndreas Gohr 'user' => 'max', 99*09527955SAndreas Gohr 'ack' => '1560805770', 100*09527955SAndreas Gohr 'lastmod' => '1560805365', 101*09527955SAndreas Gohr ], 102*09527955SAndreas Gohr ]; 103*09527955SAndreas Gohr $this->assertEquals($expected, $actual); 104*09527955SAndreas Gohr } 105*09527955SAndreas Gohr 106*09527955SAndreas Gohr /** 107*09527955SAndreas Gohr * test assignment query 108*09527955SAndreas Gohr */ 109*09527955SAndreas Gohr public function test_getUserAssignments() 110*09527955SAndreas Gohr { 111*09527955SAndreas Gohr $actual = $this->helper->getUserAssignments('regular', ['user']); 112*09527955SAndreas Gohr $expected = [ 113*09527955SAndreas Gohr [ 114*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest1', 115*09527955SAndreas Gohr 'pageassignees' => 'regular, @super', 116*09527955SAndreas Gohr 'autoassignees' => '', 117*09527955SAndreas Gohr 'lastmod' => '1560805365', 118*09527955SAndreas Gohr 'user' => null, 119*09527955SAndreas Gohr 'ack' => null, 120*09527955SAndreas Gohr ], 121*09527955SAndreas Gohr ]; 122*09527955SAndreas Gohr $this->assertEquals($expected, $actual); 123*09527955SAndreas Gohr 124*09527955SAndreas Gohr $actual = $this->helper->getUserAssignments('max', ['user', 'super']); 125*09527955SAndreas Gohr $expected = [ 126*09527955SAndreas Gohr [ 127*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest2', 128*09527955SAndreas Gohr 'pageassignees' => '@super', 129*09527955SAndreas Gohr 'autoassignees' => '', 130*09527955SAndreas Gohr 'lastmod' => '1560805365', 131*09527955SAndreas Gohr 'user' => null, 132*09527955SAndreas Gohr 'ack' => null, 133*09527955SAndreas Gohr ], 134*09527955SAndreas Gohr [ 135*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest3', 136*09527955SAndreas Gohr 'pageassignees' => '@user', 137*09527955SAndreas Gohr 'autoassignees' => '', 138*09527955SAndreas Gohr 'lastmod' => '1560805365', 139*09527955SAndreas Gohr 'user' => null, 140*09527955SAndreas Gohr 'ack' => null, 141*09527955SAndreas Gohr ], 142*09527955SAndreas Gohr ]; 143*09527955SAndreas Gohr $this->assertEquals($expected, $actual); 144*09527955SAndreas Gohr } 145*09527955SAndreas Gohr 146*09527955SAndreas Gohr public function test_getUserAcknowledgements() 147*09527955SAndreas Gohr { 148*09527955SAndreas Gohr $actual = $this->helper->getUserAcknowledgements('max', ['user', 'super']); 149*09527955SAndreas Gohr $expected = [ 150*09527955SAndreas Gohr [ 151*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest1', 152*09527955SAndreas Gohr 'pageassignees' => 'regular, @super', 153*09527955SAndreas Gohr 'autoassignees' => '', 154*09527955SAndreas Gohr 'lastmod' => '1560805365', 155*09527955SAndreas Gohr 'user' => 'max', 156*09527955SAndreas Gohr 'ack' => '1560805770', 157*09527955SAndreas Gohr ], 158*09527955SAndreas Gohr [ 159*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest2', 160*09527955SAndreas Gohr 'pageassignees' => '@super', 161*09527955SAndreas Gohr 'autoassignees' => '', 162*09527955SAndreas Gohr 'lastmod' => '1560805365', 163*09527955SAndreas Gohr 'user' => null, 164*09527955SAndreas Gohr 'ack' => null, 165*09527955SAndreas Gohr ], 166*09527955SAndreas Gohr [ 167*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest3', 168*09527955SAndreas Gohr 'pageassignees' => '@user', 169*09527955SAndreas Gohr 'autoassignees' => '', 170*09527955SAndreas Gohr 'lastmod' => '1560805365', 171*09527955SAndreas Gohr 'user' => 'max', 172*09527955SAndreas Gohr 'ack' => '1560805000', 173*09527955SAndreas Gohr ], 174*09527955SAndreas Gohr ]; 175*09527955SAndreas Gohr $this->assertEquals($expected, $actual); 176*09527955SAndreas Gohr } 177*09527955SAndreas Gohr 178*09527955SAndreas Gohr /** 179*09527955SAndreas Gohr * Check what users are assigned to a page that has a user and a group in the database 180*09527955SAndreas Gohr */ 181*09527955SAndreas Gohr public function test_getPageAssignees() 182*09527955SAndreas Gohr { 183*09527955SAndreas Gohr $actual = $this->helper->getPageAssignees('dokuwiki:acktest1'); 184*09527955SAndreas Gohr $expected = ['regular', 'max']; 185*09527955SAndreas Gohr $this->assertEquals($expected, $actual); 186*09527955SAndreas Gohr } 187*09527955SAndreas Gohr 188*09527955SAndreas Gohr /** 189*09527955SAndreas Gohr * Check what acknowledgments are there for a page 190*09527955SAndreas Gohr */ 191*09527955SAndreas Gohr public function test_getPageAcknowledgements() 192*09527955SAndreas Gohr { 193*09527955SAndreas Gohr $actual = $this->helper->getPageAcknowledgements('dokuwiki:acktest1'); 194*09527955SAndreas Gohr $expected = [ 195*09527955SAndreas Gohr [ 196*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest1', 197*09527955SAndreas Gohr 'lastmod' => '1560805365', 198*09527955SAndreas Gohr 'user' => 'max', 199*09527955SAndreas Gohr 'ack' => '1560805770', 200*09527955SAndreas Gohr ], 201*09527955SAndreas Gohr [ 202*09527955SAndreas Gohr 'page' => 'dokuwiki:acktest1', 203*09527955SAndreas Gohr 'lastmod' => '1560805365', 204*09527955SAndreas Gohr 'user' => 'regular', 205*09527955SAndreas Gohr 'ack' => null, 206*09527955SAndreas Gohr ], 207*09527955SAndreas Gohr 208*09527955SAndreas Gohr ]; 209*09527955SAndreas Gohr $this->assertEquals($expected, $actual); 210*09527955SAndreas Gohr 211*09527955SAndreas Gohr } 212*09527955SAndreas Gohr} 213