Closed philippemouchel closed 2 years ago
Hi, @philippemouchel. Definitely!
Simply subclass ContentModelContext
and override getContentEntityTypes()
with your customizations. Then update your Behat configuration to use your context instead of the Spec Tool's, e.g.:
# behat.yml
default:
suites:
default:
contexts:
- - Acquia\DrupalSpecTool\Context\ContentModelContext
+ - AcmeCorp\MyContentModelContext
As to custom entity types, as long as they implement \Drupal\Core\Entity\ContentEntityInterface
you should be fine to add basic support for them in the same place. But I haven't investigated that, and there are bound to be unanticipated effects of including them. Good luck! π
If you're looking for something more flexible for reuse across projects, or if you're interested in contributing to the Spec Tool itself, we could make the content entity types list configurable in behat.yml
. Alternatively, we could just dynamically get all defined entity types that implement ContentEntityInterface
--if that would even be desirable. If you're interested in working on something like that I may be able to give you some pointers. π
Hello! In my content_model.feature file I have the following line:
| Article (Content type) | Image | field_image | Entity reference | Required | 1 | Entity browser | | |
In the system I have implemented the field in question.
Running the test I get the following error message:
--- Missing fields (present in specification, absent from Drupal)
| Article (Content type) | Image | field_image | Entity reference | Required | 1 | Entity browser | | | (TravisCarden\BehatTableComparison\UnequalTablesException)
Usually if there is something wrong with the test I can see the field in the unexpected fields list. The system appears to be unable to detect this type of field. The same thing happens with users.
In my project I also used commerce and I solved the problem by modifying the getContentEntityTypes () method as shown by philippemouchel. My system shows the error message posted below when I add the following ids in the array: 'commerce_log', 'commerce_payment_method''commerce_payment',
**The "" entity type does not exist. (Drupal\Component\Plugin\Exception\PluginNotFoundException)**
The same error occurs when I add the to the array the 'user' id in an attempt to identify system users to conduct tests.
How is it possible to resolve the situation so that we can test for the entity reference Image and for the users?
Thank you for your kind attention and for the time dedicated. I wish you a good day.
@mgreco-n can you post a complete diff of the changes you made that you describe above?
@TravisCarden I'm using a modified version of the patch suggested by philippemouchel.
The content_model test run correctly for commerce entities or feeds, but If I had the "user" I get too the following error.
The "" entity type does not exist. (Drupal\Component\Plugin\Exception\PluginNotFoundException)
Index: vendor/acquia/drupal-spec-tool/src/Context/ContentModelContext.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/vendor/acquia/drupal-spec-tool/src/Context/ContentModelContext.php b/vendor/acquia/drupal-spec-tool/src/Context/ContentModelContext.php
--- a/vendor/acquia/drupal-spec-tool/src/Context/ContentModelContext.php
+++ b/vendor/acquia/drupal-spec-tool/src/Context/ContentModelContext.php (date 1649768110404)
@@ -171,13 +171,32 @@
* An array of entity types.
*/
protected function getContentEntityTypes() {
+ // $ids = [
+ // 'block_content',
+ // 'media',
+ // 'node',
+ // 'paragraph',
+ // 'taxonomy_term',
+ // ];
+
$ids = [
'block_content',
+ 'commerce_order',
+ 'commerce_order_item',
+ 'commerce_product',
+ 'commerce_product_attribute_value',
+ 'commerce_product_variation',
+ 'commerce_promotion',
+ 'commerce_promotion_coupon',
+ 'commerce_store',
+ 'feeds_feed',
+ 'user',
'media',
'node',
'paragraph',
'taxonomy_term',
];
+
$entity_types = [];
foreach ($ids as $id) {
try {
@Peppe87 are you trying to add support for user roles? That would be user_role
, and there's another issue to (finish) adding support for them: https://github.com/acquia/drupal-spec-tool/issues/20.
No, just to check fields on user entity.
Oh... Now that you mention it, I remember looking at that ages ago, and as I recall user entities have a different API from other kinds. Why don't you create an issue for adding support for them and link to it here?
I think this issue has been resolved, so I'm closing it. Re-open it if I'm mistaken.
Hi there.
I'm currently using this drupal-spec-tool on a Drupal Commerce site (D9 and DC2), and I had to edit ContentModelContext file to get Behat to acknowledge Drupal Commerce entities. Here is the patch.
Any elegant way to do that ? How about custom entities ?