diff --git a/.travis.yml b/.travis.yml index 720d5bd..90f4af1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,36 +13,26 @@ mysql: jobs: include: - # PHP 7.3 + - name: 'PHPCodeSniffer' - php: 7.3 + php: 7.4 env: TEST_SUITE=PHPCodeSniffer - name: 'PHPStan' - php: 7.3 - 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 - env: TEST_SUITE=PHPUnit DRUPAL=^8.9 PHPUNIT=^7 + env: TEST_SUITE=PHPStan DRUPAL=~8.9.20 PHPUNIT=^7 - 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: 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 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, 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); } }