Skip to content

Commit aea0372

Browse files
authored
Merge pull request #498 from Boegie/474
Fixes #474
2 parents cc5b129 + c2bd846 commit aea0372

File tree

4 files changed

+132
-4
lines changed

4 files changed

+132
-4
lines changed

src/Type/EntityStorage/GetQueryReturnTypeExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public function getClass(): string
2525

2626
public function isMethodSupported(MethodReflection $methodReflection): bool
2727
{
28-
return $methodReflection->getName() === 'getQuery';
28+
return in_array($methodReflection->getName(), [
29+
'getQuery',
30+
'getAggregateQuery',
31+
], true);
2932
}
3033

3134
public function getTypeFromMethodCall(

tests/src/Rules/EntityParameterTypehintRuleTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ final class EntityParameterTypehintRuleTest extends DrupalRuleTestCase
1111
{
1212
protected function getRule(): Rule
1313
{
14-
$broker = $this->createReflectionProvider();
1514
// @phpstan-ignore-next-line
16-
return new MissingFunctionParameterTypehintRule(new MissingTypehintCheck($broker, true, true, true, true, []));
15+
return new MissingFunctionParameterTypehintRule(
16+
// @phpstan-ignore-next-line
17+
new MissingTypehintCheck(
18+
true,
19+
true,
20+
true,
21+
true,
22+
[]
23+
));
1724
}
1825

1926
public function testRule(): void

tests/src/Rules/EntityQueryHasAccessCheckRuleTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,21 @@ public function cases(): \Generator
8686
[__DIR__ . '/data/bug-437.php'],
8787
[]
8888
];*/
89-
89+
yield 'bug-474.php' => [
90+
[__DIR__ . '/data/bug-474.php'],
91+
[
92+
[
93+
'Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or FALSE to specify whether access should be checked.',
94+
49,
95+
'See https://www.drupal.org/node/3201242',
96+
],
97+
[
98+
'Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or FALSE to specify whether access should be checked.',
99+
98,
100+
'See https://www.drupal.org/node/3201242',
101+
],
102+
]
103+
];
90104
yield 'bug-475.php' => [
91105
[__DIR__.'/data/bug-475.php'],
92106
[]

tests/src/Rules/data/bug-474.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace Bug474;
4+
5+
class TestClass {
6+
7+
/**
8+
* Tests entity queries using getAggregateQuery with access check.
9+
*/
10+
function bug474(): void
11+
{
12+
\Drupal::entityTypeManager()->getStorage('node')
13+
->getAggregateQuery()
14+
->accessCheck(FALSE)
15+
->condition('field_test', 'foo', '=')
16+
->execute();
17+
18+
\Drupal::entityTypeManager()->getStorage('node')
19+
->getAggregateQuery()
20+
->accessCheck(FALSE)
21+
->condition('field_test', 'foo', '=')
22+
->execute();
23+
24+
\Drupal::entityTypeManager()->getStorage('node')
25+
->getAggregateQuery()
26+
->condition('field_test', 'foo', '=')
27+
->accessCheck(TRUE)
28+
->execute();
29+
30+
\Drupal::entityTypeManager()->getStorage('node')
31+
->getAggregateQuery()
32+
->accessCheck(TRUE)
33+
->condition('field_test', 'foo', '=')
34+
->execute();
35+
36+
\Drupal::entityTypeManager()->getStorage('node')
37+
->getAggregateQuery()
38+
->condition('field_test', 'foo', '=')
39+
->accessCheck()
40+
->execute();
41+
42+
\Drupal::entityTypeManager()->getStorage('node')
43+
->getAggregateQuery()
44+
->accessCheck()
45+
->condition('field_test', 'foo', '=')
46+
->execute();
47+
48+
// Failing test due to missing accessCheck.
49+
\Drupal::entityTypeManager()->getStorage('node')
50+
->getAggregateQuery()
51+
->condition('field_test', 'foo', '=')
52+
->execute();
53+
54+
// Same tests but now with count() chained as well.
55+
\Drupal::entityTypeManager()->getStorage('node')
56+
->getAggregateQuery()
57+
->accessCheck(FALSE)
58+
->condition('field_test', 'foo', '=')
59+
->count()
60+
->execute();
61+
62+
\Drupal::entityTypeManager()->getStorage('node')
63+
->getAggregateQuery()
64+
->count()
65+
->accessCheck(FALSE)
66+
->condition('field_test', 'foo', '=')
67+
->execute();
68+
69+
\Drupal::entityTypeManager()->getStorage('node')
70+
->getAggregateQuery()
71+
->condition('field_test', 'foo', '=')
72+
->accessCheck(TRUE)
73+
->count()
74+
->execute();
75+
76+
\Drupal::entityTypeManager()->getStorage('node')
77+
->getAggregateQuery()
78+
->count()
79+
->accessCheck(TRUE)
80+
->condition('field_test', 'foo', '=')
81+
->execute();
82+
83+
\Drupal::entityTypeManager()->getStorage('node')
84+
->getAggregateQuery()
85+
->condition('field_test', 'foo', '=')
86+
->accessCheck()
87+
->count()
88+
->execute();
89+
90+
\Drupal::entityTypeManager()->getStorage('node')
91+
->getAggregateQuery()
92+
->count()
93+
->accessCheck()
94+
->condition('field_test', 'foo', '=')
95+
->execute();
96+
97+
// Failing test due to missing accessCheck.
98+
\Drupal::entityTypeManager()->getStorage('node')
99+
->getAggregateQuery()
100+
->condition('field_test', 'foo', '=')
101+
->count()
102+
->execute();
103+
}
104+
}

0 commit comments

Comments
 (0)