menu_get_names() contains an incorrect PDO syntax, passing a single field as a string to fields() rather than an array.

This causes a fatal error when the function is called. The function is not called anywhere in core now, so it's hard to find this. I came across it while working on DHTML Menu, which does call it.

This is a critical bug as far as my addon is concerned, but not from the perspective of core, so I leave it at normal priority. Nevertheless, I'd like this patch to get in quickly. :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cburschka’s picture

Whoops, my differ didn't work. Here we go.

cburschka’s picture

Extra closing parenthesis. I can't do anything right today, can I? ;)

Dries’s picture

Should we write tests for this? Given that it is not used in core, it sounds prone to bugs ...

cburschka’s picture

Assigned: Unassigned » cburschka
Status: Needs review » Needs work

Sure, good idea. It can be a simple function in the menu test, which lists menus, creates one, looks for it, then deletes it, lists menus and checks if it's gone.

cburschka’s picture

Status: Needs work » Needs review
FileSize
1.41 KB

This patch adds a check to modules/menu/menu.test. Strictly speaking, the function is in includes/menu.inc, but the menu module is the one that already creates a custom menu, so I figured it is easiest to put a line in there to check for this menu in the return value of menu_get_names().

Status: Needs review » Needs work

The last submitted patch failed testing.

cburschka’s picture

Assigned: cburschka » Unassigned

I can't get it to work either, even after resetting the static cache. No idea why the menu name isn't listed.

cburschka’s picture

Status: Needs work » Needs review

Edit: The testing framework has confused the hell out of me yet again.

catch’s picture

I like #2.

catch’s picture

Status: Needs review » Needs work

I think I posted to the wrong issue. Patch is failing though.

cburschka’s picture

Priority: Normal » Critical
Status: Needs work » Needs review

chx confirmed that it's impossible to test this without using a test module. menu_get_names() would have to be called in the context of the test site, requiring simpletest to install a hidden module and query a particular page that shows menu_get_names() return value. Even though we can reuse an existing test module (menu_test) it will still require an extra menu callback in that module. At that point we really have to ask if the one-line fix in the ten-line function is worth it. If we can do without a test, then #2 would be ready to go.

Setting back to NR for this reason.

Also, given that this actually crashes, bumping to critical lest we lose sight of it again.

Hugo Wetterberg’s picture

I second Arancaytar on this. #2 should be committed straight away, and the issue of providing testing coverage should be posted as a separate issue.

Status: Needs review » Needs work

The last submitted patch failed testing.

c960657’s picture

Status: Needs work » Needs review
FileSize
3.43 KB

Added a test.

Status: Needs review » Needs work

The last submitted patch failed testing.

c960657’s picture

Status: Needs work » Needs review
FileSize
4.24 KB

Sorry, forgot to include the actual change to menu.inc.

cburschka’s picture

Status: Needs review » Reviewed & tested by the community

Hey, neat! Less code than I thought would be required.

Patch works, uses good names for the new callbacks and has clean code-style. This is probably ready to go.

Hugo Wetterberg’s picture

Great work Arancayar! Hopefully this will get committed soon now it's covered by tests too. Four months delay for that though...

pwolanin’s picture

Do we really not use this anywhere in core? We are essentially pulling this data up for some forms - so maybe this function is redundant to http://api.drupal.org/api/function/menu_get_menus/7. That DBTNG looks a little odd also.

Hugo Wetterberg’s picture

Well, I wouldn't call it redundant. To just have the menu_get_menus function would require a dependency on the menu module. Which doesn't make sense as the menu api / inspection methods really shouldn't be tied that closely to what is described as "Allows administrators to customize the site navigation menu.". Rather it's the menu_get_menus function that's redundant, or whose functionality should've been merged into (or replaced) the menu_get_names in menu.inc

webchick’s picture

Status: Reviewed & tested by the community » Needs review

Looks like this needs more discussion.

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community

@webchick - no I was confused - this function needs to be available in the absence of menu module, and the patch here is a very straightforward bugfix.

Hugo Wetterberg’s picture

This issue made me think about the division of API and UI for the menu system. Doesn't functions like:
menu_load
menu_parent_options
_menu_parents_recurse
menu_reset_item
_menu_parent_depth_limit
menu_get_menus

Belong to the API, and therefore menu.inc, rather than the menu module?

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Ok cool, thanks Peter.

For the test, that looks a bit over engineered to me. All we really want to do is test the input/output of menu_get_names(), no? If so, don't bother with a page callback that var_export()s the contents of it, just do a straight-up assertEquals() on the function return value and the array of expected values.

Hugo Wetterberg’s picture

Ok, I've created a separate issue for movin the API-functionality from the menu module into menu.inc http://drupal.org/node/569164

c960657’s picture

Status: Needs work » Needs review

New patch with simpler test. This ignores the advice in #11 - on second thought I don't understand it.

cburschka’s picture

For the test, that looks a bit over engineered to me. All we really want to do is test the input/output of menu_get_names(), no? If so, don't bother with a page callback that var_export()s the contents of it, just do a straight-up assertEquals() on the function return value and the array of expected values.

@webchick: That's what I thought too (see #5). However, when calling a database-querying function inside a test class, the function will query the base site rather than the simpletest-generated site. So none of the menus we generate in Simpletest will be in the return value of the function. We can't even assume that the base site won't have custom menus - so it's not easy to get an array of expected values from anywhere.

c960657’s picture

FileSize
2.33 KB

Argh! I forgot to attach the patch in #26. Here it is.

However, when calling a database-querying function inside a test class, the function will query the base site rather than the simpletest-generated site.

Sure? $db_prefix is changed in setUp(), so both the testing side and the tested side have access to the same database. Note that the "original" menu (defined in menu_test.module) is returned by menu_get_names(), both in menu_get_names-2.patch and menu_get_names-3.patch.

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community

simple fix, simple test

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

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