diff --git a/core/lib/Drupal/Core/Entity/Query/ConditionFundamentals.php b/core/lib/Drupal/Core/Entity/Query/ConditionFundamentals.php index d03e2b2e8109499a10f2a08033cb1f426ac1f151..6de10bf3542fae179bf41b7e3f649d4caea20208 100644 --- a/core/lib/Drupal/Core/Entity/Query/ConditionFundamentals.php +++ b/core/lib/Drupal/Core/Entity/Query/ConditionFundamentals.php @@ -65,7 +65,7 @@ public function getConjunction() { * {@inheritdoc} */ public function count() { - return count($this->conditions) - 1; + return count($this->conditions); } /** diff --git a/core/lib/Drupal/Core/Entity/Query/ConditionInterface.php b/core/lib/Drupal/Core/Entity/Query/ConditionInterface.php index 7657c006c31be43fe6f75269d789a81e54dc8d81..bf53a92c2c449ae2d6648133f65e758c38d7c17b 100644 --- a/core/lib/Drupal/Core/Entity/Query/ConditionInterface.php +++ b/core/lib/Drupal/Core/Entity/Query/ConditionInterface.php @@ -19,8 +19,7 @@ public function getConjunction(); * 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(); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php index 2c9b86826d761f1a283237022199edc966f076bc..a47d9a9a6f9ad0481d6e793e5544c1e3256019df 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php @@ -556,6 +556,31 @@ public function testNestedConditionGroups() { $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. */