Révision cd5c298a
Ajouté par Geoffroy Desvernay il y a environ 5 ans
drupal7/modules/simpletest/tests/file.test | ||
---|---|---|
2766 | 2766 |
$this->assertTrue(file_stream_wrapper_valid_scheme(file_uri_scheme('public://asdf')), 'Got a valid stream scheme from public://asdf'); |
2767 | 2767 |
$this->assertFalse(file_stream_wrapper_valid_scheme(file_uri_scheme('foo://asdf')), 'Did not get a valid stream scheme from foo://asdf'); |
2768 | 2768 |
} |
2769 |
|
|
2770 |
/** |
|
2771 |
* Tests that phar stream wrapper is registered as expected. |
|
2772 |
* |
|
2773 |
* @see file_get_stream_wrappers() |
|
2774 |
*/ |
|
2775 |
public function testPharStreamWrapperRegistration() { |
|
2776 |
if (!class_exists('Phar', FALSE)) { |
|
2777 |
$this->assertFalse(in_array('phar', stream_get_wrappers(), TRUE), 'PHP is compiled without phar support. Therefore, no phar stream wrapper is registered.'); |
|
2778 |
} |
|
2779 |
elseif (version_compare(PHP_VERSION, '5.3.3', '<')) { |
|
2780 |
$this->assertFalse(in_array('phar', stream_get_wrappers(), TRUE), 'The PHP version is <5.3.3. The built-in phar stream wrapper has been unregistered and not replaced.'); |
|
2781 |
} |
|
2782 |
else { |
|
2783 |
$this->assertTrue(in_array('phar', stream_get_wrappers(), TRUE), 'A phar stream wrapper is registered.'); |
|
2784 |
$this->assertFalse(file_stream_wrapper_valid_scheme('phar'), 'The phar scheme is not a valid scheme for Drupal File API usage.'); |
|
2785 |
} |
|
2786 |
|
|
2787 |
// Ensure that calling file_get_stream_wrappers() multiple times, both |
|
2788 |
// without and with a drupal_static_reset() in between, does not create |
|
2789 |
// errors due to the PharStreamWrapperManager singleton. |
|
2790 |
file_get_stream_wrappers(); |
|
2791 |
file_get_stream_wrappers(); |
|
2792 |
drupal_static_reset('file_get_stream_wrappers'); |
|
2793 |
file_get_stream_wrappers(); |
|
2794 |
} |
|
2795 |
|
|
2796 |
/** |
|
2797 |
* Tests that only valid phar files can be used. |
|
2798 |
*/ |
|
2799 |
public function testPharFile() { |
|
2800 |
if (!in_array('phar', stream_get_wrappers(), TRUE)) { |
|
2801 |
$this->pass('There is no phar stream wrapper registered.'); |
|
2802 |
// Nothing else in this test is relevant when there's no phar stream |
|
2803 |
// wrapper. testPharStreamWrapperRegistration() is sufficient for testing |
|
2804 |
// the conditions of when the stream wrapper should or should not be |
|
2805 |
// registered. |
|
2806 |
return; |
|
2807 |
} |
|
2808 |
|
|
2809 |
$base = dirname(dirname(__FILE__)) . '/files'; |
|
2810 |
|
|
2811 |
// Ensure that file operations via the phar:// stream wrapper work for phar |
|
2812 |
// files with the .phar extension. |
|
2813 |
$this->assertFalse(file_exists("phar://$base/phar-1.phar/no-such-file.php")); |
|
2814 |
$this->assertTrue(file_exists("phar://$base/phar-1.phar/index.php")); |
|
2815 |
$file_contents = file_get_contents("phar://$base/phar-1.phar/index.php"); |
|
2816 |
$expected_hash = 'c7e7904ea573c5ebea3ef00bb08c1f86af1a45961fbfbeb1892ff4a98fd73ad5'; |
|
2817 |
$this->assertIdentical($expected_hash, hash('sha256', $file_contents)); |
|
2818 |
|
|
2819 |
// Ensure that file operations via the phar:// stream wrapper throw an |
|
2820 |
// exception for files without the .phar extension. |
|
2821 |
try { |
|
2822 |
file_exists("phar://$base/image-2.jpg/index.php"); |
|
2823 |
$this->fail('Expected exception failed to be thrown when accessing an invalid phar file.'); |
|
2824 |
} |
|
2825 |
catch (Exception $e) { |
|
2826 |
$this->assertEqual(get_class($e), 'TYPO3\PharStreamWrapper\Exception', 'Expected exception thrown when accessing an invalid phar file.'); |
|
2827 |
} |
|
2828 |
} |
|
2769 | 2829 |
} |
Formats disponibles : Unified diff
MAJ 7.60 -> 7.62