We partly started implementing support for a "menu_path" option in hook_menu_alter(). This can be used to move the REST API path for a resource to something different than /resource_type. Example: one might wish to move "/node/1.json" to "/api/version2/node/1.json".

We need to document this and fully implement it in hook_menu_alter().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sepgil’s picture

Status: Active » Needs work
FileSize
38.15 KB

done, added even a test :-)

sepgil’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1697558-menu_path.patch, failed testing.

sepgil’s picture

Assigned: Unassigned » sepgil
Status: Needs work » Needs review
FileSize
38.15 KB

Patch should now run through.

klausi’s picture

Status: Needs review » Needs work
+++ b/restws.api.php
@@ -54,12 +54,15 @@ function hook_restws_resource_info() {
+  $resource_info['node']['menu_info'] = 'mypath';

should be menu_path, not menu_info. Also documentation on hook_restws_resource_info() is missing.

+++ b/restws.info
@@ -3,5 +3,5 @@ description = Provides RESTful web services.
-files[] = restws.test
+files[] = tests/restws.test

"For modules, a single [module name].test file is the general rule. It should be placed directly in the module folder." from http://drupal.org/node/325974

+++ b/restws.module
@@ -209,40 +209,43 @@ function restws_menu_alter(&$items) {
+    // Remove the slash at the end for the querying paths if menu is set, or use
+    // the resource name as query path.

That comment does not relate to any code statements here?

+++ b/tests/restws_test.module
@@ -0,0 +1,13 @@
+/**
+ * Implements hook_restws_resource_info_alter().
+ */
+function restws_test_restws_resource_info_alter(&$resource_info) {
+  $resource_info['node']['menu_path'] = 'foo';
+}

Should have an @see reference to the test method.

sepgil’s picture

Status: Needs work » Needs review
FileSize
5.74 KB

Fixed the issues mentioned by klausi.

klausi’s picture

Status: Needs review » Needs work

Did some small modifications and committed this.

Now we need to fix all the URLs that are being used in resource references and querying. And we need tests that verify that the changed menu path is printed correctly in the format output.

sepgil’s picture

Status: Needs work » Needs review
FileSize
3.07 KB

I modified restws_resource_uri() so, that it can be used for any restws uri.

klausi’s picture

Status: Needs review » Needs work

Committed a slightly modified version of your patch.

Now the only missing thing are tests that verify that the changed menu path is printed correctly in the format output.

sepgil’s picture

Status: Needs work » Needs review
FileSize
4.94 KB

This patch adds the missing tests and fixes the other menu path tests, which were broken. Had to create a new test class, since enabling the test module wouldn't work with module_enable().

klausi’s picture

Status: Needs review » Needs work

Do not duplicate the httpRequest() method. The new test class should either extend the first class or you need a third class as common parent class to the actual test classes.

I guess module_enable() did not work because the menu needs to be rebuild, so that the new paths get recognized (menu_rebuild()). Please try that again.

fago’s picture

klausi’s picture

Tagging.

klausi’s picture

Issue summary: View changes

Marked #2286515: Multipart menu_path's are not working as a duplicate.

The testMenuPath() method is quite broken now and does not test the right thing. Maybe we should make restws_test_restws_resource_info_alter() configurable with variable_get(), so that each test can specify what the test path should look like.

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
3.26 KB

Tests + fixed a bug where menu_path containing a period "." was not working.

mr.baileys’s picture

Assigned: sepgil » Unassigned
FileSize
3.21 KB

Forgot a left-over debug statement in previous patch.

klausi’s picture

Status: Needs review » Needs work

Excellent work, almost there!

  1. +++ b/restws.test
    @@ -541,8 +539,21 @@ class RestWSTestCase extends DrupalWebTestCase {
    +      $this->assertResponse(200);
    

    We should also assert that the returned content in the response body is correct. You can check for the title of the node for example.

  2. +++ b/restws.test
    @@ -541,8 +539,21 @@ class RestWSTestCase extends DrupalWebTestCase {
    +      $this->assertResponse(200);
    

    Same here.

mr.baileys’s picture

Status: Needs work » Needs review
Issue tags: -D7 stable release blocker
FileSize
3.51 KB
3.51 KB

Added the assertion on node title back in as per #17.

mr.baileys’s picture

Not sure why the patch was attached twice, but both files are the same.

klausi’s picture

Status: Needs review » Needs work

Yeah no, the original assertion is wrong. Comparing the title that we generated with the node does not make sense. You need to pull out the title from the result of drupalGet().

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
1.13 KB
3.44 KB

That does make more sense. New patch & interdiff attached.

klausi’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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

klausi’s picture

Oops, forgot to push that commit, done now!