Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7411821
DeleteQueryBuilderTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
DeleteQueryBuilderTest.php
View Options
<?php
namespace
Wikimedia\Tests\Rdbms
;
use
DatabaseTestHelper
;
use
MediaWikiCoversValidator
;
use
PHPUnit\Framework\TestCase
;
use
Wikimedia\Rdbms\DeleteQueryBuilder
;
use
Wikimedia\Rdbms\Platform\ISQLPlatform
;
/**
* @covers \Wikimedia\Rdbms\DeleteQueryBuilder
*/
class
DeleteQueryBuilderTest
extends
TestCase
{
use
MediaWikiCoversValidator
;
private
DatabaseTestHelper
$db
;
private
DeleteQueryBuilder
$dqb
;
protected
function
setUp
():
void
{
$this
->
db
=
new
DatabaseTestHelper
(
__CLASS__
.
'::'
.
$this
->
getName
()
);
$this
->
dqb
=
$this
->
db
->
newDeleteQueryBuilder
();
}
private
function
assertSQL
(
$expected
,
$fname
)
{
$this
->
dqb
->
caller
(
$fname
)->
execute
();
$actual
=
$this
->
db
->
getLastSqls
();
$actual
=
preg_replace
(
'/ +/'
,
' '
,
$actual
);
$actual
=
rtrim
(
$actual
,
" "
);
$this
->
assertEquals
(
$expected
,
$actual
);
}
public
function
testCondsEtc
()
{
$this
->
dqb
->
table
(
'a'
)
->
where
(
'1'
)
->
andWhere
(
'2'
)
->
conds
(
'3'
);
$this
->
assertSQL
(
'DELETE FROM a WHERE (1) AND (2) AND (3)'
,
__METHOD__
);
}
public
function
testConflictingConds
()
{
$this
->
dqb
->
deleteFrom
(
'1'
)
->
where
(
[
'k'
=>
'v1'
]
)
->
andWhere
(
[
'k'
=>
'v2'
]
);
$this
->
assertSQL
(
'DELETE FROM 1 WHERE k =
\'
v1
\'
AND (k =
\'
v2
\'
)'
,
__METHOD__
);
}
public
function
testCondsAllRows
()
{
$this
->
dqb
->
table
(
'a'
)
->
where
(
ISQLPlatform
::
ALL_ROWS
);
$this
->
assertSQL
(
'DELETE FROM a'
,
__METHOD__
);
}
public
function
testExecute
()
{
$this
->
dqb
->
deleteFrom
(
't'
)->
where
(
'c'
)->
caller
(
__METHOD__
);
$this
->
dqb
->
execute
();
$this
->
assertEquals
(
'DELETE FROM t WHERE (c)'
,
$this
->
db
->
getLastSqls
()
);
}
public
function
testGetQueryInfo
()
{
$this
->
dqb
->
deleteFrom
(
't'
)
->
where
(
[
'a'
=>
'b'
]
)
->
caller
(
'foo'
);
$this
->
assertEquals
(
[
'table'
=>
't'
,
'conds'
=>
[
'a'
=>
'b'
],
'caller'
=>
'foo'
,
],
$this
->
dqb
->
getQueryInfo
()
);
}
public
function
testQueryInfo
()
{
$this
->
dqb
->
queryInfo
(
[
'table'
=>
't'
,
'conds'
=>
[
'a'
=>
'b'
],
]
);
$this
->
assertSQL
(
"DELETE FROM t WHERE a = 'b'"
,
__METHOD__
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 23:54 (1 d, 21 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
59/47/4fdbfb0476f65bc3075a0872a148
Default Alt Text
DeleteQueryBuilderTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment