Problem/Motivation
WebTestBase used to have a way to generate test files.
Proposed resolution
Let's provide a trait for that.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #47 | 2738567-30.patch | 10.32 KB | claudiu.cristea |
Comments
Comment #2
mtiftThis seems to work for me.
I feels a bit odd putting it in the simpletest module, but it does follow the same principle of Drupal\simpletest\ContentTypeCreationTrait, which I'm also using for my BrowserTestBase tests.
Comment #3
mtiftThis fixes a dumb spacing error at the end of the file.
Comment #4
dawehnerCool, thank you! Can you think of a core test we could convert to BTB at the same time to prove that this trait actually works?
In order to be helpful for browser tests I think you need to put this function onto this trait. You could make it a public static function, which adds a working BC layer.
Comment #5
mtiftAs far as testing, I'm not completely sure. Maybe something like ImageFieldDefaultImagesTest::testDefaultImages()?
The attached patch converts simpletest_generate_file() to a method.
Comment #6
dawehnerOne thing to prove that this trait actually works could be to replace the existing code in TestBase by this trait. Do you think this would make sense?
Comment #7
mtiftAh, good idea, and that seems to work (and I'm assuming you meant WebTestBase).
When I add
use TestFileCreationTrait;to the WebTestBase class, the tests pass. Without it they fail. The interdiff is for the(hopefully) passing patch.Comment #9
dawehnerGreat to see it works.
Ah yeah, I wasn't there whether its in TestBase or in WebTestBase.
Comment #10
alexpottThis is such weird behaviour. Not the fault of this patch but it is just strange.
This property should probably be part of the trait.
The dependencies on these Drupal common functions is interesting.
Why public static? I guess it could be useful. Just to call this without using the trait. Dunno.
Comment #12
jmuzz commentedAdded property.
generateFile is public static because it's a replacement for a global simpletest function: simpletest_generate_file(). Not sure if it really makes sense to do it this way since it will still need a class to use the trait in order to call it. If not, what would be the recommended approach? It would probably be good for the function to be available after simpletest goes away.
Comment #13
jmuzz commentedRelating an issue from the paragraphs module that is postponed on this.
Comment #15
jmuzz commentedComment #17
jmuzz commentedComment #18
jmuzz commentedI think this counts as a backwards compatibility issue.
Comment #19
dawehnerCould we move this trait outside of the simpletest namespace? This is no longer about simpletest to be honest.
Comment #20
dawehnerComment #21
dawehnerJust moved stuff around / rename methods as well as some minor docs.
Comment #22
samuel.mortensonI added the trait (ImageFieldCreationTrait) from #2782309: Refactor File and Image related image field creation logic into a new trait that wasn't included in this issue.
Comment #24
samuel.mortensonFrom the test log:
17:47:52 PHP Fatal error: Trait 'Drupal\image\Tests\ImageFieldCreationTrait' not found in /var/www/html/core/modules/image/src/Tests/ImageFieldTestBase.php on line 25Not sure why that would happen, do I need to import this trait even though it's in the same namespace?
Comment #25
dawehner@samuel.mortenson
Well, strictly speaking this doesn't belong into this issue. This is about
drupalGetTestFilesanddrupalGetTestFilesand the other one is about the file.module/image.module specific test base classes.
Comment #26
dawehner@samuel.mortenson
Do you mind reviewing #21 as it is?
Comment #27
claudiu.cristeaEDIT: The review is against #21
This is a flag but the naming doesn't sound as for a flag/bool variable. $testFilesGenerated, $testFilesAreGenerated, $hasGeneratedTestFiles? I have no idea but with $generatedTestFiles I'm expecting to find there a list/array.
Well, I think we should break the dependency on Simpletest. This is because I guess we'll use this trait also an BTB & Co. and that should not rely on simpletest. So, we need a home for the sample files.
What if type is invalid? Probably throwing an error would be better.
s/Compare/Compares ?
s/stdclass/stdClass
Should we add that this is used in uasort() in \Drupal\Tests\TestFileCreationTrait::getTestFiles() and also add a @see?
I don't see any reason in core why this would be public. But, who knows, maybe somebody has used it in contrib or custom?
Comment #28
jmuzz commentedI did items 1, 4, 5, 6.
2 - Where should they go?
3 - Maybe make separate issues for changes in functionality? This ticket is about making the existing functions available for the new testing system.
7 - Instructions unclear.
Comment #29
dawehnerThe problem with the renaming is that existing tests using this trait will have a BC break :(
This issue was meant to just move code around :(
Comment #30
jmuzz commentedComment #31
jmuzz commentedComment #34
jmuzz commentedComment #35
dawehnerThis was just about moving the code. Of course we could improve things, but those should be done in other issues
Comment #36
mtiftComment #37
claudiu.cristeaEven it's just about moving the code around, the source files were not moved. We still keep the dependency to Simpletest. I propose to move them in core so, even Simpletest can benefit. Where? I don't know. How it sounds
core/tests/files?Comment #38
dawehnerWhat about using core/tests/fixtures?
Comment #39
claudiu.cristeaYes, why not? Let's do that.
Comment #40
dawehnerI agree with @claudiu.cristea, let's do it right!
Comment #41
jmuzz commentedComment #42
claudiu.cristeaThank you @jmuzz, looks good.
Just a minor:
I think \Drupal::root() is not needed. Simply 'core/tests/fixtures/files' should work.
Also let's see if other tests were not broken. I'm thinking on tests that are accessing directly the files in simpletest dir (I remember I saw once such test).
Comment #44
jmuzz commentedI see what you mean. Well, as I understand it the point of this is to make backwards compatibility so the existing tests can get ported without doing a lot of extra stuff to them so that extra stuff can be done later. Messing with a bunch of the tests to make them compatible with the backwards compatibility seems to defeat the purpose. Maybe the files should be left where they are for now.
Comment #45
claudiu.cristeaComment #47
claudiu.cristeaIt turns out in #45 that decoupling Simpletest is not so easy. Also, we still have to keep files in simpletest for the case some contrib tests rely on those files. Probably it's better not to break here the dependency on simpletest but to deal with that in a future issue, as @jmuzz pointed in #44. Although, conceptually we have a clear issue here: a core functionality (BTB tests) will have a dependency on a module (Simpletest).
I'm reposting #30 and set back to RTBC as per #35 to unblock conversions. I opened #2803621: Break BrowserTestBase & children dependency on Simpletest, deprecate stub BC traits for breaking this dependency, probably after all test conversions.
Comment #48
claudiu.cristeaComment #49
alexpottSince this is just a code shuffle in the test system to make something available to BrowserTestBase I'm going to commit to 8.2.x as well.
Committed and pushed 97b2c76 to 8.3.x and e4bac87 to 8.2.x. Thanks!
Comment #53
mile23Formal deprecation here: #3028708: Deprecate simpletest_generate_file()