Problem/Motivation

API page: https://api.drupal.org/api/drupal/modules%21simpletest%21drupal_web_test...

"Get a list files that can be used in tests."

Missing an 'of' surely.

Also, the docs for this could really do to explain where the files come from. It appears to generate them, but I'm not entirely sure where it puts them.

Additionally, the documentation of the function this calls in simpletest.module, is also lacking.

Proposed resolution

Fix the docs.

Remaining tasks

Commit.

Note that if #2512210: SimpleTest - WebTestBase method creates binary-text files when the intention was to create text files, and text file creation is broken gets committed first, we'll need to come back here and update the docs so that it doesn't say the 'text' files are actually 'binary-text' any more. This issue is documenting the current status quo only.

User interface changes

None.

API changes

None. Docs only.

Data model changes

None. Docs only.

Brief beta eval: This is just API docs.

CommentFileSizeAuthor
#73 interdiff-2299361-68-73.txt941 bytestrgreen17
#73 description_of-2299361-73.patch3.41 KBtrgreen17
#68 interdiff-2299361-65-68.txt787 bytespushpinderchauhan
#68 description_of-2299361-68.patch3.42 KBpushpinderchauhan
#65 interdiff-2299361-63-65.txt1.01 KBnaveenvalecha
#65 description_of-2299361-65.patch3.47 KBnaveenvalecha
#63 interdiff-2299361-61-63.txt2.1 KBnaveenvalecha
#63 description_of-2299361-63.patch3.47 KBnaveenvalecha
#61 interdiff-2299361-57-61.txt2.39 KBtrgreen17
#61 description_of-2299361-61.patch3.45 KBtrgreen17
#57 interdiff-2299361-51-57.txt928 bytestrgreen17
#57 description_of-2299361-57.patch3.09 KBtrgreen17
#51 interdiff-2299361-47-51.txt869 bytestrgreen17
#51 description_of-2299361-51.patch3.13 KBtrgreen17
#47 interdiff-2299361-33-47.txt581 bytestrgreen17
#47 description_of-2299361-47.patch3.47 KBtrgreen17
#44 description_of-2299361-44.patch1007 bytesneetu morwani
#33 interdiff-2299361-30-33.txt1.49 KBtrgreen17
#33 description_of-2299361-33.patch3.47 KBtrgreen17
#30 interdiff-2299361-26-30.txt2.53 KBtrgreen17
#30 description_of-2299361-30.patch3.41 KBtrgreen17
#8 drupal_simpletest-webtestcase-drupalGetTestFiles_2299361_8.patch2.38 KBwadmiraal
#11 drupal_simpletest-webtestcase-drupalGetTestFiles_2299361_11.patch2.19 KBwadmiraal
#11 interdiff.txt1.2 KBwadmiraal
#13 interdiff.txt1.15 KBwadmiraal
#13 drupal_simpletest-webtestcase-drupalGetTestFiles_2299361_13.patch2.2 KBwadmiraal
#17 drupal_simpletest-webtestcase-drupalGetTestFiles_2299361_17.patch2.95 KBtrgreen17
#17 interdiff_2299361_13_17.txt4.63 KBtrgreen17
#22 drupal_simpletest-webtestcase-drupalGetTestFiles_2299361_22.patch3.49 KBtrgreen17
#22 interdiff-2299361-13-22.txt5.16 KBtrgreen17
#26 description_of-2299361-26.patch3.32 KBtrgreen17
#26 interdiff-2299361-13-26.txt2.88 KBtrgreen17
#29 description_of-2299361-28.patch3.41 KBtrgreen17
#29 interdiff-2299361-26-28.txt2.53 KBtrgreen17

Comments

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7

Same in WebTestBase::drupalGetTestFiles() in Drupal 8.

https://api.drupal.org/api/drupal/core!modules!simpletest!src!WebTestBas...

Looking at the code, it appears that the files go into the public files directory (which is set to something special during tests). Some files are generated, but some come from core/modules/simpletest/files.

joachim’s picture

> Looking at the code, it appears that the files go into the public files directory (which is set to something special during tests).

What's confusing is that this method is used to generate files to test file upload fields. So you're uploading files from public:// that then are uploaded and saved by the field .... right back into public:// !!!

jhodgdon’s picture

I have no idea about that. Anyway I do not think we need to document where the files are, because the return value gives you their paths.

joachim’s picture

Well that requires a developer to either read the whole of the function code, or do a trial run of it to see where the files end up!

jhodgdon’s picture

But why does a developer need to know this information ahead of time? That seems rather pointless. The point of this function is to return a list of the files, abstracting away the details so the developer doesn't need to know where they are, because this function lists them, right??!?

jhodgdon’s picture

Issue tags: +Novice

I'm resurrecting this issue.

What needs to be done, in my opinion:

a) Fix the grammar/typos in the method documentation.

b) Fix the documentation so it is accurate: it should say that it is generating files. The current docs imply it is just "getting a list", not that it is creating new files.

wadmiraal’s picture

Assigned: Unassigned » wadmiraal

On it.

wadmiraal’s picture

Assigned: wadmiraal » Unassigned
Status: Active » Needs review
StatusFileSize
new2.38 KB

Seriously, the $size parameter is almost useless, and used in only one, single test in Core. The problem is you need to know exactly what sizes are available in the test files. I'm listing them for clarity (and because checking the tests/files folder, as suggested, is a pain), but it's really not intuitive. It would be better return files that are larger than the passed size, or just leave the size parameter out completely (like marking it as deprecated, or discouraged).

Anyway, patch attached.

jhodgdon’s picture

Status: Needs review » Needs work

OK... looks pretty good!

That list of file sizes could be more concise. Maybe something like:

 * binary: 1, 45, 345
 * html: 22, 55, 66

(I totally made up those numbers, but get the idea?)
I think that would be better, because the list is kind of long and in kind of a random order... I mean it is in order by size but probably for a given test you'd be interested in just one type of file anyway, and it's hard to scan to see what sizes are actually available for one particular type. Thoughts?

Other than that, looks fine to me.

wadmiraal’s picture

Assigned: Unassigned » wadmiraal

Good point. On it.

wadmiraal’s picture

Assigned: wadmiraal » Unassigned
Status: Needs work » Needs review
StatusFileSize
new2.19 KB
new1.2 KB
jhodgdon’s picture

Status: Needs review » Needs work

Much nicer!

A couple of very minor points:

  1. +++ b/core/modules/simpletest/src/WebTestBase.php
    @@ -448,16 +448,45 @@ protected function findBlockInstance(Block $block) {
    +   *   filter the returned list by size. The default generated files can be of
    +   *   the following sizes (in bytes):
    +   *   - binary: 16, 256, 1024, 2048 and 20480
    

    "can be" seems a bit odd to me. Maybe just say:

    The files generated by this function are of the following sizes...

  2. +++ b/core/modules/simpletest/src/WebTestBase.php
    @@ -448,16 +448,45 @@ protected function findBlockInstance(Block $block) {
    +   *   - binary: 16, 256, 1024, 2048 and 20480
    ...
    +   *   - image: 125, 183, 964, 1831, 1901 and 39325
    

    Technically we require a serial comma in Drupal docs, so:

    ... 2048, and 20480

wadmiraal’s picture

Status: Needs work » Needs review
StatusFileSize
new1.15 KB
new2.2 KB

How's this?

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me, thanks!

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Overall this looks great. Two comments:

  1. +++ b/core/modules/simpletest/src/WebTestBase.php
    @@ -448,16 +448,45 @@ protected function findBlockInstance(Block $block) {
    +   * The first time this method is called, the class will generate a bunch of
    

    The expression "a bunch" is informal. Could we say "numerous" or "several"... or better, exactly how many?

  2. A lot of the information added to this docblock actually describes how simpletest_generate_file() works. That function's documentation is also rather thin. I think it's fine to have the big picture documentation in this method, but if we improve the related function's documentation, then we can reference that.
jhodgdon’s picture

Good idea! So I guess the plan would be:

a) Put the docs about generating files into simpletest_generate_files().
b) In drupalGetTestFiles(), mostly just say it returns the files generated by simplest_generate_files(), plus anything else that someone drops in there.

trgreen17’s picture

Followed jhodgdon's advice above, divided documentation between the two files. Patch and interdiff attached.

jhodgdon’s picture

Thanks for the new patch! I don't think this is quite what we were after, however.

The function simpletest_generate_file() takes as input the name of the file to create. So we shouldn't be putting anything in there about what the file names are; that part comes from the calling method WebTestBase::drupalGetTestFiles().

So. Let's go back to the patch in #13 and also look at the existing docs for simpletest_generate_file()... Let's do this (starting from that patch):

a) Add something to the docs for simpletest_generate_file(), in the @param $type docs, that explains what is actually put into the file for each value of $type: for text it looks like it's random ASCII characters. For binary, it's random characters whose codes are in the range of 0 to 31. For binary-text, it's a random sequence of 0 and 1 values. Also explicitly say what the default value is (binary-text).

b) Add something to the docs for @param $filename on simpletest_generate_file() that explains that .txt is appended to the supplied file name and the file is put in the public file directory.

c) Leave the first line of WebTestBase::drupalGetTestFiles() alone -- it was good in the patch of #13.

d) The first paragraph of the method:

+   * The first time this method is called, the class will generate a bunch of
+   * test files in text and in binary format. These files are stored in
+   * public:// and can be used for tests. It will copy all files in

Change this to say something like: The first time this method is called, it will call simpletest_generate_file() to generate text and binary-text files in the public:// directory. It will also copy all files in ...

The reason for this change is that technically this method is not passing 'text' as the type to simpletest_generate_file(), so it will be generating the default binary-text type of file, not 'text', in:

     // Generate text test files.
      $lines = array(16, 256, 1024, 2048, 20480);
      $count = 0;
      foreach ($lines as $line) {
        simpletest_generate_file('text-' . $count++, 64, $line);
      }

That could be a bug, but fixing it is out of scope for this documentation issue.

e)

+   * All files are prefixed with their type:

Let's change this to say "filenames" instead of "files".

f)

    * @param $size
-   *   File size in bytes to match. Please check the tests/files folder.
+   *   (optional) File size in bytes to match. Defaults to NULL, which will not
+   *   filter the returned list by size. The files generated by this function
+   *   are of the following sizes (in bytes):

Let's change the last two lines to say something like "The files generated and copied by this function..." to be more accurate.

g)

+   * All files are prefixed with their type:
+   * - text-*.txt and text-* (no extension)
+   * - binary-* (no extension)
+   * - html-*.html
+   * - image-*.png, image-*.jpg and image-*.gif
+   * - javascript-*.txt and javascript-*.script
+   * - php-*.txt and php-*.php
+   * - sql-*.txt and sql-*.sql

Looking at simpletest_generate_files() and the files that are currently in core/modules/simpletest/files, this is not accurate. The ones generated will all have .txt extensions, so in this function it will generate text-*.txt and binary-*.txt, so I don't know where that "no extension" idea comes from. And in the HTML line, there is also html-*.txt.

Thanks!

trgreen17’s picture

Thanks for the detailed explanation, it is much appreciated. I think I understand all of your points and I will attempt a proper fix as soon as possible.

trgreen17’s picture

Hi @jhodgdon,

So sorry it took me so long to get back on this but I have the whole day to work on it and would love to get this issue closed! I'm new at contrib though and have a question if you don't mind: You asked me to modify the docs for simpletest_generate_file(). Should that go within the function: "protected function drupalGetTestFiles..." (line 499 of Web TestBase.php) or should it go above that function with the other docs?

Thanks!
Tim

trgreen17’s picture

Hi @jhodgdon,

Sorry, never mind. I see that I should be putting this in the simpletest.module file, around line 490! My bad. :(

Tim

trgreen17’s picture

Hi @jhodgdon and @xjm, here is my latest effort for this patch and interdiff. I tried to follow jhodgdon's excellent advice above as closely as possible, but please note that I added a couple things myself in WebTestBase.php:

Line 466 - added "and have appropriate extensions:"
Line 470 - added serial comma after "image-*.jpg"

jmolivas’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

trgreen17’s picture

Status: Needs work » Needs review
StatusFileSize
new3.32 KB
new2.88 KB

I recreated the patch to fix errors.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! This is very close. Just a few cosmetic things to fix:

  1. +++ b/core/modules/simpletest/simpletest.module
    @@ -490,13 +490,17 @@ function simpletest_classloader_register() {
    + *   The name of the file, including the path. The suffix ".txt" is appended
    + *   to the supplied file name and the file is put into the public:// files directory.
    

    Documentation lines need to wrap as close to 80-character lines as possible, without going over. The first line is too short (at least, I think "to" will fit there), and the second is too long.

  2. +++ b/core/modules/simpletest/simpletest.module
    @@ -490,13 +490,17 @@ function simpletest_classloader_register() {
    + *   If $type is "text", random ASCII characters are inserted into the file.
    + *   If $type is "binary", random characters in the range of 0 to 31 are inserted into the file.
    + *   The default value is "binary-text", and a random sequence of 0 and 1 values are inserted into the file.
      *
    

    These lines also need rewrapping into one paragraph of less than 80 character lines.

    I think also for "binary" it should say "...random characters whose codes are in the range..." ?

    And we can shorten the 'default' bit, something like:

    If $type is "binary-text" (default), a random ...

    [note: no word "and" in the binary-text sentence]

  3. +++ b/core/modules/simpletest/src/WebTestBase.php
    @@ -456,16 +456,44 @@ protected function findBlockInstance(Block $block) {
    +   * The first time this method is called, it will call simpletest_generate_file()
    +   * to generate text and binary-text files in the public:// directory.
    +   * It will also copy all files in core/modules/simpletest/files to public:// as well.
    +   * These contain image, SQL, PHP, JavaScript and HTML files.
    +   *
    

    Re-wrap.

    Also I think we don't need "as well" at the end of the second sentence, since it starts with "... will also". :)

trgreen17’s picture

Thanks for the tips, it is helpful to know the proper form and style! Working on this today.

trgreen17’s picture

Status: Needs work » Needs review
StatusFileSize
new2.53 KB
new3.41 KB

Again, thank you for clearing up the 80 characters in documentation for me. I was doing it by what 'looks' best, I guess from my very old DTP days. :-) So I set phpStorm to show me 80 character columns rather than 120, which made it easy! Attaching the new patch and interdiff now.

NOTE: Please ignore the files above. I named them wrong because I didn't refresh the page before I got the suggested patch name. Rookie mistake. I will re-roll the files and post them with the proper file names. Thanks for your patience!

trgreen17’s picture

StatusFileSize
new3.41 KB
new2.53 KB

Latest patch and interdiff, re-rolled and named correctly.

jhodgdon’s picture

Status: Needs review » Needs work

I'm not too hung up on patch names. ;)

Anyway, this is looking good! But unfortunately, I double-checked and it's not quite accurate:

  1. +++ b/core/modules/simpletest/src/WebTestBase.php
    @@ -456,16 +456,45 @@ protected function findBlockInstance(Block $block) {
    +   * simpletest_generate_file() to generate text and binary-text files in the
    

    It looks like the code in the generate files function is actually calling simpletest_generate_file() with 'binary' for the files whose names start with 'binary', and no arg (which defaults to 'binary-text', not 'text') for the files whose names start with 'text'.

    So we should document this correctly. In this line it should say it generates binary and binary-text types, and down below I think we should note that the text-*.txt files are actually binary-text.

    And we should possibly also file a follow-up issue to change this, because it looks like the intention may have been that the "text" files contained random ASCII characters? I do not know.... ???

  2. +++ b/core/modules/simpletest/src/WebTestBase.php
    @@ -456,16 +456,45 @@ protected function findBlockInstance(Block $block) {
    +   *   - binary: 16, 256, 1024, 2048, and 20480
    

    The binary files generated are actually of size 64 and 1024.

  3. +++ b/core/modules/simpletest/src/WebTestBase.php
    @@ -456,16 +456,45 @@ protected function findBlockInstance(Block $block) {
    +   *   - text: 64, and 1024
    

    The binary-text files are actually: 16, 256, 1024, 2048, 20480 -- and again note that these are binary-text not really "text".

trgreen17’s picture

Wow, thank you for catching these things! I could have checked more carefully... Working on it now.

trgreen17’s picture

StatusFileSize
new3.47 KB
new1.49 KB

Newest patch and interdiff per instructions above. Thanks for the note about patch names. Understood, but I will still try to name them correctly. :-)

NOTE: We will need someone with more experience than I have to determine if a new issue should be created around "it looks like the intention may have been that the "text" files contained random ASCII characters?"

trgreen17’s picture

Status: Needs work » Needs review

Needs review.

trgreen17’s picture

Actually @jhodgdon, I think I get what you're saying about the followup issue. If we can determine that what you said is correct, and text files should contain ASCII characters, I might be able to tackle it.

This issue is my first effort at contrib (and thanks for all the help!) but it would also be very exciting to contribute some actual code to core. What is your recommendation for this?

trgreen17’s picture

If this is actually the desired behavior (ASCII characters), could it be as simple as replacing line 518 of simpletest.module: $text .= chr(rand(32, 126)); with some form of $text .= string chr ( int $ascii )? Or maybe even some form of the fprintf() function?

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

No, what I think needs to be done is that the method in WebTestBase should pass 'text' in as the type, instead of getting the default of 'binary-text'. Right? I think that the function in simpletest.module is clear enough, and now it's actually documented (once we get this patch in). But WebTestBase, in my opinion, is not calling it correctly.

Anyway, the first step there would be to write up an issue with a clear summary of the problem, which I think is that that WebTestBase method is generating binary-text files instead of text files, and it looks like probably text was the intention.

Meanwhile, I believe that the current patch clearly documents the current code. Thanks!

trgreen17’s picture

Re the new issue: of course you are right about how to do it, your way sounds much simpler. I will write up the new issue tomorrow morning, and if it's okay with you, PM you the URL so you can see if I did it correctly?

Re this issue: Awesome!! Thanks so much for your help. :-) As I said this is my first contrib and it's actually very exciting! So... what's next for this issue? Do I need to do anything else?

Thanks again,
Tim

jhodgdon’s picture

Please post the issue URL here in this issue rather than messaging me in IRC. And use the "relationships" section on the issue to mark it as "related" to this issue. Thanks!

And for this issue, you're done unless it gets marked back to "needs work". At least until it is committed to Drupal 8 -- then someone will need to backport the patch to Drupal 7 (but wait until D8 has been taken care of before that, just in case it still is deemed to need work).

trgreen17’s picture

Thanks for such clear explanations and help with this issue. I will create the new issue later today or first thing tomorrow, post the URL here, relate it back to this issue, and try to solve it myself!

And I am following this issue of course, so if there is any more work needed I will be alerted and will be happy to do it.

trgreen17’s picture

I have created a related issue to force text files to be created as 'text' rather than the default of 'binary-text'

Here is the issue URL: https://www.drupal.org/node/2512210

jhodgdon’s picture

Status: Reviewed & tested by the community » Needs work

We need to fix this a bit -- these are not the right sizes for the generated files:

+   *   function are of the following sizes (in bytes):
+   *   - binary: 64, and 1024
+   *   - html: 24
+   *   - sql: 41
+   *   - php: 44, and 47
+   *   - javascript: 57, and 58
+   *   - text: 16, 256, 1024, 2048, and 20480 (these are binary-text files)
+   *   - image: 125, 183, 964, 1831, 1901, and 39325

For binary and text, these numbers are the number of *lines* being generated, not the number of bytes in the file.

neetu morwani’s picture

StatusFileSize
new1007 bytes
neetu morwani’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 44: description_of-2299361-44.patch, failed testing.

trgreen17’s picture

Status: Needs work » Needs review
StatusFileSize
new3.47 KB
new581 bytes

Changing 'bytes' to 'lines' in WebTestBase.php, documentation line #488, since this is more accurate after fixing the related issue.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! But...

+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -457,16 +457,45 @@ protected function findBlockInstance(Block $block) {
+   *   (optional) File size in bytes to match. Defaults to NULL, which will not
+   *   filter the returned list by size. The files generated and copied by this
+   *   function are of the following sizes (in lines):
+   *   - binary: 64, and 1024

This is possibly accurate, but not useful. The caller has to pass in the file size in bytes to match, but we only tell them the number of lines and not how many bytes are in each line. How would they figure this out?

Plus I think maybe that the other files (the ones that are copied not generated) are given as file sizes? Unsure...

Anyway I don't think this is a great way to document it. If they have to match file size, we should either tell them the file sizes, or leave this list out entirely.

trgreen17’s picture

Good point, seems like too much documentation in this case? I'm thinking of leaving it out since as you said they need to pass the file sizes in. How about this as the last line of that doc block?

* @param $size
* (optional) File size in bytes to match. Defaults to NULL, which will not
* filter the returned list by size.

Thoughts?

jhodgdon’s picture

Works for me.

trgreen17’s picture

Status: Needs work » Needs review
StatusFileSize
new3.13 KB
new869 bytes

Excellent. Here's a patch with "less is more" documentation. :-)

jhodgdon’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Thanks! This looks fine to me now.

Note that if #2512210: SimpleTest - WebTestBase method creates binary-text files when the intention was to create text files, and text file creation is broken gets committed first, we'll need to come back here and update the docs so that it doesn't say the 'text' files are actually 'binary-text' any more.

Updated summary and added brief beta eval.

jhodgdon’s picture

Title: description of drupalGetTestFiles() is vague and has a typo » description of drupalGetTestFiles() is vague and has a typo; simpletest_generate_file() needs help too
xjm’s picture

Status: Reviewed & tested by the community » Postponed
jhodgdon’s picture

Status: Postponed » Needs work

The other issue got in. This patch needs a bit of an update now. See comment #52.

trgreen17’s picture

Yes, will work on it this afternoon.

trgreen17’s picture

Status: Needs work » Needs review
StatusFileSize
new3.09 KB
new928 bytes

I changed "binary-text" to "text" in one place and removed what I consider to be unnecessary documentation on one line. But do you think we should say "ASCII text" instead of just "text?"

jhodgdon’s picture

ASCII text sounds like a good idea to me. Also one other thought/question:

+++ b/core/modules/simpletest/simpletest.module
@@ -490,13 +490,19 @@ function simpletest_classloader_register() {
+ *   random sequence of 0 and 1 values are inserted into the file.

Do you think we should also put '0' and '1' in quotes here, to avoid it being mistaken for real binary numbers, or is it clear enough because the type is "binary-text"?

trgreen17’s picture

Agreed on both ASCII and '0' and '1' in quotes. It will make it more clear. However, to possibly avoid another patch, should I use single or double quotes for the 0 and 1? We are using double quotes for "text" but from a PHP perspective maybe single quotes are better for the numbers?

jhodgdon’s picture

Generally, our Drupal coding standards prefer single quotes in code, so we should also use them in docs. I would change all of them to single quotes. Thanks!

trgreen17’s picture

StatusFileSize
new3.45 KB
new2.39 KB

Makes perfect sense! Happy to do it.

jhodgdon’s picture

Status: Needs review » Needs work

Great!

So I took one more look at this patch and since it's just documentation at this point, I found a few nitpick things to fix to make the docs just a bit better:

  1. +++ b/core/modules/simpletest/simpletest.module
    @@ -490,13 +490,19 @@ function simpletest_classloader_register() {
      * Generates test file.
    

    If we're fixing up the docs, can we put "a" in here? :)

  2. +++ b/core/modules/simpletest/simpletest.module
    @@ -490,13 +490,19 @@ function simpletest_classloader_register() {
    + *   (optional) The type, for example: 'text', 'binary', or 'binary-text'. If
    

    These are not really "examples", but actually the three allowed values.

    And would this be clearer as a list? Something like:

    (optional) The type, one of:
    - text: The generated file contains random ASCII characters.
    ...

  3. +++ b/core/modules/simpletest/src/WebTestBase.php
    @@ -457,16 +457,37 @@ protected function findBlockInstance(Block $block) {
    +   * JavaScript and HTML files.
    

    We use serial commas in Drupal docs by convention, so needs a comma after JavaScript in this line.

naveenvalecha’s picture

Status: Needs work » Needs review
StatusFileSize
new3.47 KB
new2.1 KB

addressed #62

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! Pretty close but:

+++ b/core/modules/simpletest/simpletest.module
@@ -487,16 +487,23 @@ function simpletest_classloader_register() {
+ *     - binary: The generated file random characters whose codes are in the
+ *       range of 0 to 31 are inserted into the file.
+ *     - binary-text: The generated file random characters whose codes are in
+ *       the range of 0 to 31 are inserted into the file.

These two descriptions are garbled.

naveenvalecha’s picture

Status: Needs work » Needs review
StatusFileSize
new3.47 KB
new1.01 KB

The last submitted patch, 63: description_of-2299361-63.patch, failed testing.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks for the new patch! But:

+++ b/core/modules/simpletest/simpletest.module
@@ -487,16 +487,23 @@ function simpletest_classloader_register() {
+ *   (optional) The type, one of:
+ *     - text: The generated file contains random ASCII characters.
+ *     - binary: The generated file contains random characters whose codes are
+ *       in the range of 0 to 31 are inserted into the file.
+ *     - binary-text: The generated file contains random sequence of '0' and '1'
+ *       values are inserted into the file.

These are still garbled.

Either say "contains" or "are inserted into the file", but not both. Either way is fine with me.

pushpinderchauhan’s picture

Status: Needs work » Needs review
StatusFileSize
new3.42 KB
new787 bytes

Incorporated #67 suggestion.

Status: Needs review » Needs work

The last submitted patch, 68: description_of-2299361-68.patch, failed testing.

naveenvalecha’s picture

Status: Needs work » Needs review
jhodgdon’s picture

Status: Needs review » Needs work
+++ b/core/modules/simpletest/simpletest.module
@@ -487,16 +487,23 @@ function simpletest_classloader_register() {
+ *   (optional) The type, one of:
+ *     - text: The generated file contains random ASCII characters.
+ *     - binary: The generated file contains random characters whose codes are
+ *       in the range of 0 to 31.
+ *     - binary-text: The generated file contains random sequence of '0' and '1'
+ *       values.
  *

OK, now the text looks good, thanks!

Unfortunately (sorry I didn't notice this before), the indentation is two spaces too much. List markers - are lined up with the text above.

trgreen17’s picture

Status: Needs work » Needs review
StatusFileSize
new3.41 KB
new941 bytes

Thanks for the patches! I figured I would go ahead and implement #72 above.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Great, thanks! I think this is ready to go in now.

xjm’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +Needs followup

Thanks for reworking this one after the other patch.

+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -457,16 +457,37 @@ protected function findBlockInstance(Block $block) {
+   *   (optional) File size in bytes to match. Defaults to NULL, which will not
+   *   filter the returned list by size.

So this parameter is... bizarre. It's especially fussy since you have to use an exact size matching a file generated by simpletest_generate_file()... which doesn't even generate based on size; it generates based on lines and characters! Looking above, it seems a similar concern was raised in #8.

I checked and it is used three times, once directly and twice when passed to the wrapper method in FileFieldTestBase::getTestFile(). Somewhere since #15 we lost the previous docs about what sizes were available... looks like that was done deliberately in #51. I can see the case for that. However, reading the current docs, I don't know how to find out what file sizes there are as we have also lost the prompt in HEAD to check the temporary directory (at least I think that's what it means).

TBH it's code smell and it seems like the parameter should possibly be moved to the calling code, but that's out of scope. I think what we should do is file a followup to deprecate the size parameter and replace the test usages (both beta-eligible changes) since the docs here are an improvement overall.

This issue only changes documentation, so per https://www.drupal.org/core/beta-changes, this can be completed any time during the Drupal 8 beta phase. Committed and pushed to 8.0.x. Thanks everyone for figuring out how this kinda strange API works and documenting it!

  • xjm committed f1463d3 on 8.0.x
    Issue #2299361 by trgreen17, wadmiraal, naveenvalecha, er.pushpinderrana...
jhodgdon’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Fixed » Patch (to be ported)
Issue tags: -Needs followup

Bizarre indeed. Follow-up:
#2534800: \Drupal\Tests\TestFileCreationTrait has mostly unusable file size filter

Also we need to backport these docs fixes to Drupal 7.

  • xjm committed f1463d3 on 8.1.x
    Issue #2299361 by trgreen17, wadmiraal, naveenvalecha, er.pushpinderrana...

  • xjm committed f1463d3 on 8.3.x
    Issue #2299361 by trgreen17, wadmiraal, naveenvalecha, er.pushpinderrana...

  • xjm committed f1463d3 on 8.3.x
    Issue #2299361 by trgreen17, wadmiraal, naveenvalecha, er.pushpinderrana...
stefan.r’s picture

Issue tags: +Dublin2016

Tagging the backport to D7 as a novice task -- just note that not necessarily all of the code will apply (for instance, "core/modules/simpletest/files" is "modules/simpletest/files" in D7.

Prior to backporting we should also manually determine that all of the D8 comments apply to D7 as well.

MaskyS’s picture

Here I go ;)

MaskyS’s picture

Assigned: Unassigned » MaskyS
MaskyS’s picture

Assigned: MaskyS » Unassigned

  • xjm committed f1463d3 on 8.4.x
    Issue #2299361 by trgreen17, wadmiraal, naveenvalecha, er.pushpinderrana...

  • xjm committed f1463d3 on 8.4.x
    Issue #2299361 by trgreen17, wadmiraal, naveenvalecha, er.pushpinderrana...
mile23’s picture

Status: Patch (to be ported) » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.