Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #55 from Adnan0703/3.0
Browse files Browse the repository at this point in the history
deleteOldFileOnSave test
  • Loading branch information
burzum committed May 14, 2015
2 parents beb0630 + 137df41 commit 5cc5eff
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/TestCase/Model/Table/ImageStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,59 @@ public function testValidateImageSize() {
$result = $this->Image->validateImageSize($file, ['height' => ['<', 100]]);
$this->assertFalse($result);
}

/**
* testDeleteOldFileOnSave
*
* @return void
*/
public function testDeleteOldFileOnSave() {
$entity = $this->Image->newEntity([
'foreign_key' => 'test-1',
'model' => 'Test',
'file' => [
'name' => 'titus.jpg',
'size' => 332643,
'tmp_name' => Plugin::path('Burzum/FileStorage') . DS . 'tests' . DS . 'Fixture' . DS . 'File' . DS . 'titus.jpg',
'error' => 0
]
]);

$this->Image->save($entity);
$result = $this->Image->find()
->where([
'id' => $entity->id
])
->first();

$this->assertTrue(!empty($result) && is_a($result, '\Cake\ORM\Entity'));
$this->assertTrue(file_exists($this->testPath . $result['path']));

$oldImageFile = $this->testPath . $result['path'];
$secondEntity = $this->Image->newEntity([
'foreign_key' => 'test-1',
'model' => 'Test',
'file' => [
'name' => 'titus.jpg',
'size' => 332643,
'tmp_name' => Plugin::path('Burzum/FileStorage') . DS . 'tests' . DS . 'Fixture' . DS . 'File' . DS . 'titus.jpg',
'error' => 0
],
'old_file_id' => $entity->id
]);

$this->Image->save($secondEntity);
$result = $this->Image->find()
->where([
'id' => $secondEntity->id
])
->first();

$this->assertTrue(!empty($result) && is_a($result, '\Cake\ORM\Entity'));
$this->assertTrue(file_exists($this->testPath . $result['path']));

$Folder = new Folder($oldImageFile);
$folderResult = $Folder->read();
$this->assertEquals(count($folderResult[1]), 0);
}
}

0 comments on commit 5cc5eff

Please sign in to comment.