Closed (fixed)
Project:
Feeds Tamper
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
26 Nov 2020 at 15:13 UTC
Updated:
18 Mar 2021 at 16:04 UTC
Jump to comment: Most recent, Most recent file


Comments
Comment #2
megachrizNeeds tests.
Comment #3
jamesdixon commentedThanks I plan to review this week!
Comment #4
jamesdixon commentedLooks good.
For tests I'm thinking we would create a test function like testGetSourceDefinition in feeds_tamper/tests/src/Unit/FeedTypeTamperMetaTest.php.
We could assert that $source_list['alpha'] is equal to 'Alpha' and $source_list['beta'] is equal to 'Beta' after this code in setUp() is run, then getSourceDefinition() is run:
We could also try changing that getMappingSources mock function to return this array:
Then we would check to make sure getSourceDefinition() is returning
['alpha' => 'alpha', 'beta' => 'beta']
since no labels were provided in the second case.
Comment #5
megachriz@jamesdixon
Your suggestion for the first case sounds good. I think the second case should be the following:
We make the assumption here that sources are always keyed by their machine name. Here is for example the method to add a custom source from
\Drupal\feeds\Entity\FeedType:The custom source is saved with the machine name as the key.
Feeds also assumes the key of a source contains the machine name. From
\Drupal\feeds\Form\MappingForm::buildForm():So I think it is safe to assume that
getMappingSources()never returns a numerical indexed array.Comment #6
jamesdixon commentedThanks! I'll look into setting up this test.
Comment #7
jamesdixon commentedI pushed a commit to the branch which starts the test but does not cover the second case we described where there is no label available for the source definition.
I'm trying to figure out the best way to change the Feed Type to return a different value for getMappingSources() without reproducing all the code form setUp(). Unfortunately since $feed_type is protected and I can't just change that on $this->feedTypeTamperMeta I think I will need to create another function which recreates the entire FeedTypeTamperMeta like was done in setUp().
Thinking of setting up a data provider function for testGetSourceDefinition() unless there's a better way.
Comment #8
megachrizPossible way to solve this:
createFeedTypeTamperMeta().$this->feedTypeinstead of$feed_type).getMappingSources(), then call the method to create the FeedTypeTamperMeta. If it is not possible to override, then you could add a parameter to thecreateFeedTypeTamperMeta()method in which you can pass the return value forgetMappingSources().Comment #9
jamesdixon commentedThanks I'll check this out!
Comment #10
jamesdixon commentedThanks for all the guidance @megachriz! I pushed a candidate for the getSourceList() test to this branch.
It may not be the most elegant solution but I made a createFeedTamperMeta() function in the test, and passed the mapping sources parameter in setup so you could call it again to change the FeedTamperMeta if you need to.
Now I noticed getSourceDefinition() is returning the value of the source label as the machine key in the code:
Now the test is testing for that case. Do you think we need to change the getSourceList() code to return what you suggested here?
I'm not sure I fully understood that comment.
Also is there a guide on creating a merge request using the new branching system? There are options like squash commit etc and I'm not fully sure what that would do. There are multiple commits for this one issue and I'm used to a single commit for an issue.
@megachriz have you been using the merge request feature?
Thanks for all the help.
Comment #11
jamesdixon commentedComment #12
jamesdixon commentedNevermind on the merge request stuff I had a read of the docs!
Comment #14
megachrizI've submitted my review, @jamesdixon. Note that there are also a few coding standard issues. See https://www.drupal.org/pift-ci-job/1960645
Comment #15
jamesdixon commentedThanks for the review @megachriz! I've worked through your feedback and pushed it to the merge request. Let me know if you see anything else you think we need to tune. Appreciate it.
Comment #17
megachrizAlright, I think this is good to go. Merged!