Problem/Motivation

Easyrdf is only used in tests and doesn't support php 7.4
It looks like its no longer maintained

Proposed resolution

Move all the code that is dependent on the EasyRDF to a single trait to make refactoring to not use it simpler.

Remaining tasks

User interface changes

None

API changes

New trait

Data model changes

None

Release notes snippet

CommentFileSizeAuthor
#36 3090017-36.patch59.15 KBalexpott
#36 27-36-interdiff.txt40.68 KBalexpott
#24 3090017-easyrdf-do-not-test-24.patch60.61 KBlarowlan
#24 interdiff-fdfe0a.txt2.39 KBlarowlan
#20 3090017-19.patch59.23 KBlarowlan
#20 interdiff-35e5b2.txt818 byteslarowlan
#20 interdiff-3ee902.txt5.75 KBlarowlan
#18 3090017-easyrdf-9x-18.patch58.19 KBamjad1233
#18 3090017-easyrdf-9x-interdiff_3_18_RdfParsingTrait.txt2.33 KBamjad1233
#18 3090017-easyrdf-9x-interdiff_3_18_FieldRdfaTestBase.txt1.58 KBamjad1233
#18 3090017-easyrdf-9x-interdiff_3_18_StandardProfileTest.txt17.94 KBamjad1233
#3 3090017-easyrdf-9x.patch15.63 KBlarowlan
#8 3090017-easyrdf-9x-interdiff_3_8.txt5.8 KBamjad1233
#8 3090017-easyrdf-9x-8.patch21.43 KBamjad1233
#12 3090017-easyrdf-9x-interdiff_3_12_EntityReferenceFieldAttributeTest.txt2.87 KBamjad1233
#12 3090017-easyrdf-9x-interdiff_3_12_FileFieldAttributeTest.txt2.44 KBamjad1233
#12 3090017-easyrdf-9x-interdiff_3_12_ImageFieldAttributeTest.txt3 KBamjad1233
#12 3090017-easyrdf-9x-interdiff_3_12_NodeAttributeTest.txt4.64 KBamjad1233
#12 3090017-easyrdf-9x-interdiff_3_12_StandardProfileTest.txt16.12 KBamjad1233
#12 3090017-easyrdf-9x-interdiff_3_12_TaxonomyAttributeTest.txt3.62 KBamjad1233
#12 3090017-easyrdf-9x-interdiff_3_12_UserAttributesTest.txt4.69 KBamjad1233
#12 3090017-easyrdf-9x-interdiff_3_12_RdfParsingTrait.txt1.47 KBamjad1233
#12 3090017-easyrdf-9x-interdiff_3_12_FieldRdfaTestBase.txt1.14 KBamjad1233
#12 3090017-easyrdf-9x-12.patch55.07 KBamjad1233

Comments

larowlan created an issue. See original summary.

andypost’s picture

The PR to fix compatibility https://github.com/njh/easyrdf/pull/311

larowlan’s picture

Status: Active » Needs review
Issue tags: +Novice
StatusFileSize
new15.63 KB

First step is to isolate calls to EasyRdf into a trait then we can chop from a single spot.

Here's a POC and a crack at converting CommentAttributesTest

Still to go:

  • EntityReferenceFieldAttributesTest.php (2 usages found)
  • FileFieldAttributesTest.php (1 usage found)
  • ImageFieldAttributesTest.php (2 usages found)
  • NodeAttributesTest.php (5 usages found)
  • StandardProfileTest.php (17 usages found)
  • TaxonomyAttributesTest.php (3 usages found)
  • UserAttributesTest.php (4 usages found)
  • FieldRdfaTestBase.php (1 usage found)
amjad1233’s picture

Assigned: Unassigned » amjad1233
mondrake’s picture

Issue tags: +PHP 7.4
mondrake’s picture

mondrake’s picture

Would be great to backport to 8.8.x to allow testing on PHP 7.4 without the workarounds @alexpott devised in #3086374-79: Make Drupal 8 & 9 compatible with PHP 7.4

amjad1233’s picture

@larowlan I am bit confused here.

Should I paste the interdiff to your patch or I should create a whole new patch?

Meanwhile, I have knocked out the easy one for NodeAttributes. I am up to Taxonomy ones.

larowlan’s picture

@amjad both, which you did 👍

larowlan’s picture

+++ b/core/modules/rdf/tests/src/Functional/NodeAttributesTest.php
@@ -19,9 +22,37 @@ class NodeAttributesTest extends NodeTestBase {
+  /**
+   * URI of the front page of the Drupal site.
+   *
+   * @var string
+   */
+  protected $baseUri;
+
+  /**
+   * Node for testing.
+   *
+   * @var \Drupal\node\Entity\Node
+   */
+  protected $node;
+
+  /**
+   * URI of the test node created by CommentTestBase::setUp().
+   *
+   * @var string
+   */
+  protected $nodeUri;
...
+    // Create node with single quotation mark title to ensure it does not get
+    // escaped more than once.
+    $this->node = $this->drupalCreateNode([
+      'type' => 'article',
+      'title' => $this->randomMachineName(8) . "'",
+    ]);
+

@@ -35,61 +66,51 @@ protected function setUp() {
+    // Prepares commonly used URIs.
+    $this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
+    $this->nodeUri = $this->node->toUrl('canonical', ['absolute' => TRUE])->toString();
...
-    // Create node with single quotation mark title to ensure it does not get
-    // escaped more than once.
-    $node = $this->drupalCreateNode([
-      'type' => 'article',
-      'title' => $this->randomMachineName(8) . "'",
-    ]);
-
-    $node_uri = $node->toUrl('canonical', ['absolute' => TRUE])->toString();
-    $base_uri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
-
-    // Parses front page where the node is displayed in its teaser form.
-    $parser = new \EasyRdf_Parser_Rdfa();
-    $graph = new \EasyRdf_Graph();
-    $parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri);
 

I don't think we need these changes, we can just keep the local variables in this test.

The class properties already existed in the Comment test, that's why I used them.

amjad1233’s picture

Cool. I will make that change and upload other ones as well soon. Almost finished with *Entity+Field*Attributes.

amjad1233’s picture

Hi @larowlan,

Here are the new patches with interdiffs for each individual test. Hopefully, it will make reviewing easy for you.

Need your special attention to FieldRdfaTestBase as I was bit nervous.

Happy Reviewing :-)

larowlan’s picture

  1. geez, FieldRdfaTestBase is a weird one, it looks like leftover debugging code, I think we should just do the following:
    
        $expected_rdf_value += ['type' => 'literal'];
    
        // The field formatter will be rendered inside the entity. Set the field
        // formatter in the entity display options before rendering the entity.
        \Drupal::service('entity_display.repository')
          ->getViewDisplay('entity_test', 'entity_test')
          ->setComponent($this->fieldName, $formatter)
          ->save();
        $build = \Drupal::entityTypeManager()
          ->getViewBuilder($this->entity->getEntityTypeId())
          ->view($this->entity, 'default');
        $output = \Drupal::service('renderer')->renderRoot($build);
    
        $this->assertTrue($this->hasRdfProperty($output, $this->uri,  $this->uri, $property, $expected_rdf_value), "Formatter {$formatter['type']} exposes data correctly for {$this->fieldType} fields.");
    
    

    and remove the $debug class property.

    what do you think @mondrake @andypost

  2. +++ b/core/modules/rdf/tests/src/Functional/CommentAttributesTest.php
    @@ -307,17 +291,12 @@ public function _testBasicCommentRdfaMarkup($graph, CommentInterface $comment, $
    +      $author_uri = $this->getRdfNode($this->getSession()->getPage()->getContent(), $this->baseUri, $comment_uri, '<http://rdfs.org/sioc/ns#has_creator>');
    +      $this->assertTrue($author_uri->isBnode());
    

    thinking about it more, I think the ::isBNode call here (which is from my original patch) is wrong, cause that's easyrdf specific knowledge in the test, we need to keep that internal to the trait, probably a ::rdfElementIsBlank method on the trait

  3. +++ b/core/modules/rdf/tests/src/Functional/StandardProfileTest.php
    @@ -205,10 +208,10 @@ public function testRdfaOutput() {
    +    $this->assertEqual(2, count($this->getRdfGraph(Url::fromRoute('<front>'), $this->baseUri)->allOfType('http://schema.org/Article')), 'Two articles found on front page.');
    

    because we still have an ::allOfType call here, we've still got a coupling to easyrdf - maybe we make the method ::getElementByRdfTypeCount i.e it returns 2 and does the allOfType call for us, keeping that internal to the trait - thoughts?

  4. +++ b/core/modules/rdf/tests/src/Functional/StandardProfileTest.php
    @@ -244,25 +245,27 @@ protected function doFrontPageRdfaTests() {
    +    $this->assertEqual($this->getRdfGraph($this->article->toUrl(),$this->baseUri)->type($this->articleUri), 'schema:Article', 'Article type was found (schema:Article).');
    

    similar here, can we hoist the ::type call up into the trait so the test has no knowledge of easyrdf as a method - e.g. ::getElementRdfType?

  5. +++ b/core/modules/rdf/tests/src/Functional/StandardProfileTest.php
    @@ -281,13 +284,13 @@ protected function doPageRdfaTests() {
    -    $graph = $this->getRdfGraph($this->page->toUrl());
    +    $graph = $this->getRdfGraph($this->page->toUrl(), $this->baseUri);
     
         // Type.
         $this->assertEqual($graph->type($this->pageUri), 'schema:WebPage', 'Page type was found (schema:WebPage).');
    
    @@ -297,7 +300,7 @@ protected function doUserRdfaTests() {
    -    $graph = $this->getRdfGraph($this->adminUser->toUrl());
    +    $graph = $this->getRdfGraph($this->adminUser->toUrl(), $this->baseUri);
     
         // User type.
         $this->assertEqual($graph->type($this->authorUri), 'schema:Person', "User type was found (schema:Person) on user page.");
    
    @@ -317,7 +320,7 @@ protected function doUserRdfaTests() {
    -    $graph = $this->getRdfGraph($this->term->toUrl());
    +    $graph = $this->getRdfGraph($this->term->toUrl(), $this->baseUri);
     
         // Term type.
         $this->assertEqual($graph->type($this->termUri), 'schema:Thing', "Term type was found (schema:Thing) on term page.");
    
    @@ -369,24 +373,24 @@ protected function assertRdfaCommonNodeProperties($graph, NodeInterface $node, $
    -    $this->assertEqual($graph->type($this->authorUri), 'schema:Person', "$message_prefix author type was found (schema:Person).");
    +    $this->assertEqual($this->getRdfGraph($node->toUrl(), $this->baseUri)->type($this->authorUri), 'schema:Person', "$message_prefix author type was found (schema:Person).");
    
    @@ -421,20 +425,19 @@ protected function assertRdfaArticleProperties($graph, $message_prefix) {
    -    $this->assertEqual($graph->type($this->articleCommentUri), 'schema:Comment', 'Comment type was found (schema:Comment).');
    +    $this->assertEqual($this->getRdfGraph($this->article->toUrl(),$this->baseUri)->type($this->articleCommentUri), 'schema:Comment', 'Comment type was found (schema:Comment).');
    
    @@ -462,24 +465,24 @@ protected function assertRdfaNodeCommentProperties($graph) {
    -    $this->assertEqual($graph->type($this->commenterUri), 'schema:Person', 'Comment author type was found (schema:Person).');
    +    $this->assertEqual($this->getRdfGraph($this->article->toUrl(),$this->baseUri)->type($this->commenterUri), 'schema:Person', 'Comment author type was found (schema:Person).');
    

    which we could re-use here too and avoid the ::getRdfGraph calls

    After that I think that means the trait will end up with only these four methods

    - hasRdfProperty
    - getElementByRdfTypeCount
    - getElementRdfType
    - rdfElementIsBlank

Which means we'll have to reimplement those 4 without easyrdf and we're done - thanks for moving this along @amjad

mondrake’s picture

Priority: Normal » Critical

I think this becomes critical as long as easyrdf

It looks like its no longer maintained

mondrake’s picture

@larowlan re #13.1 I cannot judge, sorry

amjad1233’s picture

Cool. Still a bit confused about #13.1, but I reckon others should be trivial I am on it.

@larowlan will wait for your decision on #13.1 meanwhile I will tackle the other four methods.

larowlan’s picture

for 13.1 basically we remove the debug option and just use hasRdfProperty

amjad1233’s picture

Here are the patches as per above comment. We will update the CommnetAttributeTest after we make decisions.

Status: Needs review » Needs work

The last submitted patch, 18: 3090017-easyrdf-9x-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new5.75 KB
new818 bytes
new59.23 KB

I think this isolates all the easyrdf/easyrdf code into the trait

next step is to implement it without easyrdf

looking at the d7 code, it just uses xpath, so that seems like an approach

larowlan’s picture

Then after that, we can follow https://www.drupal.org/node/3089540 to remove easyrdf from composer.lock and core/composer.json

larowlan’s picture

Looking at the original issue where this was introduced, xpath was not sufficient for what we needed, so I guess we simplify and use DomDocument

amjad1233’s picture

Sounds good. Good work for Blank Node. @larowlan. Just pasting the link we discussed https://en.wikipedia.org/wiki/Blank_node as it was a good reference to get my head around the issue. :-)

larowlan’s picture

StatusFileSize
new2.39 KB
new60.61 KB

Here's some progress, some passing tests with the new body, but only supported property attribute so far

amjad1233’s picture

Issue tags: +DrupalSouth 2019

Adding tag for DrupalSouth 2019

amateescu’s picture

Edit: commented in the wrong issue :)

larowlan’s picture

Title: Remove test dependency on easyrdf/easyrdf » Isolate test dependency on easyrdf/easyrdf to a single trait
Issue summary: View changes
Priority: Critical » Normal
StatusFileSize
new59.16 KB

Discussed with @amjad1233 and @alexpott.

Easyrdf has merged the PR to add PHP 7.4 support, but there is still merit in having all of our usages of easyrdf isolated to a trait.

As a result, we're pivoting this issue back to the patch in #20

Downgrading this to normal.

larowlan credited alexpott.

larowlan’s picture

Crediting @alexpott for discussions around this

amjad1233’s picture

Title: Isolate test dependency on easyrdf/easyrdf to a single trait » Remove test dependency on easyrdf/easyrdf
Issue summary: View changes
Priority: Normal » Critical

@larowlan So should we re-upload the patch in #20 ?

And you reckon this will be backported to 8.9.0?

Thus, we can add some tests against that.

amjad1233’s picture

Title: Remove test dependency on easyrdf/easyrdf » Isolate test dependency on easyrdf/easyrdf to a single trait
Priority: Critical » Normal

Sorry, I don't know how I changed the title and priority.

alexpott’s picture

@amjad1233 yep to going back to #20 and I agree that as a test only change we can target the 8.x branch too.

alexpott’s picture

+++ b/core/modules/rdf/tests/src/Functional/UserAttributesTest.php
@@ -75,24 +82,20 @@ public function testUserAttributesInMarkup() {
-      // Parses the node created by the user.
-      $parser = new \EasyRdf_Parser_Rdfa();
-      $graph = new \EasyRdf_Graph();
-      $base_uri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
-      $parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri);
+      $this->drupalGet('node/' . $node->id());
 
       // Ensures the default bundle mapping for user is used on the Authored By
       // information on the node.
@@ -100,14 +103,14 @@ public function testUserAttributesInMarkup() {

@@ -100,14 +103,14 @@ public function testUserAttributesInMarkup() {
         'type' => 'uri',
         'value' => 'http://rdfs.org/sioc/ns#UserAccount',
       ];
-      $this->assertTrue($graph->hasProperty($account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
+      $this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri,  $account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
+
       // User name.
       $expected_value = [
         'type' => 'literal',
         'value' => $author->getAccountName(),
       ];
-      $this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
-
+      $this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri,  $account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');

This change will make the tests slower as we have to rebuild the graph for these two assertions.

I wonder if instead of a trait we could build a lightweight facade to the graph object that does the assertions we need?

larowlan’s picture

I wonder if instead we should add it to WebAssert and then we don't need the first argument and can then keep a reference to the graph item and only regenerate if the session has changed?

xjm’s picture

Priority: Normal » Major

I think this is at least a major task; less dependency coupling would be good.

alexpott’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new40.68 KB
new59.15 KB

I'm withdrawing my review in #33. I don't think that we should hold this up on those concerns. This is only tests and it doesn't matter if we parse a few extra graphs - it's not making a huge difference to test performance.

Here's #27 with coding standards fixes and some docs fixes. As none of these changes is functional I consider this RTBC. I'm also making this change critical as it is blocking some of the simpler solutions for getting to PHP 7.4 compatibility - which is also more important that an couple of extra seconds spent running these tests.

The patch

Testing Drupal\Tests\rdf\Functional\CommentAttributesTest
....                                                                4 / 4 (100%)

Time: 28.99 seconds, Memory: 6.00 MB

Without the patch

Testing Drupal\Tests\rdf\Functional\CommentAttributesTest
....                                                                4 / 4 (100%)

Time: 30.12 seconds, Memory: 6.00 MB

So whilst the patch does do more parsing there are other things in the tests that cause the time to vary by bigger amounts.

As my changes are purely to documentation and automated coding standards - I think it is okay for me to rtbc

mondrake’s picture

Priority: Major » Critical
catch’s picture

Reviewed both the patch and the deceptively large interdiff which is mostly reducing duplicate spaces. +1 to getting this in to unblock PHP 7.4 compatibility and all looks good. I'll commit it to 9.0.x and 8.9.x when it's green, but leave it at for backport against 8.8.x until after the release packaging stuff is all resolved.

  • catch committed 1fa5a19 on 9.0.x
    Issue #3090017 by amjad1233, larowlan, alexpott, mondrake, andypost:...

  • catch committed 0e00ab1 on 8.9.x
    Issue #3090017 by amjad1233, larowlan, alexpott, mondrake, andypost:...
catch’s picture

Version: 9.0.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed 1fa5a19 and pushed to 9.0.x, backported to 8.9.x. Thanks!

Leaving at 'to be ported' for 8.8.x, for after the packaging pipeline is happy again.

  • catch committed d32c184 on 8.8.x
    Issue #3090017 by amjad1233, larowlan, alexpott, mondrake, andypost:...
catch’s picture

Status: Patch (to be ported) » Fixed

Cherry-picked to 8.8.x since this is now a hard blocker for PHP 7.4 support.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.