When trying to add a category for the contact form using the following page:
The page: http://localhost/drupal/admin/build/contact/add
Using a category name that already exists, the following error received:
PHP Fatal error: Cannot use object of type stdClass as array in /var/www/drupal/modules/contact/contact.admin.inc on line 114
Running on Debian, Apache/2.2.8, PHP 5.2.5-3, Drupal 6.2
On another server with the same apache/php version, the error appear even when using a new category name.
Both Drupals are pretty clean installations without any external module installed.
Comments
Comment #1
mr.baileysAlso happens on 7.x-dev.
Steps to reproduce:
Patch attached adds additional validation on the category field, making sure the category does not already exist.
Comment #3
mr.baileysPossible testbot failure, requesting re-test.
Comment #4
mr.baileysComment #5
pp commentedPatch is good, and resolve the problem.
Comment #6
catchdb_result() is deprecated, you can use db_query()->fetchField() instead. The conditions probably don't need wrapping in extra parentheses. Also we usually use double quotes for strings with single quotes in, rather than
\'since it's easier for translators to deal with and more readable generally.Other than that, looks good.
Is there a unique key on category name? We could consider adding one as well to enforce it there as well.
Comment #7
dave reidAssigning myself to reroll this patch with a test.
Comment #8
mr.baileysRe-rolled with DB:TNG and a simple test case.
Comment #9
dave reidLet's just use %category instead of '@category'.
Instead of adding e-mail recipients, let's just leave that parameter as an empty string.
Use assertText and assertNoText. We only use assertRaw when we need to. I know we're using it elsewhere in the contact test but I'd like to fix that eventually.
Powered by Dreditor.
Comment #10
mr.baileysThanks for the review, new patch attached.
I think in this case they are needed since assertText/assertNoText looks for stripped html, causing the assertion to fail on the <em>s in '%category'.
Comment #11
dave reidI'm 100% sure assertText ignores HTML, but the tests are good anyway. I just prefer to use assertText since its simpler. :) Patch looks good and tested locally.
I also think we should always add 'Would you like to edit the existing [foo]?' whenever we get duplicate messages like this, but its something to work on in D8, not now.
Comment #12
webchickCommitted to HEAD. Thanks!
I agree assertText() seems better too, but the surrounding ones use assertRaw() so this is consistent. Could file a follow-up patch about that though.
Comment #13
mr.baileysWell, I agree that assertText looks better and makes more sense, but I'm also
100%99% sure that it won't work with the because of the <em>s :)From the assertions page:
Let's run it through the testbot to be sure.
Comment #15
mr.baileyssetting back to fixed since we can't replace the assertRaw with assertText.
Comment #16
dave reidThe problem is you need to provide assertText() with actual non-HTML, so instead of
$this->assertText(t('A contact form with category %category already exists.', array('%category' => $category))You'd do:
$this->assertText(t('A contact form with category @category already exists.', array('@category' => $category))Comment #17
webchickEh, I'd say leave it for now. If we want to go through contact.test whole-sale and clean-up the assertRaw -> assertText in another issue, then cool. But this isn't the only instance in the file, at least from my quick check.
Comment #18
dave reid@webchick: Oh agreed. It would be a follow-up if anything, but it's not important enough for me to work on it. :)