Active
Project:
Drupal core
Version:
main
Component:
phpunit
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
28 Nov 2014 at 18:18 UTC
Updated:
22 Aug 2025 at 22:56 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
mile23Here are three patches, two set to test.
One is just a file move from
core/tests/Drupal/Tests/Component/Utility/HtmlTest.phptocore/tests/Drupal/Tests/Core/Utility/HtmlTest.php.One adds minor coding standards changes.
One adds the tests from #2382011: Expand unit testing for Drupal\Component\Utility\UserAgent (and originally: #2294503: Component Utilities unit test cleanups.), including comments here: https://www.drupal.org/node/2382011#comment-9384979
Comment #4
mile23Let's try that again....
This patch moves HtmlTest to the Component namespace and adds tests.
Comment #5
mile23OK, since that's working, here are the tests that were added, merged in from #2382011: Expand unit testing for Drupal\Component\Utility\UserAgent as mentioned above.
Comment #6
daffie commentedI have two remarks for this patch.
Probably a stupid question: Why do we need this? The variable $property is local?
Why is this function not called testGetClass? The same for the other functions?
Comment #7
mile23Not a stupid question. :-) Reflections are a little counter-intutive.
$propertyis a local variable but it holds aReflectionPropertythat refers to a property of another object. In this case we need to poke aNULLvalue intoHtml::seenIdsInitto reinitialize it. Since it's static and all. What a pain. :-)Yes, that's probably a better name. I was just moving those tests over without changing them too much.
So in this patch I changed
$propertyto a more useful name, and also changed that function totestGetClass()to be consistent with our coding standards.Comment #8
daffie commented@Mile23: I know what reflections are. Mostly. But my remark was that you put it in a local function variable. As far as I know you cannot use that variable outside of the function. Or am I wrong?
@Mile23: You only changed testHtmlClass(). There are more testHtml* functions.
Comment #9
mile23Right, the local variable within the method goes out of scope as soon as
setUp()ends.However, since
seenIdsInitis a static property (of a static class, no less), the value we set using reflection will 'keep.' It's just a glorified global, really.setUp()gets run before every test method, so now that variable is in a known state so the test can run. Some tests don't need it, others do, but it's just easy to do that initialization every time.And... so I did miss a few other method names.. :-)
Comment #10
daffie commented@Mile23: Thank you for explaining. Again I learned something new.
The function name has changed to testGetId()
Comment #11
mile23Ugh. Forget this comment. I shouldn't code before second cup of coffee.
Comment #12
mile23Changes from #10, plus some docblock rearrangement for PHPUnit coding standards (document @returns, not @params for data providers).
Comment #13
mile23Comment #14
daffie commentedSome minor comment remarks.
The first line: We are testing Html::getUniqueIdWithAjaxIds().
The first line: We are testing Html::getId().
In the rest of the class it is: "Tests the Html::theTestMethod() method."
Comment #15
mile23Nope. :-)
But anyway, removed all short summary lines.
Comment #16
daffie commentedThe HtmlTest has been moved and has been extended.
The old test file has been deleted.
The comments are all in order.
It looks good to me so I give it a RTBC.
Comment #17
tstoecklerNot downgrading but in these cases it really helps to roll patches with
-C -Min order to allow for easier reviewing.Comment #18
alexpottThe serialise test in giving a false impression of test coverage.
We should be passing in some script and styles to test that that code has the expected affect.
Comment #19
alexpottAlso can the move and test additions and fixes happen in separate issues.
Comment #20
mile23Setting to postponed based on #2392673: Move Drupal\Tests\Core\Utility\HtmlTest to the proper namespace
This will obviously need a re-roll when that drops.
Comment #21
mile23Comment #22
daffie commentedComment #23
mile23Straight-up reroll from #15.
Comment #24
daffie commentedThis is already covered by @coversDefaultClass.
Can we remove this. We already have @covers ::getClass.
Can we rename providerTestCleanCssIdentifier() to providerCleanCssIdentifier().
Can we rename providerTestGetUniqueId() to providerGetUniqueId().
Can we rename providerTestGetUniqueIdWithAjaxIds() to providerGetUniqueIdWithAjaxIds().
Can we rename providerTestGetId() to providerGetId().
Can we rename this provider function. It is used multiple times. So it can become providerLoad() or providerHtml().
In the function testLoad we do not have an assertion like:
Why not? If we add such an assertion, can we make $expected the first parameter in the testLoad() method.
Comment #26
daffie commentedStill needs work
Comment #27
franksj commentedI addressed each of @daffie's comments except for this guy:
It looks like we're analyzing $doc by looking at its tags. Are you suggesting asserting that the entire doc is equal to something expected? Do you mind clarifying?
Comment #28
franksj commentedWhoops, forgot my interdiff.
Comment #29
mile23We're testing that given funky HTML we end up with good normalized HTML, and that we have the proper number of elements. We can't really generate a \DomDocument for some of the data, and we also can't compare equality for it.
Comment #30
josephdpurcell commentedNow reviewing.
Comment #31
josephdpurcell commentedI looked at the full patch, looks good.
I looked at the interdiff to see if it matched all of daffie's comments from #24 at it looks good.
Regarding daffie's comment about testLoad, it seems to me that the tests that are there for testLoad are sufficient for merging. If someone wanted to expand on them more I suggest a follow up.
Marking as RTCB.
Comment #32
tim.plunkettThis doesn't actually change anything, just adding to the patch size.
Here and elsewhere, use [] for new code.
Comment #33
alexpottThe issue summary needs an update because we no longer move code around.
@tim.plunkett if they change all the new stuff to
[]then this file will be half new half old... so I don't think that's really worth it - as far as I remember the current agreement is each file should be internally consistent. I'm not particularly bothered by #32.1 - fine either way by me - although in general I side on the lease change to achieve the task in the issue summary - which in this case is to add more test coverage and therefore in reality this change is out of scope.Comment #47
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #48
smustgrave commentedThis one actually appears to still be relevant