View source
<?php
namespace Drupal\system\Tests\Database;
class TaggingTest extends DatabaseTestBase {
function testHasTag() {
$query = db_select('test');
$query
->addField('test', 'name');
$query
->addField('test', 'age', 'age');
$query
->addTag('test');
$this
->assertTrue($query
->hasTag('test'), 'hasTag() returned true.');
$this
->assertFalse($query
->hasTag('other'), 'hasTag() returned false.');
}
function testHasAllTags() {
$query = db_select('test');
$query
->addField('test', 'name');
$query
->addField('test', 'age', 'age');
$query
->addTag('test');
$query
->addTag('other');
$this
->assertTrue($query
->hasAllTags('test', 'other'), 'hasAllTags() returned true.');
$this
->assertFalse($query
->hasAllTags('test', 'stuff'), 'hasAllTags() returned false.');
}
function testHasAnyTag() {
$query = db_select('test');
$query
->addField('test', 'name');
$query
->addField('test', 'age', 'age');
$query
->addTag('test');
$this
->assertTrue($query
->hasAnyTag('test', 'other'), 'hasAnyTag() returned true.');
$this
->assertFalse($query
->hasAnyTag('other', 'stuff'), 'hasAnyTag() returned false.');
}
function testExtenderHasTag() {
$query = db_select('test')
->extend('Drupal\\Core\\Database\\Query\\SelectExtender');
$query
->addField('test', 'name');
$query
->addField('test', 'age', 'age');
$query
->addTag('test');
$this
->assertTrue($query
->hasTag('test'), 'hasTag() returned true.');
$this
->assertFalse($query
->hasTag('other'), 'hasTag() returned false.');
}
function testExtenderHasAllTags() {
$query = db_select('test')
->extend('Drupal\\Core\\Database\\Query\\SelectExtender');
$query
->addField('test', 'name');
$query
->addField('test', 'age', 'age');
$query
->addTag('test');
$query
->addTag('other');
$this
->assertTrue($query
->hasAllTags('test', 'other'), 'hasAllTags() returned true.');
$this
->assertFalse($query
->hasAllTags('test', 'stuff'), 'hasAllTags() returned false.');
}
function testExtenderHasAnyTag() {
$query = db_select('test')
->extend('Drupal\\Core\\Database\\Query\\SelectExtender');
$query
->addField('test', 'name');
$query
->addField('test', 'age', 'age');
$query
->addTag('test');
$this
->assertTrue($query
->hasAnyTag('test', 'other'), 'hasAnyTag() returned true.');
$this
->assertFalse($query
->hasAnyTag('other', 'stuff'), 'hasAnyTag() returned false.');
}
function testMetaData() {
$query = db_select('test');
$query
->addField('test', 'name');
$query
->addField('test', 'age', 'age');
$data = array(
'a' => 'A',
'b' => 'B',
);
$query
->addMetaData('test', $data);
$return = $query
->getMetaData('test');
$this
->assertEqual($data, $return, 'Correct metadata returned.');
$return = $query
->getMetaData('nothere');
$this
->assertNull($return, 'Non-existent key returned NULL.');
}
}