Make WordPress Core

Opened 8 years ago

Closed 4 years ago

Last modified 4 years ago

#39975 closed task (blessed) (fixed)

Remove direct calls to '/tmp/' in Unit Tests

Reported by: joemcgill's profile joemcgill Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch needs-refresh
Focuses: Cc:

Description

As noted by @mikeschroder in 39875, there are several places in our unit tests where we assume the temp directory is '/tmp/' and make direct calls. Instead, we should use something like wp_tempnam() to ensure we're writing and removing files from the right place during tests.

Attachments (3)

39975.01.patch (6.5 KB) - added by DJPaul 8 years ago.
39975.2.diff (7.5 KB) - added by christophherr 7 years ago.
Replaces three additional occurrences of /tmp in phpunittests/widgets
39975.3.diff (9.0 KB) - added by christophherr 7 years ago.
Removes symlinks from phpunit/tests/link/themeFile.php using parts of @danielhueskens patch on #40856

Download all attachments as: .zip

Change History (18)

@DJPaul
8 years ago

#1 @DJPaul
8 years ago

  • Keywords has-patch added; needs-patch removed

Please see 39975.01.patch which makes the requested change. There is one whitespace change (space at the end of the line) accidentally included.

#3 @netweb
8 years ago

Related, possible duplicate: #40856

@christophherr
7 years ago

Replaces three additional occurrences of /tmp in phpunittests/widgets

@christophherr
7 years ago

Removes symlinks from phpunit/tests/link/themeFile.php using parts of @danielhueskens patch on #40856

#4 @christophherr
7 years ago

This would greatly improve the unit test experience on Windows.

39975.2 replaces additional usages of /tmp from three files in phpunit/tests/widgets
39975.1 and 30075.2 remove 157 errors.

39975.3 replaces symlinks from phpunit/tests/link/themeFile.php using parts of @danielhuesken 's patch on #40856.
On Windows 10 with PHP 7.1.11, this removes the following warnings:

Warning: unlink(C:\laragon\www\trunk/src/wp-content\themes\theme-file-parent): Permission denied in C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php on line 13

Warning: unlink(C:\laragon\www\trunk/src/wp-content\themes\theme-file-child): Permission denied in C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php on line 14

and also avoids additional warnings when the tests are run again (because unlink didn't remove the symlink in the previous run) :

Warning: symlink(): Cannot create symlink, error code(183) in C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php on line 8

Warning: symlink(): Cannot create symlink, error code(183) in C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php on line 9

6 failures remain after 39975.3:

1) Tests_WP_Customize_Manager::test_import_theme_starter_content
Expected reuse of non-auto-draft attachment.
Failed asserting that an array contains 914.

C:\laragon\www\trunk\tests\phpunit\tests\customize\manager.php:644

2) Tests_DB::test_mysqli_flush_sync
procedure could not be created (missing privileges?)

C:\laragon\www\trunk\tests\phpunit\tests\db.php:621

3) Test_Theme_File::test_theme_file_uri_returns_valid_uri with data set #0 ('parent-only.php', 'theme-file-parent', array('theme-file-parent'))
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'C:\laragon\www\trunk\tests\phpunit\includes/../data/themedir1/default/parent-only.php'

C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php:117

4) Test_Theme_File::test_theme_file_uri_returns_valid_uri with data set #1 ('child-only.php', 'theme-file-child', array('theme-file-child'))
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'C:\laragon\www\trunk\tests\phpunit\includes/../data/themedir1/default/child-only.php'

C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php:117

5) Test_Theme_File::test_theme_file_uri_returns_valid_uri with data set #2 ('parent-and-child.php', 'theme-file-child', array('theme-file-parent', 'theme-file-child'))
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'C:\laragon\www\trunk\tests\phpunit\includes/../data/themedir1/default/parent-and-child.php'

C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php:117

6) Test_Theme_File::test_theme_file_uri_returns_valid_uri with data set #3 ('neither.php', 'theme-file-parent', array())
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'C:\laragon\www\trunk\tests\phpunit\includes/../data/themedir1/default/neither.php'

C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php:117
Last edited 7 years ago by christophherr (previous) (diff)

#5 @Clorith
7 years ago

#43038 was marked as a duplicate.

#6 @birgire
6 years ago

#44605 was marked as a duplicate.

This ticket was mentioned in Slack in #hosting-community by desrosj. View the logs.


6 years ago

This ticket was mentioned in Slack in #core by clorith. View the logs.


5 years ago

#9 @davidbaumwald
4 years ago

  • Keywords needs-refresh added

Latest patch fails against trunk, so marking for a refresh.

#10 @SergeyBiryukov
4 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Owner set to SergeyBiryukov
  • Status changed from new to accepted

#11 @SergeyBiryukov
4 years ago

In 48463:

Tests: Copy themes from tests/phpunit/data to wp-content/themes, instead of creating a symlink.

This allows the theme file tests in phpunit/tests/link/themeFile.php to run on Windows without requiring administrative privileges.

Follow-up to [42812], [42819].

Props danielhuesken, christophherr, davidbaumwald, SergeyBiryukov.
See #40856, #39975.

#12 @SergeyBiryukov
4 years ago

  • Milestone changed from Future Release to 5.5

#13 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 48464:

Tests: Replace hardcoded /tmp/ references with get_temp_dir().

This allows more tests to pass on Windows.

Props danielhuesken, DJPaul, christophherr, joemcgill, netweb, davidbaumwald, SergeyBiryukov.
Fixes #40856, #39975.

#14 @SergeyBiryukov
4 years ago

As noted in comment:4, [48463] uncovered a few theme file test failures that were previously skipped. These can be addressed either in follow-up commits here or in a new ticket.

Note: See TracTickets for help on using tickets.