Updated: Comment #0
Problem/Motivation
The ForumBreadcrumbBuilder, part of the new breadcrumb system, is really doing 2 jobs. It's handling breadcrumbs for nodes that are in forums as well as the forum listing pages. But it's really obvious from the code that it's two services, as there's an if-else in both relevant methods.
Services should only do one job. That one module is providing both use cases is fine; they can still be separate services, and they should be.
Proposed resolution
Split ForumBreadcrumbBuilder into 2 services: ForumNodeBreadcrumbBuilder and ForumListingBreadcrumbBuilder.
* The contents of ForumBreadcrumbBuilder::applies() should get split as appropriate (right now it's just 2 conditions joined by an OR, so one class gets one half and the other gets the other.)
* The two utility methods that are called from ForumBreadcrumbBuilder::build() can be inlined into the build() method of the new services, as appropriate.
When this is done, there should be no change apparent in the UI from the current behavior. It's just a code reorganization.
Remaining tasks
Notes:
This is tagged Novice, but is really an "advanced novice" issue; or maybe a "services novice" issue. :-)
For reference:
The breadcrumb change notice: https://drupal.org/node/2026025
A blog post about the breadcrumb system, because I'm biased: http://www.palantir.net/blog/d8ftw-breadcrumbs-work
If you have questions, stop by #drupal-contribute or #drupal-wscci.
User interface changes
None.
API changes
None; this is an internal refactor that should not affect anyone.
Comment | File | Size | Author |
---|---|---|---|
#27 | interdiff_23.txt | 584 bytes | Mile23 |
#27 | forum-bc-split-2209997_24.patch | 31.02 KB | Mile23 |
#25 | interdiff_22.txt | 950 bytes | Mile23 |
#25 | forum-bc-split-2209997_23.patch | 31.02 KB | Mile23 |
#22 | interdiff-2209997-21-22.txt | 8.21 KB | YesCT |
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedlinking directly to the contributor task for creating patch.
Comment #2
ThisIsDog CreditAttribution: ThisIsDog commentedComment #3
Mile23Oo. Awkward. Novice issue queue SHOWDOWN!
I made this before I saw that ThisIsDog had assigned himself. My bad.
But I made it so here goes.
ForumTest::verifyForums() leads me to believe that the tests cover breadcrumbs for chains with forums, containers, and nodes in them. I wish I could tell for sure, but that test class is impossible to read. Also: 2AM.
Comment #4
YesCT CreditAttribution: YesCT commented@ThisIsDog are you up to do a review on it?
Sometimes when that happens to me, I go ahead and finish, and then I diff my solution against someone else's. :) And that helps get the review started.
Review hints and explanations: https://drupal.org/contributor-tasks/review
Comment #5
jibranCan we have unit tests as well? :$
Similar much. Why not create a ForumBreadcrumbBuilderBase.
Needs update. ForumListingBreadcrumbBuilder and ForumNodeBreadcrumbBuilder now.
Comment #6
Mile23See: http://drupalcode.org/project/drupal.git/blob/e93b685205fa5aa261953b5f14...
But I guess I'll refactor to have three classes where one was passing tests before. :-)
Comment #7
ThisIsDog CreditAttribution: ThisIsDog commentedSure, I'll do a review of what Mile23 submits. I actually fell asleep at my computer not too long after I assigned myself, so it actually works out okay. I don't want to step on his toes though, so I'll avoid writing code.
Feel free to ping me on IRC when you finish refactoring. I'll take a look at it.
Comment #8
larowlanA gift from your friendly PHPUnit fairy (you have to believe to receive).
Tests the node one, you might want to adapt this into an abstract base test and use it for both.
Also +1 to making a Forum breadcrumb base.
Comment #9
Mile23Forum breadcrumb base, and some more PHPUnit fairy goodness.
I struggled with testing build(), because of that despicable chain of dependencies.
From #8:
This kind of stuff makes my test isolation OCD go nuts. :-) Maybe unwrap it to be a dataprovider and tack it on with the rest?
Also @ThisIsDog: I stepped on your toes, so please hop in where you want to.
Edit: Ugh. Wrong patch. Maybe after dinner.
Comment #10
jibraninterdiff please.
Comment #11
Mile23Interdiff when it's meaningful. :-)
Comment #12
jibranI don't know what is the difference between #8 and #9 so can't review.
Comment #13
larowlanPlease please please look after our reviewers and post an interdiff.
Comment #14
Mile23Moved the breadcrumb stuff to /Breadcrumb/ namespace (and folder) since there are a bunch of files.
Refactored larowlan's unit tests, and hammered out a few things as well.
Only needs a similar test for
ForumListingBreadcrumbBuilder::build()
.AND... Two interdiffs, one from #8 and one from #9, so choose based on which of those you read (or submitted).
Comment #15
jibranThank you very much @Mile23 for the interdiffs. Just some minor points.
What's 'new' in it? :D
arghh. Can we redefine it in local namespace? comments please @larowlan.
white space.
Wrong rebase I think.
Comment #16
larowlansee #8
Stick it behind a protected method and then mock that method, passed in #8.
Comment #17
Mile23Why would we do that, when forum manager does it for us? :-)
I think I missed deleting that comment you both are looking at.
And yes, bad rebase. Sob.
Comment #18
larowlanAh, helps if I read the code and not the comments/reviews
Great work
Fixes #15 - note the interdiff is big because it backs out the search/node/field module changes.
Comment #19
Mile23Thanks, larowlan.
ForumBreadcrumbBuilderBase has a build() method that does the 'Home > Forum' part now, and all the build() methods are now tested.
Also maybe a real rebase. :-)
Comment #20
dawehnerIt would be great to fix this weird indentation.
We use @coversDefaultClass and @covers now in quite some places.
You can use assertAttributeEquals directly.
<3
Comment #21
Mile23All the stuff in #20 (including <3), plus there was more funky formatting.
Comment #22
YesCT CreditAttribution: YesCT commentedsummary of these changes: some typos, copy paste errors, standards. (so just nits)
details (to see all the changes, see interdiff):
a) we might as well follow the standard for api summaries on classes. https://drupal.org/node/1354#classes "Use a third person verb to start the summary of a class, interface, or method. For example: "Represents a ..." or "Provides..."."
b) a typo: breadcrum
The entity manager.
is more common, eh? Not sure why it was "Entity".
TermInterface is an unused use.
#20.1 didn't say how it should be fixed but #1539712: [policy, no patch] Coding standards for breaking function calls and language constructs across lines seems to imply that the closing parens should be at the same indention as the line that opened them.
huh. I didn't know forums used taxonomy terms as their ids and for organization. interesting. @anypost says it was always like this.
wrapping this to 80 chars.
"Lines containing comments (including docblocks) must wrap as close to 80 characters as possible without going over,..."
https://drupal.org/node/1354#general
I think we just indent 2 spaces, even in a place like this.
copy and paste. fixed to match the class.
this
all by itself,
is a little weird.
we could split it like some of the others.
or make it all one line.
or maybe like...
(which is else where in this same class)
I googled a bit to see if there was some advice about when to use getMock vs getMockBuilder,
and found
http://phpunit.de/manual/3.7/en/test-doubles.html
and
http://stackoverflow.com/questions/279493/phpunit-avoid-constructor-argu...
In this case, I guess either could be used.
Comment #23
dawehnerYou can also use assertAttributeEquals here.
Comment #24
Mile23Yah, the two bits do the same thing. They really should be consistent in the same patch, shouldn't they? I think the builder is more expressive and easier to read, but The Drupal Community's Opinion May Differ.
Actually you can't. The constructor takes a config factory and then extracts the config object and stores it. What we're testing is whether that happens.
Comment #25
Mile23Just amended ForumNodeBreadcrumbBuilderTest::testBuild() to have a nicer getMock() format.
Comment #26
jibranThis patch is doing some serious unit testing. Thanks for the awesome work @Mile23.
ForumNodeBreadcrumbBuilder not NodeBreadcrumbBuilder.
Comment #27
Mile23@jibran: Doh! that one 'contains'....
Much unit testing credit goes to the PHPUnit fairy. Otherwise known as larowlan (see #8)
Comment #28
jibranThanks. I think it is done.
Comment #29
ThisIsDog CreditAttribution: ThisIsDog commentedI went through it too and it looked good to me.
Comment #31
jibran27: forum-bc-split-2209997_24.patch queued for re-testing.
Comment #32
jibranReverting the old status.
Comment #33
alexpottReviewing...
Comment #35
alexpottCommitted 58f31ac and pushed to 8.x. Thanks!