Support from Acquia helps fund testing for Drupal Acquia logo

Comments

naveenvalecha created an issue. See original summary.

sumanthkumarc’s picture

Assigned: Unassigned » sumanthkumarc

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sumanthkumarc’s picture

Version: 8.3.x-dev » 8.4.x-dev
sumanthkumarc’s picture

Assigned: sumanthkumarc » Unassigned
benelori’s picture

Issue tags: +DCTransylvania
Wim Leers’s picture

@benelori: thanks for taking this on! :)

naveenvalecha’s picture

Assigned: Unassigned » naveenvalecha

Assigning to myself to take this up.

Wim Leers’s picture

Thanks @naveenvalecha!

Wim Leers’s picture

Issue tags: -DCTransylvania +php-novice, +API-First Initiative

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Assigned: naveenvalecha » Unassigned
Status: Active » Needs review
FileSize
5.64 KB

Here's the needed test coverage.

Wim Leers’s picture

FileSize
1.02 KB
6.61 KB

Turns out that \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::getEntityResourceUrl() is inadequate, and this has gone unnoticed for a long time.

Turns out ContactForm is the only @ConfigEntityType in Drupal core that specifies a canonical link template. This is why we're only finding this now!


That method does this:

  protected function getEntityResourceUrl() {
    $has_canonical_url = $this->entity->hasLinkTemplate('canonical');
    return $has_canonical_url ? $this->entity->toUrl() : Url::fromUri('base:entity/' . static::$entityTypeId . '/' . $this->entity->id());
  }

Simple enough, right? But … ConfigEntityBase overrides the toUrl() method:

  public function toUrl($rel = 'edit-form', array $options = []) {
    // Unless language was already provided, avoid setting an explicit language.
    $options += ['language' => NULL];
    return parent::toUrl($rel, $options);
  }

Which means that we were getting the edit-form URL instead of the canonical URL, even when we know a canonical URL exists. Fortunately, this is easy to fix.

Wim Leers’s picture

FileSize
1.54 KB
8.09 KB

The above patch almost passes — the only thing that's missing is the expected helpful messages for 403 responses. Fortunately, this too is trivial fix 😀

The last submitted patch, 12: 2843778-12.patch, failed testing. View results

Wim Leers’s picture

FileSize
3.59 KB
11.38 KB

Added HAL+JSON test coverage.

Now ready for final review.

The last submitted patch, 13: 2843778-13.patch, failed testing. View results

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/contact/src/ContactFormAccessControlHandler.php
@@ -20,12 +20,12 @@ class ContactFormAccessControlHandler extends EntityAccessControlHandler {
+      return AccessResult::allowedIfHasPermission($account, 'access site-wide contact form')->andIf(AccessResult::allowedIf($entity->id() !== 'personal'));
...
+      return AccessResult::allowedIfHasPermission($account, 'administer contact forms')->andIf(AccessResult::allowedIf($entity->id() !== 'personal'));

+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
@@ -1291,7 +1291,7 @@ protected function assertNormalizationEdgeCases($method, Url $url, array $reques
+    return $has_canonical_url ? $this->entity->toUrl('canonical') : Url::fromUri('base:entity/' . static::$entityTypeId . '/' . $this->entity->id());

Really nice correction! 💎

all other just nice ;)


https://www.drupal.org/pift-ci-job/753333 - it seems CI also really likes this patch <3333
larowlan’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/rest/tests/src/Functional/EntityResource/ContactForm/ContactFormResourceTestBase.php
    @@ -0,0 +1,97 @@
    +      'id' => 'llama',
    +      'label' => 'Llama',
    +      'message' => 'Let us know what you think about llamas',
    +      'reply' => 'Llamas are indeed awesome!',
    ...
    +      'recipients' => [],
    

    I'd like to see some coverage around the recipients field, particularly for the multi-value instance (comma separated). But that can be in the existing follow-up. It's a bit of a snowflake in so far as we're cramming multiple values into a single field.

  2. +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
    @@ -1291,7 +1291,7 @@ protected function assertNormalizationEdgeCases($method, Url $url, array $reques
    -    return $has_canonical_url ? $this->entity->toUrl() : Url::fromUri('base:entity/' . static::$entityTypeId . '/' . $this->entity->id());
    +    return $has_canonical_url ? $this->entity->toUrl('canonical') : Url::fromUri('base:entity/' . static::$entityTypeId . '/' . $this->entity->id());
    

    I think a comment here to explain the findings in #13 would help - and probably prevent someone thinking that the 'canonical' argument was superfluous. I thought it was at first. Knocking back to needs work for that (docs gate), but will keep an eye out for when this gets back to RTBC so it doesn't sink to bottom of list.

Wim Leers’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
2.33 KB
11.77 KB
  1. I tried to address it here (there is no "existing follow-up" that I know of?). The comma-separated thing is only for the @ContactForm entity form. When you save that form, it stores them as a list of strings. (I tested manually to verify.) Test coverage added!
  2. Good call, added comment.

  • larowlan committed a87e8aa on 8.5.x
    Issue #2843778 by Wim Leers: EntityResource: Provide comprehensive test...

  • larowlan committed 3d0abda on 8.4.x
    Issue #2843778 by Wim Leers: EntityResource: Provide comprehensive test...
larowlan’s picture

Version: 8.5.x-dev » 8.4.x-dev
Status: Reviewed & tested by the community » Fixed

Committed as a87e8aa and pushed to 8.5.x.

Cherrypicked as 3d0abda and pushed to 8.4.x.

Thanks @WimLeers et al

Status: Fixed » Closed (fixed)

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