public function ConditionTest::testNestedConditions in Drupal driver for SQL Server and SQL Azure 4.2.x
Same name and namespace in other branches
- 8.2 tests/src/Kernel/ConditionTest.php \Drupal\Tests\sqlsrv\Kernel\ConditionTest::testNestedConditions()
- 3.0.x tests/src/Kernel/ConditionTest.php \Drupal\Tests\sqlsrv\Kernel\ConditionTest::testNestedConditions()
- 3.1.x tests/src/Kernel/ConditionTest.php \Drupal\Tests\sqlsrv\Kernel\ConditionTest::testNestedConditions()
- 4.0.x tests/src/Kernel/ConditionTest.php \Drupal\Tests\sqlsrv\Kernel\ConditionTest::testNestedConditions()
- 4.1.x tests/src/Kernel/ConditionTest.php \Drupal\Tests\sqlsrv\Kernel\ConditionTest::testNestedConditions()
Confirms that we can properly nest custom conditional clauses.
File
- tests/
src/ Kernel/ ConditionTest.php, line 21
Class
- ConditionTest
- Test the functions of the custom Condition class.
Namespace
Drupal\Tests\sqlsrv\KernelCode
public function testNestedConditions() {
// This query should translate to:
// SELECT job FROM {test} WHERE name='Paul' AND (name REGEX '^P' OR age=27)
// That should find only one record. Yes it's a non-optimal way of writing
// that query but that's not the point!
$query = $this->connection
->select('test');
$query
->addField('test', 'job');
$query
->condition('name', 'Paul');
$query
->condition($this->connection
->condition('OR')
->condition('name', '^P', 'REGEXP')
->condition('age', '27'));
$job = $query
->execute()
->fetchField();
$this
->assertEquals($job, 'Songwriter', 'Correct data retrieved.');
}