Exemplo n.º 1
0
 public function testGetFile()
 {
     $fs = new SymfonyFileSystem();
     $someJunk = 'whatever dude';
     $hash = md5($someJunk);
     $testFilePath = $this->uploadDirectory . '/' . $hash;
     file_put_contents($testFilePath, $someJunk);
     $file = m::mock('Symfony\\Component\\HttpFoundation\\File\\File')->shouldReceive('getPathname')->andReturn($testFilePath)->getMock();
     $this->mockFileSystem->shouldReceive('exists')->with($testFilePath)->andReturn(true);
     $this->mockFileSystem->shouldReceive('move');
     $newHash = $this->tempFileSystem->storeFile($file, false);
     $newFile = $this->tempFileSystem->getFile($newHash);
     $this->assertSame($hash, $newHash);
     $this->assertSame(file_get_contents($newFile->getPathname()), $someJunk);
 }
Exemplo n.º 2
0
 public function testCheckLearningMaterialFilePath()
 {
     $goodLm = m::mock('Ilios\\CoreBundle\\Entity\\LearningMaterial')->shouldReceive('getRelativePath')->andReturn('goodfile')->mock();
     $badLm = m::mock('Ilios\\CoreBundle\\Entity\\LearningMaterial')->shouldReceive('getRelativePath')->andReturn('badfile')->mock();
     $this->mockFileSystem->shouldReceive('exists')->with($this->fakeTestFileDir . '/goodfile')->andReturn(true)->once();
     $this->mockFileSystem->shouldReceive('exists')->with($this->fakeTestFileDir . '/badfile')->andReturn(false)->once();
     $this->assertTrue($this->iliosFileSystem->checkLearningMaterialFilePath($goodLm));
     $this->assertFalse($this->iliosFileSystem->checkLearningMaterialFilePath($badLm));
 }
Exemplo n.º 3
0
 public function testGetFile()
 {
     $fs = new SymfonyFileSystem();
     $someJunk = 'whatever dude';
     $hash = md5($someJunk);
     $hashDirectory = substr($hash, 0, 2);
     $parts = [$this->fakeTestFileDir, 'learning_materials', 'lm', $hashDirectory];
     $dir = implode($parts, '/');
     $fs->mkdir($dir);
     $testFilePath = $dir . '/' . $hash;
     file_put_contents($testFilePath, $someJunk);
     $file = m::mock('Symfony\\Component\\HttpFoundation\\File\\File')->shouldReceive('getPathname')->andReturn($testFilePath)->getMock();
     $this->mockFileSystem->shouldReceive('exists')->with($testFilePath)->andReturn(true);
     $this->mockFileSystem->shouldReceive('mkdir');
     $newPath = $this->iliosFileSystem->storeLearningMaterialFile($file, false);
     $newFile = $this->iliosFileSystem->getFile($newPath);
     $this->assertSame($newFile->getPathname(), $testFilePath);
     $this->assertSame(file_get_contents($newFile->getPathname()), $someJunk);
     $fs->remove($this->fakeTestFileDir . '/learning_materials');
 }