Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
migration system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
27 Sep 2014 at 07:06 UTC
Updated:
19 Feb 2015 at 09:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
benjy commentedI was confused by so many integer fields coming back as strings so i've opened #2345813: Primitive TypedData fields are not cast properly
Comment #2
benjy commentedComment #4
ultimikeBenjy,
Is this something that we can have a newbie do? It doesn't seem like it is much more than a big search-and-replace...
-mike
Comment #5
benjy commentedYes we certainly could make this a novice task. The reason I did it was to try find a few bugs and I actually think there are 2 or 3 in the failed test here that will all need separate issues.
Comment #6
quietone commentedI've been looking at this, seemed a good way to poke around.
What is the recommended way to compare arrays?
Line 136-138 of MigrateFieldInstanceTest.php states
but that is the only case I found like that. Usually assertEqual is used.
Comment #7
benjy commentedI was using assertIdentical but I think that also meant the order had to be the same. I'm not entirely sure if there is an agreed upon approach in core, many simply use assertEqual() which is fine unless you're asserting against an empty array.
Comment #8
chx commentedEither you do that to compare two arrays -- but even that compares only arrays that do not contain arrays. Here, look at this:
use this. Put it in the NestedArray class, I would say. It's kinda useful:
['foo' => 'bar', 'this' => 'that']is kinda identical to['this' => 'that', 'foo' => 'bar']after all.Comment #9
quietone commented@chx, thanks. But if the arrays are identical and contain a NULL, kindaIdenticalArrays will return False because "isset() will return FALSE if testing a variable that has been set to NULL".
Comment #10
quietone commentedSince strings are returned, then shall we keep assertEqual be kept for testing integers and NULL?
It is unexpected to get a string back when when an int was loaded. Is this behavior documented?
Comment #11
chx commented> Is this behavior documented?
Kind of yes.
Comment #12
quietone commented@chx, thanks. That lead to some interesting reading.
The attached patch changes assertEqual to assertIdentical only when both arguments are strings. But without some standard future tests could be written with assertEquals and not assertIdentical. This looks like a good case for an agreed approach and documentation. Is that suitable for a documentation issue?
Still need to address comment #8.
Comment #13
quietone commentedComment #15
quietone commentedOops, left one line using assertIdentical on ''.
Comment #16
benjy commentedWhen we're asserting against TRUE/FALSE I think we should change to assertIdentical, eg:
Main reason been that if you look at my patch from #3, I had failures like
Which looks like a bug but assertEqual(NULL, false) will return TRUE!
Comment #17
quietone commentedThose failures seem to be the result of testing the empty string or NULL, not a TRUE/FALSE test. Anyway, MigrateNodeBundleSettingsTest.php has been changed to test integer to integer.
That just leaves 88 more to change and I should be able to do that over this weekend.
Comment #18
benjy commentedWhat I meant was, previously it was:
$this->assertEquals(NULL, FALSE); // PassesAnd I changed to this:
$this->assertIdentical(NULL, FALSE); // FailsAwesome, ping me if you need any help.
Comment #19
quietone commentedAnother installment. This just leaves the arrays plus a few others that are not straightforward. I need to look at those when I am not as tired as I am now.
@benjy, I may take you up on that offer, after this busy weekend.
Comment #20
quietone commentedManaged to get some time and converted all but 3 assertEquals successfully.
Comment #22
quietone commentedAnd the interdiff, with a proper name.
Comment #24
quietone commentedDown to the last 3.
MigrateCckFieldValuesTest.php - Both failures relate to a multivalue field.
MigrateFieldInstanceTest.php - An array test with an empty string ('') that fails when assertIdentical is used.
Comment #26
quietone commentedThis should be right.
Comment #28
quietone commentedMigrateFieldInstanceTest.php - No, it's not the empty string. I missed that the value is a float.
Comment #29
quietone commentedComment #31
quietone commentedassertIdentical fails because the value being tested is either a float or a string, depending on which test is run. When MigrateCckFieldValuesTest is run by itself $planet_node->field_multivalue->value returns a string. When MigrateDrupal6Test is run $planet_node->field_multivalue->value returns a float. Why?
Comment #32
quietone commentedI think this it finished now. All but one assertEqual has been changed to assertIdentical. There are two cases which I guess should be addressed in separate issues.
1) field_multivalue is defined in two files, MigrateCckFieldValuesTest.php, as an integerl, and in Drupal6FieldInstance.php, as a decimal. When CckFieldValues test is run, it expects an integer casted as a string. But if the full d6 migration test is run first, it will create field_multivalue as a float with precision 2 and the returned string will be 'NN.00' not 'NN' as expected.
I changed MigrateCckFieldValuesTest.php to match the way field_multivalue is created in Drupal6FieldInstance.php and all tests pass, irregardless of the order. The allows the tests to pass but a better solution is to fix the duplication.
2) And a similar thing is going on with MigrateNodeTest.php at line 58. If run by itself $node_revision->revision_log->value is Null but when the complete set of tests is run $node_revision->revision_log->value is ''. The test on line 58 remains an assertEqual.
Comment #33
quietone commentedComment #34
benjy commentedIs this because of MigrateDrupal6Test? If so, we've done something similar before where we set a property in setUp() which doesn't run for MigrateDrupal6Test. Makes this clearer.
Comment #35
benjy commentedAlso, not sure if you addressed my comments from #18, the test run of my first patch seem to be gone so I can't review them failures.
Comment #36
quietone commentedPatch not longer applies. So just a reroll.
Comment #37
quietone commented@benjy, regarding comment #18 and #35.
The assertIdentical fails because it does type checking. And since NULL is the only possible value of type null assertIdentical with anything other than a NULL will fail. Whereas. assertEqual does type juggling, NULL is converted to boolean FALSE and comparing FALSE to FALSE will pass.
So, to change any assertEqual with a NULL argument to an assertIdentical I changed NULL to match the type of the source. That seems to me a good way to do it, since in a migration one should know the source data well. Or am I missing your point?
regarding comment #34
Yea, wasn't sure how to tackle this one, so just tried this poor method. The property sounds like it would work and I'll look into it. But still confused why the source data is not consistent for these tests.
Comment #38
benjy commentedComment #39
quietone commentedOh, so you want to check all instances where NULL is used in an assert, all instances of assertNotNull, assertNull and when a parameter of an assert is tested for null, i.e.
$this->assertIdentical(is_null($form_display), FALSE, "Form display node.story.default loaded with config.");Is that right?
Comment #40
chx commentedWe have assertNull and assertNotNull for those. Both simpletest and phpunit.
Comment #41
benjy commentedAs discussed in IRC, my point was asserting that something is NULL might be an incorrect change and indicative of a bug where something is not migrated.
Comment #42
quietone commentedThanks for the the clarification.
Of the assertions involving NULL, most I can verify are checking that something does not exist and should stay.
The following files are the only ones that have tests that need a more experienced eye on them.
MigrateCommentVariableEntityFormDisplaySubjectTest
MigrateUploadEntityFormDisplayTest.php
MigrateUserProfileEntityDisplayTest.php and MigrateUserProfileEntityFormDisplayTest.php
$this->assertNull($display->getComponent('profile_sell_address'));$this->assertNull($display->getComponent('profile_sold_to'));MigrateFieldTest.php
$this->assertEqual($settings['default_image']['fid'], '');Plus this one we talked about on IRC
MigrateAggregatorFeedTest.php - remove the test on 'hash' and creating a new issue to determine if hash needs to be migrated or not.
Comment #43
quietone commentedI'm getting inconsistent test results since yesterday so uploading this patch.
Comment #45
quietone commentedRight, fixed MigrateNodeTest in attached patch. That leaves these two remaining instances of assertEqual.
$this->assertEqual($settings['default_image']['uuid'], '');$settings['default_image']['uuid'] is not set. But I'm not sure if it is migrated.
$this->assertEqual($user->getSignatureFormat(), reset($signature_format));I'd appreciate some suggestions on these two.
Comment #47
benjy commented$this->assertEqual($settings['default_image']['uuid'], '');I don't know why we're asserting a uuid, that surely didn't come from D6. I think the test can be deleted.
$this->assertEqual($user->getSignatureFormat(), reset($signature_format));D8 stores NULL when the signature format is disabled. If we can get the user Id and check in the dumps it might tell us what the issue is.
Comment #48
ultimikeComment #49
ultimikeLooking at
$this->assertEqual($user->getSignatureFormat(), reset($signature_format));Changing this to
$this->assertIdentical($user->getSignatureFormat(), reset($signature_format));and running the MigrateUserTest results in two fails, both when the D6 signature format = 0 (UIDs 16 and 17).
Since $signature_format is set earlier in the test, can't we just check to see if it is an empty array and set it to null if it is? Then assertIdentical will work.
-mike
Comment #50
benjy commentedIf the signature format for user 16/17 is "0" in the dumps then that should run through the static map in the d6_user migration and the destination should be NULL.
So, $signature_format should be array(NULL) at this point and the assert identical check should work. If that's not the case, something else is going wrong?
Comment #51
benjy commentedTook a closer look at this, what you said is nearly right. Apart from we need to check $source->filter_format === '0' rather than the result of the lookup in the idMap. We have a separate issue so I posted there: #2403815: Test migration of signature_format with assertIdentical
Comment #52
quietone commentedRerolled, in preparation for returning home and working on this in the next few days.
Comment #54
quietone commentedLets try this reroll
Comment #56
quietone commentedNew patch including changes suggested in #46 and #51.
#46 - Removed test for uuid.
#51 - Since there is a new issue for the testing of signature_format that is restored that to an assertEqual.
There should be one fail. It seems that my comment in #45 was incorrect and MigrateNodeTest.php still has a problem.
$this->assertEqual($node_revision->revision_log->value, '');Comment #58
benjy commentedSeems like a bug, do you want to try track it down?
Comment #59
quietone commentedYes, I would, and I've looked at it a bit, but l have far too many questions about migration and D8 in general to do it. I just wind up spinning my wheels, as the saying goes.
Comment #60
benjy commentedThe first thing I would try would be to update the dump and the test to actually have a log message. It's possible something turns an empty string into NULL during processing. Hopefully it's as easy at that.
Comment #61
quietone commentedWell, I've found two things:
1. The test node created in MigrateNodeTestBase has a revision_log value of NULL.
But when I create a node via the GUI the revision_log value is blank, presumably an empty string.
2. The migration of the revision_log value works when the string is not empty.
Comment #62
benjy commentedBased on this finding, lets either add a comment explaining this or update the dumps so we have a string and use assertIdentical. Whichever you prefer.
Comment #63
quietone commentedAdded code to make the revision_log a string. Works for MigrateNodeTest but having trouble (again) getting the complete migration tests to run.
Comment #65
quietone commentedMade a mistake rerolling.
Comment #67
quietone commentedSigh, another reroll mistake.
Comment #68
quietone commentedGood. And grep doesn't find any instances of 'assertEqual'.
Comment #69
benjy commentedGreat work. I'm glad we've managed to get this green, I know it has been tedious but it has already proven elsewhere that it's a good way to catch bugs.
Thanks again.
Comment #70
quietone commentedThanks. I couldn't have done this with out your help.
It did fulfill my goal of a being a good way to poke around. I know more about migration now and have heaps more questions.
Comment #71
alexpottComment #72
quietone commentedReroll.
Comment #73
benjy commentedBack to RTBC
Comment #74
alexpottGreat - I think the increased strictness is worth it. Migrate is not blocked by the beta. Committed b1d2d7c and pushed to 8.0.x. Thanks!