I'm working on the D7 version of project_release module with the goal of having less custom stuff. This is about the download table on pages like http://drupal.org/project/bad_judgement, the "tar.gz (7.28 KB) | zip (8.47 KB)" part.
In D6, these are tokens provided by project release:
$file_parts = explode('.', basename($item['filename']));
$ext = array_pop($file_parts);
// See if the previous extension is '.tar' and if so, add that, so we see
// 'tar.gz' or 'tar.bz2' instead of just 'gz'.
$ext2 = array_pop($file_parts);
if ($ext2 == 'tar') {
$ext = $ext2 . '.' . $ext;
}
$tokens['[' . $this->options['id'] . '-ext' . ']'] = $ext;
In D7, I'm using the handy built-in "File: Extension" field. But it doesn't special-case 'tar'. It would be nice if it did.
Comments
Comment #1
drummHere is a patch and some tags.
Comment #2
drummAnd here is a completely-untested D8 version.
Comment #4
drummI still don't know the magic filenames or whatever that testbot wants.
Comment #5
dawehnerI really appreciate that you already created a patch against 8.x
Beside tar.gz/tar.bz2 i don't know of an example of this usage of two fileendings,
though if this is not a special case we might should try to implement some option for it?
In general the patch both looks fine to be committed.
Comment #6
marvil07 commentedHere a patch with the option to choose, first on D8 ;-)
Comment #8
marvil07 commentedThe error on the failing test(
Drupal\views\Tests\Handler\AreaTest) is too generic (The test did not complete due to a fatal error.) and I have that test running locally with the patch applied with the new current 8.x.So, let's see what testbot says on a second run.
Comment #9
dawehnerShould have /** {@inheritdoc} */
extension_detect_tar feels better to read. Feel free to change it.
Can you explain what you want to tell us with this comment :)
Should have inheritdoc as well.
Maybe bojhan can suggest some better strings.
Hei, this explanation should have been the description before.
Just to make it more clear we could do 'tar.' . $extension.
Comment #10
marvil07 commentedThanks for the suggestions, they all makes sense, I'll follow them.
Sorry, I based my code on other handlers, that's a docblock I should had removed :-p
Also, as talked on irc, this needs also a test.
Comment #11
marvil07 commentedHere the suggested changes are incorporated.
The test is not yet working. I am not sure about what I should be trying on the test.
I opted to extend
ViewUnitTestBaseand re-useviews_test_datamoduletest_viewview, but it seems like I am overriding the values in the wrong way, so I always get a 'Missing handler: views_test_data extension field'.Maybe I should just do a full (not unit test) test and create files with several names instead?
Suggestions welcome :-)
Comment #12
tim.plunkettYou'll need this in the test:
public static $modules = array('file');Comment #14
marvil07 commented@tim.plunkett: Yes, I I'll need that, but probably with more modules, i.e. all the ones mentioned on the base test class
ViewUnitTestBase, but that does not really solve my question: should I be doing what I am trying in the patch or make a "full" test uploading files and not usingViewUnitTestBase.Comment #15
tim.plunkettNo, $modules is additive, you only need to tack onto whatever is on the parent class.
Several of the more complex handlers have unit and web tests. Case by case basis.
Comment #16
marvil07 commentedThat's a clever hack I was not aware of :-p, sadly not really intuitive(thinking on simple OOP), thanks for pointing it out!
Now that test are running locally, I guess a unit test is enough, since there is not something special to test via web test.
Comment #17
dawehnerThanks for writing a test!
doc + public|protected
needs a small docblock.
I'm not sure, but I think we should better provide a separated test view?
Comment #18
marvil07 commentedI added changes about method visibility and documentation. Notice I also changed the test method name so the target is more clear.
I do not think that is really necessary, since we are only trying to test an option on the field handler behavior. BTW I based my test on another test trying to do that, FieldFileSizeTest, which uses that technique. If I am missing something in my reasoning, please let me know.
Comment #19
dawehnerWell yeah, you probably looked at one of the few examples which manipulate the existing test view instead of creating a new one.
By looking at the yml code you should be able to figure out how to change an existing one, so it's part of the testing.
Comment #20
marvil07 commentedWhat's new:
Comment #21
marvil07 commentedWhat's new: Several extra documentation suggestions made by Daniel.
Comment #22
dawehnerThank you for all the effort
Comment #23
damiankloip commentedAgreed, the patch is looking good.
Comment #24
alexpottCommitted e8c6f84 and pushed to 8.x. Thanks!
Comment #25
marvil07 commentedThanks for all the suggestions and support here!
I'm moving the issue back to D7 views, to actually get the functionality where it was intended originally.
BTW I opened a related issue on #2000058: Document how to make views unit tests.
Comment #26
marvil07 commentedHere the D7 version, test included :-)
Also, I noticed a minor bug in the added code(wrong default value for form option), so adding also a follow-up patch for D8.
Comment #27
marvil07 commentedWell, lets do the d8 patch on comment 26 first, so we can get attention on a bug first instead.
Comment #28
dawehnerI guess we then needs tests for it?
Comment #29
marvil07 commented@dawehner: IMHO no, because that's only a miss-use of the form api on a configuration setting we are declaring.
Comment #30
dawehnerWe don't test this kind of behavior anywhere else so maybe just get this in.
Comment #31
dwwHere's the patch from #26 re-uploaded with a name that the testbot will try to test. Agreed on the RTBC, and that this doesn't need tests, but I figured the core committers would appreciate seeing that no other tests break with this applied.
Comment #32
alexpottCommitted 9b9636c and pushed to 8.x. Thanks!
Comment #33
marvil07 commentedThanks for adding it to D8!
Now let's review the patch for D7, it is on comment 26 ;-)
Comment #34
dwwFixed a trivial indentation bug in
ViewsHandlerTestFileExtension::testFileExtensionTarOption()from #26. Haven't actually tested this on D7 yet, but the code looks fine to me.Comment #35
damiankloip commentedI think we should suffix this with 'Test', instead of having it in the middle of the class name.
core seems like Drupal core, and in D7, that's not what this is :) Can we just go with 'Test the views_handler_field_file_extension handler'
We could do with some docblocks here.
I don't think we need to say it's that handler again - we can just say 'Tests the extension_detect_tar option' or something.
Otherwise, this is looking pretty good!
Comment #36
dwwActually, every other test class follows the pattern ViewsHandler[Foo]Test. So if anything, we should do that to be consistent (i.e. "Test" as suffix, not prefix).
Otherwise, sure. I'm not above giving out pedantic reviews, so it's only fair I should be subjected to some, myself. ;)
Comment #37
dwwFixed everything from #35 except the docblocks for dataSet() and viewsData() since those are functions from the parent class and no other views tests document them. If anything, they should use @inheritdoc but so far none of the D7 views tests do that, so I don't want to introduce an inconsistency here.
Comment #38
damiankloip commentedDidn't I say have test as suffix?! I'm confused. :-)
Sorry, been doing D8 views for too long... so I'm afraid you get a pedantic review including doc blocks.
Comment #39
dwwWhoops, yeah you said suffix. Sorry, I misread. ;)
So, RTBC?
Comment #40
dawehnerIf someone wants to fix all the nitpicks you could theoretically do, feel free to do it. Otherwise I will just get it in.
Comment #41
dwwIMHO I already fixed all the nitpicks, other than introducing some PHPDoc inconsistencies relative to the rest of D7 views in the name of D8 pedantic standards.
Comment #42
damiankloip commentedI didn't say adhere to all those standards, I just said I've been working in d8 for a long time.
Having the few comments make sense seems valid to me. Especially as they have already been fixed.
Comment #43
dwwFor the record, I'm in favor of "pedantic" standards. I'm not objecting to that. But consistency is also important, and I don't want to do things in the D7 code base that we're not doing anywhere else. ;) But whatever, it's a moot point. We're not disagreeing.
Instead, can someone who didn't author this patch please RTBC it?
Thanks,
-Derek
Comment #44
dwwWeird, I didn't touch the tag. Stupid evil comment_alter_taxonomy. :/
Comment #45
damiankloip commentedThe patch is looking good to me.
Comment #46
dawehnerThank you very much. Let's get this in for d.o
Committed and pushed to 7.x-3.x
Comment #47
marvil07 commentedThanks to all the people pushing this ticket ahead :-)