Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
saveBookLink() in \Drupal\book\BookManager should return an array on success but doesn't return anything.
This causes submit() in \Drupal\book\Form\BookOutlineForm to think an error has occurred on saving the new book outline, even though it has been successful.
Patch returns the $link array as specified in BookManagerInterface.
Comment | File | Size | Author |
---|---|---|---|
#12 | BookManager-saveBookLink-return-array-11.patch | 1.53 KB | mcjim |
#9 | BookManager-saveBookLink-return-array-9.patch | 1.36 KB | mcjim |
#8 | BookManager-testSaveBookLink-do-not-test.patch | 1.17 KB | mcjim |
#6 | Incorrect-error-message-2208325-6.patch | 943 bytes | anksy |
BookManager-saveBookLink-return-array.patch | 472 bytes | mcjim | |
Comments
Comment #1
mcjim CreditAttribution: mcjim commentedComment #2
mcjim CreditAttribution: mcjim commentedComment #3
mcjim CreditAttribution: mcjim commentedComment #4
dawehnerBeside from the potential unit test we should really ensure to test this functionality using a simple test, see the BookTest class.
If you need some help with that, just ping me somewhere.
Your fix is perfect.
Comment #5
lhangea CreditAttribution: lhangea commented#4 I'm a newbie in writing unit tests and I tried writing one for this issue. However I encounter dificulties because I want to unit test the method saveBookLink to see if it returns or not an array. But this method calls loadBookLink which connects to the database (which it cannot happen in unit testing as far as I know ). How am I supposed to unit test this ?
Thanks
Comment #6
anksy CreditAttribution: anksy commentedThis is the test for the issue.
Comment #8
mcjim CreditAttribution: mcjim commentedAttached is work-in-progress on a unit test for saveBookLink().
It's stalled, however, because we can't mock the database connection.
Migrate module is able to mock a database connection, and if that code is pulled into core, we could use that. See #2225473: Move database fakes out of migrate module so they can be used in non-migrate tests.
Comment #9
mcjim CreditAttribution: mcjim commentedNew patch that includes a simpletest test to check that saveBookLink returns something.
Comment #10
mcjim CreditAttribution: mcjim commentedComment #11
dawehnerCool!
Can we test a little bit more, like the content of it?
Comment #12
mcjim CreditAttribution: mcjim commentedAlternative test, which checks the content of the returned array.
It uses
$link += $book_manager->getLinkDefaults($link['nid']);
to add the link defaults to the dummy data. This replicates some of what saveBookLink() does, but I guess that should be OK? If not, I could just hardcode what it adds in the test.Comment #13
dawehner+1
Comment #14
alexpottCommitted 16fb258 and pushed to 8.x. Thanks!