public function testCreateWithFilenameWithSubfolder() { // Note: We can't use fixtures/setUp() for this, as we want to create the db record manually. // Creating the folder is necessary to avoid having "Filename" overwritten by setName()/setRelativePath(), // because the parent folders don't exist in the database $folder = Folder::find_or_make('/FileTest/'); $testfilePath = BASE_PATH . '/assets/FileTest/CreateWithFilenameHasCorrectPath.txt'; // Important: No leading slash $fh = fopen($testfilePath, "w"); fwrite($fh, str_repeat('x', 1000000)); fclose($fh); $file = new File(); $file->setFromLocalFile($testfilePath); $file->ParentID = $folder->ID; $file->write(); $this->assertEquals('CreateWithFilenameHasCorrectPath.txt', $file->Name, '"Name" property is automatically set from "Filename"'); $this->assertEquals('FileTest/CreateWithFilenameHasCorrectPath.txt', $file->Filename, '"Filename" property remains unchanged'); // TODO This should be auto-detected, see File->updateFilesystem() // $this->assertInstanceOf('Folder', $file->Parent(), 'Parent folder is created in database'); // $this->assertFileExists($file->Parent()->getURL(), 'Parent folder is created on filesystem'); // $this->assertEquals('FileTest', $file->Parent()->Name); // $this->assertInstanceOf('Folder', $file->Parent()->Parent(), 'Grandparent folder is created in database'); // $this->assertFileExists($file->Parent()->Parent()->getURL(), // 'Grandparent folder is created on filesystem'); // $this->assertEquals('assets', $file->Parent()->Parent()->Name); }