1*4515310dSAndreas Gohr<?php 2*4515310dSAndreas Gohrnamespace dokuwiki\plugin\dbquery\test; 3*4515310dSAndreas Gohr 4*4515310dSAndreas Gohruse DokuWikiTest; 5*4515310dSAndreas Gohr 6*4515310dSAndreas Gohr/** 7*4515310dSAndreas Gohr * General tests for the dbquery plugin 8*4515310dSAndreas Gohr * 9*4515310dSAndreas Gohr * @group plugin_dbquery 10*4515310dSAndreas Gohr * @group plugins 11*4515310dSAndreas Gohr */ 12*4515310dSAndreas Gohrclass HelperTest extends DokuWikiTest 13*4515310dSAndreas Gohr{ 14*4515310dSAndreas Gohr protected $pluginsEnabled = array('dbquery'); 15*4515310dSAndreas Gohr /** @var \helper_plugin_dbquery $hlp */ 16*4515310dSAndreas Gohr protected $hlp; 17*4515310dSAndreas Gohr 18*4515310dSAndreas Gohr /** @inheritDoc */ 19*4515310dSAndreas Gohr public function setUp(): void 20*4515310dSAndreas Gohr { 21*4515310dSAndreas Gohr parent::setUp(); 22*4515310dSAndreas Gohr $this->hlp = plugin_load('helper', 'dbquery'); 23*4515310dSAndreas Gohr } 24*4515310dSAndreas Gohr 25*4515310dSAndreas Gohr public function testGatherVariables() 26*4515310dSAndreas Gohr { 27*4515310dSAndreas Gohr global $INFO; 28*4515310dSAndreas Gohr $INFO['id'] = 'foo:bar:baz'; 29*4515310dSAndreas Gohr 30*4515310dSAndreas Gohr $expected = [ 31*4515310dSAndreas Gohr ':user' => '', 32*4515310dSAndreas Gohr ':mail' => '', 33*4515310dSAndreas Gohr ':groups' => [], 34*4515310dSAndreas Gohr ':id' => ':foo:bar:baz', 35*4515310dSAndreas Gohr ':page' => 'baz', 36*4515310dSAndreas Gohr ':ns' => ':foo:bar', 37*4515310dSAndreas Gohr ]; 38*4515310dSAndreas Gohr $actual = $this->hlp->gatherVariables(); 39*4515310dSAndreas Gohr $this->assertEquals($expected, $actual); 40*4515310dSAndreas Gohr } 41*4515310dSAndreas Gohr 42*4515310dSAndreas Gohr public function testGatherVariablesUser() 43*4515310dSAndreas Gohr { 44*4515310dSAndreas Gohr global $INFO; 45*4515310dSAndreas Gohr /** @var \auth_plugin_authplain $auth */ 46*4515310dSAndreas Gohr global $auth; 47*4515310dSAndreas Gohr 48*4515310dSAndreas Gohr $INFO['id'] = 'foo:bar:baz'; 49*4515310dSAndreas Gohr $auth->createUser('foo', 'bar', 'My Test User', 'foo@example.com', ['one', 'two', 'three']); 50*4515310dSAndreas Gohr auth_login('foo', 'bar'); 51*4515310dSAndreas Gohr 52*4515310dSAndreas Gohr $expected = [ 53*4515310dSAndreas Gohr ':user' => 'foo', 54*4515310dSAndreas Gohr ':mail' => 'foo@example.com', 55*4515310dSAndreas Gohr ':groups' => ['one', 'two', 'three'], 56*4515310dSAndreas Gohr ':id' => ':foo:bar:baz', 57*4515310dSAndreas Gohr ':page' => 'baz', 58*4515310dSAndreas Gohr ':ns' => ':foo:bar', 59*4515310dSAndreas Gohr ]; 60*4515310dSAndreas Gohr $actual = $this->hlp->gatherVariables(); 61*4515310dSAndreas Gohr $this->assertEquals($expected, $actual); 62*4515310dSAndreas Gohr } 63*4515310dSAndreas Gohr 64*4515310dSAndreas Gohr public function testPrepareStatement() 65*4515310dSAndreas Gohr { 66*4515310dSAndreas Gohr $pdo = $this->hlp->getPDO('sqlite:', '', ''); 67*4515310dSAndreas Gohr 68*4515310dSAndreas Gohr $parameters = [ 69*4515310dSAndreas Gohr ':user' => 'foo', 70*4515310dSAndreas Gohr ':mail' => 'foo@example.com', 71*4515310dSAndreas Gohr ':groups' => ['one', 'two', 'three'], 72*4515310dSAndreas Gohr ':id' => ':foo:bar:baz', 73*4515310dSAndreas Gohr ':page' => 'baz', 74*4515310dSAndreas Gohr ':ns' => ':foo:bar', 75*4515310dSAndreas Gohr ]; 76*4515310dSAndreas Gohr $sql = 'SELECT :user, :mail, :id, :page, :ns WHERE \'foo\' in (:groups)'; 77*4515310dSAndreas Gohr $sth = $this->hlp->prepareStatement($pdo, $sql, $parameters); 78*4515310dSAndreas Gohr 79*4515310dSAndreas Gohr $actual = $sth->queryString; 80*4515310dSAndreas Gohr $expected = 'SELECT :user, :mail, :id, :page, :ns WHERE \'foo\' in (:group0,:group1,:group2)'; 81*4515310dSAndreas Gohr $this->assertEquals($expected, $actual); 82*4515310dSAndreas Gohr } 83*4515310dSAndreas Gohr} 84