From cee38d9c9cc64e9993b9b2ee4d4bae2938fc34f4 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Thu, 25 Nov 2021 18:50:27 +0100 Subject: [PATCH 1/5] ISAICP-6720: Handle field_name.entity case in entity query. --- src/Entity/Query/Sparql/Query.php | 2 +- src/Entity/Query/Sparql/SparqlCondition.php | 30 ++++++++++----------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Entity/Query/Sparql/Query.php b/src/Entity/Query/Sparql/Query.php index 576d178..9f842cd 100644 --- a/src/Entity/Query/Sparql/Query.php +++ b/src/Entity/Query/Sparql/Query.php @@ -404,7 +404,7 @@ public function conditionAggregateGroupFactory($conjunction = 'AND') { */ protected function conditionGroupFactory($conjunction = 'AND') { $class = static::getClass($this->namespaces, 'SparqlCondition'); - return new $class($conjunction, $this, $this->namespaces, $this->graphHandler, $this->fieldHandler, $this->languageManager); + return new $class($conjunction, $this, $this->namespaces, $this->fieldHandler, $this->languageManager); } /** diff --git a/src/Entity/Query/Sparql/SparqlCondition.php b/src/Entity/Query/Sparql/SparqlCondition.php index 2913460..ad7fc93 100644 --- a/src/Entity/Query/Sparql/SparqlCondition.php +++ b/src/Entity/Query/Sparql/SparqlCondition.php @@ -9,7 +9,6 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\sparql_entity_storage\SparqlEntityStorageFieldHandlerInterface; -use Drupal\sparql_entity_storage\SparqlEntityStorageGraphHandlerInterface; use EasyRdf\Serialiser\Ntriples; /** @@ -17,13 +16,6 @@ */ class SparqlCondition extends ConditionFundamentals implements SparqlConditionInterface { - /** - * The SPARQL graph handler service. - * - * @var \Drupal\sparql_entity_storage\SparqlEntityStorageGraphHandlerInterface - */ - protected $graphHandler; - /** * The SPARQL field mapping handler service. * @@ -152,7 +144,7 @@ class SparqlCondition extends ConditionFundamentals implements SparqlConditionIn * * @var array */ - protected $fieldMappingConditions; + protected $fieldMappingConditions = []; /** * The entity type ID key. @@ -194,25 +186,20 @@ class SparqlCondition extends ConditionFundamentals implements SparqlConditionIn * The entity query this condition belongs to. * @param array $namespaces * List of potential namespaces of the classes belonging to this condition. - * @param \Drupal\sparql_entity_storage\SparqlEntityStorageGraphHandlerInterface $sparql_graph_handler - * The SPARQL graph handler service. * @param \Drupal\sparql_entity_storage\SparqlEntityStorageFieldHandlerInterface $sparql_field_handler * The SPARQL field mapping handler service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager service. */ - public function __construct($conjunction, SparqlQueryInterface $query, array $namespaces, SparqlEntityStorageGraphHandlerInterface $sparql_graph_handler, SparqlEntityStorageFieldHandlerInterface $sparql_field_handler, LanguageManagerInterface $language_manager) { + public function __construct($conjunction, SparqlQueryInterface $query, array $namespaces, SparqlEntityStorageFieldHandlerInterface $sparql_field_handler, LanguageManagerInterface $language_manager) { $conjunction = strtoupper($conjunction); parent::__construct($conjunction, $query, $namespaces); - $this->graphHandler = $sparql_graph_handler; $this->fieldHandler = $sparql_field_handler; $this->languageManager = $language_manager; $this->typePredicate = $query->getEntityStorage()->getBundlePredicates(); $this->bundleKey = $query->getEntityType()->getKey('bundle'); $this->idKey = $query->getEntityType()->getKey('id'); $this->labelKey = $query->getEntityType()->getKey('label'); - // Initialize variable to avoid warnings;. - $this->fieldMappingConditions = []; $this->fieldMappings = [ $this->idKey => self::ID_KEY, $this->bundleKey => count($this->typePredicate) === 1 ? reset($this->typePredicate) : SparqlArg::toVar($this->bundleKey . '_predicate'), @@ -263,7 +250,18 @@ public function condition($field = NULL, $value = NULL, $operator = NULL, $lang if (!$this->fieldHandler->fieldIsMapped($this->query->getEntityTypeId(), $field)) { return $this; } - $column = isset($field_name_parts[1]) ? $field_name_parts[1] : $this->fieldHandler->getFieldMainProperty($this->query->getEntityTypeId(), $field); + + if (isset($field_name_parts[1])) { + // The 'entity' column designates an entity reference. + // @see \Drupal\Core\Entity\Query\QueryInterface::condition() + // @todo Handle more complex column representations, such as + // 'tags.entity.name' or tags.entity:taxonomy_term.name'. + $column = $field_name_parts[1] === 'entity' ? 'target_id' : $field_name_parts[1]; + } + else { + $column = $this->fieldHandler->getFieldMainProperty($this->query->getEntityTypeId(), $field); + } + $this->conditions[] = [ 'field' => $field, 'value' => $value, From 690bfd9d68859276da0c894e0c25d4e17192c830 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Thu, 25 Nov 2021 19:27:28 +0100 Subject: [PATCH 2/5] ISAICP-6720: Test coverage. --- tests/src/Kernel/SparqlEntityQueryTest.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/src/Kernel/SparqlEntityQueryTest.php b/tests/src/Kernel/SparqlEntityQueryTest.php index 29fec6e..17733c8 100644 --- a/tests/src/Kernel/SparqlEntityQueryTest.php +++ b/tests/src/Kernel/SparqlEntityQueryTest.php @@ -70,6 +70,17 @@ protected function setUp(): void { } } + /** + * Tests that the case field_ref.entity is handled. + */ + public function testEntityColumns(): void { + $ids = array_keys($this->getQuery()->condition('reference.entity', $this->entities[1]->id())->execute()); + $this->assertSame([ + 'http://vegetable.example.com/004', + 'http://vegetable.example.com/009', + ], $ids); + } + /** * Tests basic functionality related to Id and bundle filtering. */ @@ -635,7 +646,8 @@ protected function getTestEntityValues() { protected function getQuery(string $operator = 'AND'): SparqlQueryInterface { return $this->container->get('entity_type.manager') ->getStorage('sparql_test') - ->getQuery($operator); + ->getQuery($operator) + ->accessCheck(FALSE); } } From 1e99b2a4c12d3210e9b2503f4e6dcf5d5a2325de Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Thu, 25 Nov 2021 21:39:02 +0100 Subject: [PATCH 3/5] ISAICP-6720: Try to fix tests. --- .travis.yml | 14 +++----------- composer.json | 1 + phpstan.neon | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 720d5bd..d6b72b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,23 +13,15 @@ mysql: jobs: include: - # PHP 7.3 + # PHP 7.4 - name: 'PHPCodeSniffer' - php: 7.3 + php: 7.4 env: TEST_SUITE=PHPCodeSniffer - name: 'PHPStan' - php: 7.3 + php: 7.4 env: TEST_SUITE=PHPStan DRUPAL=~8.9.0 PHPUNIT=^7 - - name: 'PHPUnit with Drupal 8 on PHP 7.3' - php: 7.3 - env: TEST_SUITE=PHPUnit DRUPAL=^8.9 PHPUNIT=^7 - - - name: 'PHPUnit with Drupal 9 on PHP 7.3' - php: 7.3 - env: TEST_SUITE=PHPUnit DRUPAL=^9.1 PHPUNIT=^9 - # PHP 7.4 - name: 'PHPUnit with Drupal 8 on PHP 7.4' php: 7.4 diff --git a/composer.json b/composer.json index 47cc511..ab5b699 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "ml/json-ld": "^1.0" }, "require-dev": { + "behat/mink": "~1.9.0", "composer/installers": "^1.7", "drupal/coder": "^8.3", "drupal/core": "^8.9 || ^9.1", diff --git a/phpstan.neon b/phpstan.neon index 218cabc..4144b48 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ parameters: customRulesetUsed: true reportUnmatchedIgnoredErrors: false - excludes_analyse: + excludePaths: - ../testing_site/modules/sparql_entity_storage/vendor includes: - vendor/mglaman/phpstan-drupal/extension.neon From 01f86d4d274d50754cc647e3612fd425ce71c8c9 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Thu, 25 Nov 2021 21:43:13 +0100 Subject: [PATCH 4/5] ISAICP-6720: More fixing. --- .travis.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index d6b72b0..e01c5c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,28 +13,26 @@ mysql: jobs: include: - # PHP 7.4 + - name: 'PHPCodeSniffer' php: 7.4 env: TEST_SUITE=PHPCodeSniffer - name: 'PHPStan' php: 7.4 - env: TEST_SUITE=PHPStan DRUPAL=~8.9.0 PHPUNIT=^7 - - # PHP 7.4 - - name: 'PHPUnit with Drupal 8 on PHP 7.4' - php: 7.4 - env: TEST_SUITE=PHPUnit DRUPAL=^8.9 PHPUNIT=^7 + env: TEST_SUITE=PHPStan DRUPAL=^9.2 PHPUNIT=^9 - name: 'PHPUnit with Drupal 9 on PHP 7.4' php: 7.4 - env: TEST_SUITE=PHPUnit DRUPAL=^9.1 PHPUNIT=^9 + env: TEST_SUITE=PHPUnit DRUPAL=^9.2 PHPUNIT=^9 + + - name: 'PHPUnit with Drupal 9 on PHP 8.0' + php: 8.0 + env: TEST_SUITE=PHPUnit DRUPAL=^9.2 PHPUNIT=^9 - # PHP 8 - name: 'PHPUnit with Drupal 9 on PHP 8 nightly' php: nightly - env: TEST_SUITE=PHPUnit DRUPAL=^9.1 PHPUNIT=^9 + env: TEST_SUITE=PHPUnit DRUPAL=^9.2 PHPUNIT=^9 cache: directories: From f552ad21e84fc8f55ac7e3328fdad77634c32e25 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Thu, 25 Nov 2021 21:48:12 +0100 Subject: [PATCH 5/5] ISAICP-6720: Still accept usage of deprecated Symfony event. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e01c5c9..90f4af1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ jobs: - name: 'PHPStan' php: 7.4 - env: TEST_SUITE=PHPStan DRUPAL=^9.2 PHPUNIT=^9 + env: TEST_SUITE=PHPStan DRUPAL=~8.9.20 PHPUNIT=^7 - name: 'PHPUnit with Drupal 9 on PHP 7.4' php: 7.4