Issue #2961285 by pavlosdan, hchonov, borisson_: Entity query condition count is faulty

8.7.x
Alex Pott 2018-08-07 15:48:44 +01:00
parent c9159d8633
commit a4208fd3c8
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
3 changed files with 27 additions and 3 deletions

View File

@ -65,7 +65,7 @@ abstract class ConditionFundamentals {
* {@inheritdoc}
*/
public function count() {
return count($this->conditions) - 1;
return count($this->conditions);
}
/**

View File

@ -19,8 +19,7 @@ interface ConditionInterface {
* Implements \Countable::count().
*
* Returns the size of this conditional. The size of the conditional is the
* size of its conditional array minus one, because one element is the
* conjunction.
* size of its conditional array.
*/
public function count();

View File

@ -556,6 +556,31 @@ class EntityQueryTest extends EntityKernelTestBase {
$this->assertResult(4, 6, 12, 14);
}
/**
* Tests that condition count returns expected number of conditions.
*/
public function testConditionCount() {
// Query for all entities of the first bundle that
// have red as a colour AND are triangle shaped.
$query = $this->storage->getQuery();
// Add an AND condition group with 2 conditions in it.
$and_condition_group = $query->andConditionGroup()
->condition($this->figures . '.color', 'red')
->condition($this->figures . '.shape', 'triangle');
// We added 2 conditions so count should be 2.
$this->assertEqual($and_condition_group->count(), 2);
// Add an OR condition group with 2 conditions in it.
$or_condition_group = $query->orConditionGroup()
->condition($this->figures . '.color', 'red')
->condition($this->figures . '.shape', 'triangle');
// We added 2 conditions so count should be 2.
$this->assertEqual($or_condition_group->count(), 2);
}
/**
* Test queries with delta conditions.
*/