diff options
author | Antoine Musso <hashar@users.mediawiki.org> | 2011-05-13 15:39:45 +0000 |
---|---|---|
committer | Antoine Musso <hashar@users.mediawiki.org> | 2011-05-13 15:39:45 +0000 |
commit | ba564eeb7c73c409e3cbd1063c2ac350d6a7e360 (patch) | |
tree | e7dedda27bfc05523618490dbeee086ab857aa1c /tests/phpunit/includes/db/DatabaseTest.php | |
parent | 7e4d49b9bcd5cb585272eca0b3ba18d71787db42 (diff) | |
download | mediawikicore-ba564eeb7c73c409e3cbd1063c2ac350d6a7e360.tar.gz mediawikicore-ba564eeb7c73c409e3cbd1063c2ac350d6a7e360.zip |
Support abstraction for 'NOT IN' SQL structure
Following a live discussion with Catrope.
When using Database::makeList() in LIST_AND or LIST_OR modes, you can now
suffix the field name with an exclamation mark. It will negate the logical
boolean.
Example:
$db->makeList( array( 'field!' => array( 1,2,3 ) );
outputs:
'field' NOT IN ('1', '2', '3' );
$db->makeList( array( 'foo!' => array( 777 ) ) );
outputs:
'foo' =! 777
(note: tests not ran, please run them and ammend them)
Notes
Notes:
http://mediawiki.org/wiki/Special:Code/MediaWiki/87992
Diffstat (limited to 'tests/phpunit/includes/db/DatabaseTest.php')
-rw-r--r-- | tests/phpunit/includes/db/DatabaseTest.php | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/phpunit/includes/db/DatabaseTest.php b/tests/phpunit/includes/db/DatabaseTest.php index 7357524f28d2..5fac8dceef23 100644 --- a/tests/phpunit/includes/db/DatabaseTest.php +++ b/tests/phpunit/includes/db/DatabaseTest.php @@ -90,6 +90,34 @@ class DatabaseTest extends MediaWikiTestCase { $sql ); } + function testMakeNotInList() { + $this->assertEquals( + $this->db->makeList( array( + 'field' => array( 0, 1 ) + ) ), + "field IN ('0','1')" + ); + $this->assertEquals( + $this->db->makeList( array( + 'field!' => array( 0, 1 ) + ) ), + "field NOT IN ('0','1')" + ); + + // make sure an array with only one value use = or != + $this->assertEquals( + $this->db->makeList( array( + 'field' => array( 777 ) + ) ), + "field = 777" + ); + $this->assertEquals( + $this->db->makeList( array( + 'field!' => array( 888 ) + ) ), + "field != 888" + ); + } } |