Comments

timmillwood created an issue. See original summary.

wim leers’s picture

Issue tags: +API-First Initiative

As of #2868035: Test that all core content+config entity types have functional REST test coverage, every entity type is required to have REST test coverage. To ensure Drupal 8 is actually "API-First": all entities should be accessible via HTTP APIs.

wim leers’s picture

Issue tags: +Workflow Initiative
amateescu’s picture

content_workspace is an internal entity type, why would we want to add REST support for it?

Kind of the same for replication_log, is there are any reason to support CRUD for this entity type via REST?

timmillwood’s picture

Status: Active » Needs review
StatusFileSize
new1.99 KB

Let's do content workspace entities first.

timmillwood’s picture

Assigned: Unassigned » timmillwood
StatusFileSize
new3.21 KB
new5.12 KB

Adding progress on testing GET, PATCH, POST, DELETE operations.

All fail on permission related issues, which makes me think the workspace permission setup is both flawed and untested.

Status: Needs review » Needs work

The last submitted patch, 7: 2928215-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

timmillwood’s picture

Assigned: timmillwood » Unassigned
Status: Needs work » Needs review
StatusFileSize
new9.7 KB
new12.49 KB

Status: Needs review » Needs work

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

timmillwood’s picture

Status: Needs work » Needs review
Related issues: +#2885469: Regression: manually setting the ID field for newly-created content entities is not possible anymore (public follow-up to SA-2017-002)
StatusFileSize
new12.86 KB
new1.48 KB

Status: Needs review » Needs work

The last submitted patch, 11: 2928215-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

timmillwood’s picture

Status: Needs work » Needs review
StatusFileSize
new5.08 KB
new15.29 KB

This fixes remaining issues with the Workspace entity tests.

After discussion with @amateescu we decided replication_log is an internal entity type, and therefore shouldn't be exposed via REST.

Status: Needs review » Needs work

The last submitted patch, 13: 2928215-13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

timmillwood’s picture

Status: Needs work » Needs review
StatusFileSize
new7.88 KB
new15.19 KB

Fixing all the coding standards items!

Status: Needs review » Needs work

The last submitted patch, 15: 2928215-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

timmillwood’s picture

Title: Write EntityResourceTestBase subclasses for workspace, content_workspace, and replication_log entities » [PP-1] Write EntityResourceTestBase subclasses for workspace, content_workspace, and replication_log entities
Issue summary: View changes
Status: Needs work » Postponed
wim leers’s picture

Looks great!

  1. +++ b/tests/src/Functional/EntityResource/WorkspaceJsonAnonTest.php
    @@ -0,0 +1,26 @@
    + * Test workspace entities for unauthenticated JSON requests.
    
    +++ b/tests/src/Functional/EntityResource/WorkspaceJsonBasicAuthTest.php
    @@ -0,0 +1,36 @@
    + * Test workspace entities for JSON requests via basic auth.
    

    Just FYI: we didn't add these comments to the REST tests in core because it's 100% boilerplate: the class name already explains precisely this :)

    So you can remove it if you want, but if you prefer this, that's fine too

  2. +++ b/tests/src/Functional/EntityResource/WorkspaceResourceTestBase.php
    @@ -0,0 +1,185 @@
    +  protected function setUpAuthorization($method) {
    +    $this->grantPermissionsToTestedRole([
    +      'administer workspaces',
    +      'create workspace',
    +      'update workspace layla',
    +      'delete workspace layla',
    +      'view workspace layla',
    +      ]);
    +  }
    

    This should not grant all permissions, but should only grant the permissions necessary depending on the method. That's why $method is a parameter.

  3. +++ b/tests/src/Functional/EntityResource/WorkspaceResourceTestBase.php
    @@ -0,0 +1,185 @@
    +      'upstream' => 'local_workspace:live',
    +      ]);
    

    Supernit: The second line I quoted is indented one level too much.

  4. +++ b/tests/src/Functional/EntityResource/WorkspaceResourceTestBase.php
    @@ -0,0 +1,185 @@
    +        $this->formatExpectedTimestampItemValues((int) $this->entity->getStartTime()),
    ...
    +        $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()),
    

    Hm, why do we need one return value to be cast to an integer but not the other?

  5. +++ b/tests/src/Functional/EntityResource/WorkspaceResourceTestBase.php
    @@ -0,0 +1,185 @@
    +    $http_method_to_entity_operation = [
    +      'GET' => 'view',
    +      'POST' => 'create',
    +      'PATCH' => 'update',
    +      'DELETE' => 'delete',
    +    ];
    +    $operation = $http_method_to_entity_operation[$method];
    +    $entity_access = $this->entity->access($operation, NULL, TRUE);
    +    if (!$entity_access->isAllowed()) {
    +      return $entity_access->getReason();
    +    }
    +    return parent::getExpectedUnauthorizedAccessMessage($method);
    

    See #2928887-3: EntityResource and EntityResourceTestBase have different ideas for access — this should hardcode the expected strings, otherwise we still won't A) know that the messages are helpful, B) know that we regress.

  6. +++ b/tests/src/Kernel/WorkspaceInternalResourceTest.php
    @@ -0,0 +1,62 @@
    +    $this->setExpectedException(PluginNotFoundException::class, 'The "entity:content_workspace" plugin does not exist.');
    ...
    +    $this->setExpectedException(PluginNotFoundException::class, 'The "entity:replication_log" plugin does not exist.');
    

    👍

  7. --- /dev/null
    +++ b/workspace.link_relation_types.yml
    

    👍 — nice bugfix that this surfaced :)

timmillwood’s picture

StatusFileSize
new2.61 KB
new15.58 KB

#18.1 - PHPCS tells me we need these.
#18.2 - Done
#18.3 - Done
#18.4 - I've no idea, but otherwise I was getting a string.
#18.5 - Done
#18.6 - 🤘
#18.7 - 🤘

amateescu’s picture

Title: [PP-1] Write EntityResourceTestBase subclasses for workspace, content_workspace, and replication_log entities » Write EntityResourceTestBase subclasses for workspace, content_workspace, and replication_log entities
Status: Postponed » Fixed
StatusFileSize
new15.03 KB
new1.13 KB

These tests are needed in the main core patch, so I rerolled #19, fixed a couple of minor things and committed to 8.x-2.x.

This means that the new tests will fail until #2885469: Regression: manually setting the ID field for newly-created content entities is not possible anymore (public follow-up to SA-2017-002) gets in, but well, #2927169: Fix views queries is in the same boat :)

wim leers’s picture

So very glad to see this test coverage, and I'm sure that that gives you some extra confidence too :) And fewer hurdles to get it into core!


#19:
Sorry for not seeing your comment until now :(

RE #18.4: hm, but that then means getStartTime() isn't returning an integer, which violates its interface if I'm reading #2784921-83: Add Workspaces experimental module correctly.


#20: I think you'll like the fact that I've been pushing #2885469: Regression: manually setting the ID field for newly-created content entities is not possible anymore (public follow-up to SA-2017-002) forward then :)

amateescu’s picture

StatusFileSize
new3.18 KB

RE #18.4: hm, but that then means getStartTime() isn't returning an integer, which violates its interface if I'm reading #2784921-83: Add Workspaces experimental module correctly.

This happens for many other timestamp fields, and basically all integer ones IIRC. There are many instances of casting to (int) throughout REST test classes.

FWIW, these changes were needed in order to make the core patch pass all the tests, so I've committed them here as well.

  • amateescu committed da4c7c7 on 8.x-2.x
    Issue #2928215 followup by amateescu: Fix EntityResourceTestBase...
amateescu’s picture

Status: Fixed » Closed (fixed)

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