Ticket #44083: 44083.4.diff
File 44083.4.diff, 2.7 KB (added by , 5 years ago) |
---|
-
src/wp-includes/functions.php
diff --git src/wp-includes/functions.php src/wp-includes/functions.php index 019f8b6bf6..60bd8f905b 100644
function wp_mkdir_p( $target ) { 1813 1813 } else { 1814 1814 $dir_perms = 0777; 1815 1815 } 1816 1817 /** 1818 * Fires before the directory is created. 1819 * 1820 * @since 5.3 1821 * 1822 * @param string $target Full path to attempt to create. 1823 * @param int $dir_perms Directory permisions 1824 */ 1825 do_action( 'before_create_directory', $target, $dir_perms ); 1816 1826 1817 1827 if ( @mkdir( $target, $dir_perms, true ) ) { 1818 1828 1819 1829 /* 1820 1830 * If a umask is set that modifies $dir_perms, we'll have to re-set 1821 1831 * the $dir_perms correctly with chmod() … … function wp_mkdir_p( $target ) { 1827 1837 } 1828 1838 } 1829 1839 1840 /** 1841 * Fires after the directory is created and the permissions are set. 1842 * 1843 * @since 5.3 1844 * 1845 * @param string $target Full path to the created directory. 1846 * @param int $dir_perms Directory permisions 1847 */ 1848 do_action( 'after_create_directory', $target, $dir_perms ); 1849 1830 1850 return true; 1831 1851 } 1832 1852 -
tests/phpunit/tests/functions.php
diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php index 2191af7ddb..1666a00b61 100644
class Tests_Functions extends WP_UnitTestCase { 1655 1655 array( '03:61:59', false ), // Out of bound. 1656 1656 ); 1657 1657 } 1658 1659 /** 1660 * @ticket 44083 1661 */ 1662 function test_before_and_after_create_directory_actions() { 1663 WP_Filesystem(); 1664 1665 // Test folder to be created/ 1666 $test_folder = DIR_TESTROOT . '/test_44083_folder'; 1667 1668 // Create a test option. 1669 update_option( 'test_44083_option', 1 ); 1670 1671 // Hook a function in {@see 'before_create_directory'} filter. 1672 add_action( 'before_create_directory', function( $target ) { 1673 // Perform check. 1674 $this->assertSame( 1, get_option( 'test_44083_option', null ) ); 1675 1676 // Update test option. 1677 update_option( 'test_44083_option', 2 ); 1678 }); 1679 1680 // Hook a function in {@see 'after_create_directory'} filter. 1681 add_action( 'after_create_directory', function( $target ) use ( $test_folder ) { 1682 global $wp_filesystem; 1683 1684 // Perform check. 1685 $this->assertSame( 2, get_option( 'test_44083_option', null ) ); 1686 1687 // Delete test option. 1688 delete_option( 'test_44083_option' ); 1689 1690 // Delete the test folder created. 1691 $wp_filesystem->delete( $test_folder ); 1692 }); 1693 1694 $create_test_folder = wp_mkdir_p( $test_folder ); 1695 1696 if ( $create_test_folder ) { 1697 // If the folder was created, then the 'after_create_directory' hook should be fired. 1698 $this->assertFalse( file_exists( $test_folder ) ); 1699 1700 $this->assertFalse( get_option( 'test_44083_option' ) ); 1701 } 1702 } 1703 1658 1704 }