Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 41... Línea 41...
41
 * @package   core
41
 * @package   core
42
 * @category  test
42
 * @category  test
43
 * @copyright 2009 Jerome Mouneyrac
43
 * @copyright 2009 Jerome Mouneyrac
44
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45
 */
45
 */
46
class filelib_test extends \advanced_testcase {
46
final class filelib_test extends \advanced_testcase {
47
    public function test_format_postdata_for_curlcall(): void {
47
    public function test_format_postdata_for_curlcall(): void {
Línea 48... Línea 48...
48
 
48
 
49
        // POST params with just simple types.
49
        // POST params with just simple types.
50
        $postdatatoconvert = array( 'userid' => 1, 'roleid' => 22, 'name' => 'john');
50
        $postdatatoconvert = array( 'userid' => 1, 'roleid' => 22, 'name' => 'john');
Línea 1824... Línea 1824...
1824
        $this->assertEquals($thirdrecord['filename'], $allfiles[2]->filename);
1824
        $this->assertEquals($thirdrecord['filename'], $allfiles[2]->filename);
1825
        $this->assertEquals($fourthrecord['filename'], $allfiles[3]->filename);
1825
        $this->assertEquals($fourthrecord['filename'], $allfiles[3]->filename);
1826
        $this->assertEquals($fifthrecord['filename'], $allfiles[4]->filename);
1826
        $this->assertEquals($fifthrecord['filename'], $allfiles[4]->filename);
1827
    }
1827
    }
Línea -... Línea 1828...
-
 
1828
 
-
 
1829
    /**
-
 
1830
     * Test that zip files in the draftarea are returned.
-
 
1831
     * @covers ::file_get_all_files_in_draftarea
-
 
1832
     */
-
 
1833
    public function test_file_get_all_files_in_draftarea_zip_files(): void {
-
 
1834
        $this->resetAfterTest();
-
 
1835
        $this->setAdminUser();
-
 
1836
 
-
 
1837
        $zip1 = ['filename' => 'basezip.zip'];
-
 
1838
        $file = self::create_draft_file($zip1);
-
 
1839
 
-
 
1840
        $zip2 = [
-
 
1841
            'filename' => 'infolder.zip',
-
 
1842
            'filepath' => '/assignment/',
-
 
1843
            'itemid' => $file->get_itemid(),
-
 
1844
        ];
-
 
1845
        $file = self::create_draft_file($zip2);
-
 
1846
 
-
 
1847
        $otherfile = [
-
 
1848
            'filename' => 'otherfile.txt',
-
 
1849
            'filepath' => '/secondfolder/',
-
 
1850
            'itemid' => $file->get_itemid(),
-
 
1851
        ];
-
 
1852
        $file = self::create_draft_file($otherfile);
-
 
1853
 
-
 
1854
        $allfiles = file_get_all_files_in_draftarea($file->get_itemid());
-
 
1855
        $this->assertCount(3, $allfiles);
-
 
1856
        $this->assertEquals($zip1['filename'], $allfiles[0]->filename);
-
 
1857
        $this->assertEquals($zip2['filename'], $allfiles[1]->filename);
-
 
1858
        $this->assertEquals($otherfile['filename'], $allfiles[2]->filename);
-
 
1859
    }
1828
 
1860
 
1829
    public function test_file_copy_file_to_file_area(): void {
1861
    public function test_file_copy_file_to_file_area(): void {
1830
        // Create two files in different draft areas but owned by the same user.
1862
        // Create two files in different draft areas but owned by the same user.
1831
        global $USER;
1863
        global $USER;
1832
        $this->resetAfterTest(true);
1864
        $this->resetAfterTest(true);
Línea 2042... Línea 2074...
2042
                '.html ; .htm',
2074
                '.html ; .htm',
2043
                'text/html',
2075
                'text/html',
2044
            ],
2076
            ],
2045
        ];
2077
        ];
2046
    }
2078
    }
-
 
2079
 
-
 
2080
    /**
-
 
2081
     * Tests that readfile_accel() triggers the expected debugging message when a non-empty
-
 
2082
     * output buffer is detected, using both a file path and a stored_file input.
-
 
2083
     *
-
 
2084
     * This test runs a CLI script in a separate process to isolate buffer manipulation.
-
 
2085
     * This is necessary because readfile_accel() uses ob_get_clean() and ob_end_flush(),
-
 
2086
     * which interfere with PHPUnit's internal output buffer enforcement and cause risky
-
 
2087
     * test errors.
-
 
2088
     *
-
 
2089
     * The CLI script simulates a non-empty output buffer, calls the readfile_accel(), and
-
 
2090
     * prints any debugging output. The test then captures that output and asserts that the
-
 
2091
     * correct debugging message was generated.
-
 
2092
     *
-
 
2093
     * @covers ::readfile_accel
-
 
2094
     */
-
 
2095
    public function test_readfile_accel_with_path_and_stored_file(): void {
-
 
2096
        $this->resetAfterTest();
-
 
2097
 
-
 
2098
        // Construct the command to run the CLI script with a custom constant defined.
-
 
2099
        $scriptpath = __DIR__ . '/fixtures/readfile_accel_debug_cli.php';
-
 
2100
        $cmd = 'php -r ' . escapeshellarg("define('PHPUNIT_READFILE_ACCEL_TEST', true); require '$scriptpath';");
-
 
2101
 
-
 
2102
        $pipes = [];
-
 
2103
        $process = proc_open($cmd, [
-
 
2104
            1 => ['pipe', 'w'],
-
 
2105
            2 => ['pipe', 'w'],
-
 
2106
        ], $pipes);
-
 
2107
 
-
 
2108
        $stdout = stream_get_contents($pipes[1]);
-
 
2109
        $stderr = stream_get_contents($pipes[2]);
-
 
2110
 
-
 
2111
        fclose($pipes[1]);
-
 
2112
        fclose($pipes[2]);
-
 
2113
 
-
 
2114
        $exitcode = proc_close($process);
-
 
2115
 
-
 
2116
        $output = $stdout . $stderr;
-
 
2117
 
-
 
2118
        // Debug just in case the subprocess fails.
-
 
2119
        $this->assertSame(0, $exitcode);
-
 
2120
 
-
 
2121
        // Validate that both path-based and stored_file debugging messages are present.
-
 
2122
        $filename = "readfile_accel.txt";
-
 
2123
        $filepath = '/tmp/' . $filename;
-
 
2124
        $this->assertStringContainsString('Non-empty default output handler buffer detected while serving the file ' .
-
 
2125
            $filepath . '. Buffer contents (first 20 characters): test text', $output);
-
 
2126
        $this->assertStringContainsString('Non-empty default output handler buffer detected while serving the file ' .
-
 
2127
            $filename . '. Buffer contents (first 20 characters): test text', $output);
-
 
2128
    }
2047
}
2129
}
Línea 2048... Línea 2130...
2048
 
2130
 
2049
/**
2131
/**
2050
 * Test-specific class to allow easier testing of curl functions.
2132
 * Test-specific class to allow easier testing of curl functions.