Beispiel #1
0
 public function testFileProcessing()
 {
     foreach (File::find() as $file) {
         $file->delete();
     }
     foreach (Foo::find() as $foo) {
         $foo->delete();
     }
     $mappingManager = new MappingManager();
     $fileMapper = new \Vegas\Media\Db\Mapping\File(new File());
     $mappingManager->add($fileMapper);
     $fooFile = $this->mockFile(true);
     $this->mockFooRecord($fooFile);
     $foo = Foo::findFirst();
     $mappedRecord = $foo->readMapped('image');
     MediaHelper::moveFilesFrom($mappedRecord);
     MediaHelper::generateThumbnailsFrom((array) $mappedRecord, ['width' => 600, 'height' => 300]);
     foreach ($mappedRecord as $file) {
         $testFile = $file->getRecord();
         $this->assertTrue(!$testFile->is_temp);
         $this->assertTrue(file_exists($testFile->original_destination . '/' . $testFile->temp_name));
         $this->assertTrue(file_exists($testFile->original_destination . '/thumbnails/' . '600_300_' . $testFile->temp_name));
         //delete created thumbnails for next test
         unlink($testFile->original_destination . '/thumbnails/' . '600_300_' . $testFile->temp_name);
         //undo file moving the file for next test
         rename($testFile->original_destination . '/' . $testFile->temp_name, $testFile->temp_destination . '/' . $testFile->temp_name);
     }
 }
Beispiel #2
0
 public function testMapper()
 {
     foreach (File::find() as $file) {
         $file->delete();
     }
     foreach (Foo::find() as $foo) {
         $foo->delete();
     }
     $mappingManager = new MappingManager();
     $fileMapper = new \Vegas\Media\Db\Mapping\File(new File());
     $mappingManager->add($fileMapper);
     $fooFile = $this->mockFile(false);
     $this->mockFooRecord($fooFile);
     $foo = Foo::findFirst();
     $this->assertInstanceOf('\\ArrayObject', $foo->readMapped('image'));
     $this->assertCount(1, $foo->readMapped('image'));
     $this->assertInternalType('array', $foo->readMapped('image')->getArrayCopy());
     $this->assertInstanceOf('\\Vegas\\Media\\File\\Decorator', $foo->readMapped('image')[0]);
     $this->assertInstanceOf('\\Vegas\\Media\\File\\Decorator', $foo->readMapped('image')->offsetGet(0));
     $this->assertEquals('origin.jpg', $foo->readMapped('image')[0]->getRecord()->name);
     $this->assertTrue($foo->readMapped('image')[0]->save());
     $this->assertEquals($fooFile->getId(), $foo->readMapped('image')[0]->getRecord()->getId());
     $this->assertEquals('/origin/temp.jpg', $foo->readMapped('image')[0]->getPath());
     $this->assertEquals('/origin/temp.jpg', $foo->readMapped('image')[0]->getUrl());
     $this->assertInstanceOf('\\SplFileInfo', $foo->readMapped('image')[0]->getFileInfo());
     $this->assertEquals('/origin/thumbnails/100_100_temp.jpg', $foo->readMapped('image')[0]->getThumbnailUrl(100, 100));
     $this->assertEquals('/origin/thumbnails/100_100_temp.jpg', $foo->readMapped('image')[0]->getThumbnailPath(100, 100));
     $this->assertTrue($foo->readMapped('image')[0]->delete());
     $this->assertCount(0, $foo->readMapped('image'));
 }
Beispiel #3
0
 protected function initDbMappings()
 {
     $mappingManager = new MappingManager();
     $mappingManager->add(new Json());
 }
Beispiel #4
0
 public function testShouldPrintDecimalValue()
 {
     $mappingManager = new MappingManager();
     $mappingManager->add(new Decimal());
     $fake = new Fake();
     $fake->currency = 987654.0321;
     $this->assertInternalType('string', $fake->readMapped('currency'));
     $this->assertEquals('987654.03', $fake->readMapped('currency'));
     $fake->currency = 7123.4;
     $this->assertInternalType('string', $fake->readMapped('currency'));
     $this->assertEquals('7123.40', $fake->readMapped('currency'));
 }