Index: trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php |
— | — | @@ -779,6 +779,67 @@ |
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
| 783 | + * @dataProvider provider_testGetFileStat |
| 784 | + */ |
| 785 | + public function testGetFileStat( $path, $content, $alreadyExists ) { |
| 786 | + $this->backend = $this->singleBackend; |
| 787 | + $this->tearDownFiles(); |
| 788 | + $this->doTestGetFileStat( $path, $content, $alreadyExists ); |
| 789 | + $this->tearDownFiles(); |
| 790 | + |
| 791 | + $this->backend = $this->multiBackend; |
| 792 | + $this->tearDownFiles(); |
| 793 | + $this->doTestGetFileStat( $path, $content, $alreadyExists ); |
| 794 | + $this->tearDownFiles(); |
| 795 | + } |
| 796 | + |
| 797 | + private function doTestGetFileStat( $path, $content, $alreadyExists ) { |
| 798 | + $backendName = $this->backendClass(); |
| 799 | + |
| 800 | + if ( $alreadyExists ) { |
| 801 | + $this->prepare( array( 'dir' => dirname( $path ) ) ); |
| 802 | + $status = $this->backend->create( array( 'dst' => $path, 'content' => $content ) ); |
| 803 | + $this->assertEquals( array(), $status->errors, |
| 804 | + "Creation of file at $path succeeded ($backendName)." ); |
| 805 | + |
| 806 | + $size = $this->backend->getFileSize( array( 'src' => $path ) ); |
| 807 | + $time = $this->backend->getFileTimestamp( array( 'src' => $path ) ); |
| 808 | + $stat = $this->backend->getFileStat( array( 'src' => $path ) ); |
| 809 | + |
| 810 | + $this->assertEquals( strlen( $content ), $size, |
| 811 | + "Correct file size of '$path'" ); |
| 812 | + $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 5, |
| 813 | + "Correct file timestamp of '$path'" ); |
| 814 | + |
| 815 | + $size = $stat['size']; |
| 816 | + $time = $stat['mtime']; |
| 817 | + $this->assertEquals( strlen( $content ), $size, |
| 818 | + "Correct file size of '$path'" ); |
| 819 | + $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 5, |
| 820 | + "Correct file timestamp of '$path'" ); |
| 821 | + } else { |
| 822 | + $size = $this->backend->getFileSize( array( 'src' => $path ) ); |
| 823 | + $time = $this->backend->getFileTimestamp( array( 'src' => $path ) ); |
| 824 | + $stat = $this->backend->getFileStat( array( 'src' => $path ) ); |
| 825 | + |
| 826 | + $this->assertFalse( $size, "Correct file size of '$path'" ); |
| 827 | + $this->assertFalse( $time, "Correct file timestamp of '$path'" ); |
| 828 | + $this->assertFalse( $stat, "Correct file stat of '$path'" ); |
| 829 | + } |
| 830 | + } |
| 831 | + |
| 832 | + function provider_testGetFileStat() { |
| 833 | + $cases = array(); |
| 834 | + |
| 835 | + $base = $this->baseStorePath(); |
| 836 | + $cases[] = array( "$base/unittest-cont1/b/z/some_file.txt", "some file contents", true ); |
| 837 | + $cases[] = array( "$base/unittest-cont1/b/some-other_file.txt", "", true ); |
| 838 | + $cases[] = array( "$base/unittest-cont1/b/some-diff_file.txt", null, false ); |
| 839 | + |
| 840 | + return $cases; |
| 841 | + } |
| 842 | + |
| 843 | + /** |
783 | 844 | * @dataProvider provider_testGetFileContents |
784 | 845 | */ |
785 | 846 | public function testGetFileContents( $source, $content ) { |
— | — | @@ -793,9 +854,6 @@ |
794 | 855 | $this->tearDownFiles(); |
795 | 856 | } |
796 | 857 | |
797 | | - /** |
798 | | - * @dataProvider provider_testGetFileContents |
799 | | - */ |
800 | 858 | public function doTestGetFileContents( $source, $content ) { |
801 | 859 | $backendName = $this->backendClass(); |
802 | 860 | |