protected function setImage($imageId) { $id = (int) $imageId; if ($id > 0) { try { $image = ImageFileModel::getById($id); $this->image = $image; } catch (NotFoundException $exception) { //Do nothing } } }
public function testGetImageSummaryWhenThereIsNoCachedFile() { Yii::app()->user->userModel = User::getByUsername('super'); $pathToFiles = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files'); $filePath = $pathToFiles . DIRECTORY_SEPARATOR . 'testImage.png'; $fileUploadData = ImageFileModelUtil::saveImageFromTemporaryFile($filePath, 'fileNameTest'); $id = $fileUploadData['id']; $imageFileModel = ImageFileModel::getById($id); $imageFileModel->width = null; $imageFileModel->height = null; $this->assertTrue($imageFileModel->save()); unlink(ImageFileModel::getImageCachePathByFileName($imageFileModel->getImageCacheFileName(), false)); ImageFileModelUtil::getImageSummary($imageFileModel); }
public function testCreateImageCache() { $pathToFiles = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files'); $fileContents = file_get_contents($pathToFiles . DIRECTORY_SEPARATOR . 'testImage.png'); $imageFile = ImageFileModel::getById($this->imageFile1Id); if (file_exists($imageFile->getImageCachePath())) { unlink($imageFile->getImageCachePath()); } if (file_exists($imageFile->getImageCachePath(true))) { unlink($imageFile->getImageCachePath(true)); } $this->assertEquals($fileContents, $imageFile->fileContent->content); $this->assertEquals('testImage.png', $imageFile->name); $this->assertEquals('image/png', $imageFile->type); $this->assertEquals(3332, $imageFile->size); $this->assertFalse(file_exists($imageFile->getImageCachePath())); $this->assertFalse(file_exists($imageFile->getImageCachePath(true))); //Now cache the image without the creation of the thumb $imageFile->createImageCache(); $this->assertTrue(file_exists($imageFile->getImageCachePath())); $this->assertFalse(file_exists($imageFile->getImageCachePath(true))); //Now cache the image and create the thumb $imageFile->createImageCache(true); $this->assertTrue(file_exists($imageFile->getImageCachePath())); $this->assertTrue(file_exists($imageFile->getImageCachePath(true))); }
public function actionToggle($id, $attribute) { if (Yii::app()->request->isAjaxRequest && Yii::app()->request->isPostRequest) { $imageFile = ImageFileModel::getById((int) $id); $imageFile->toggle($attribute); } }
public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $imageFile = ImageFileModel::getById($this->imageFile1Id); if (file_exists($imageFile->getImageCachePath())) { unlink($imageFile->getImageCachePath()); } if (file_exists($imageFile->getImageCachePath(true))) { unlink($imageFile->getImageCachePath(true)); } //Test all default controller actions that do not require any POST/GET variables to be passed. //This does not include portlet controller actions. $content = $this->runControllerWithNoExceptionsAndGetContent('zurmo/imageModel/getUploaded'); $returnedObject = CJSON::decode($content); $this->assertContains('zurmo/imageModel/getImage?fileName=' . $imageFile->getImageCacheFileName(), $returnedObject[0]['image']); $this->assertContains('zurmo/imageModel/getThumb?fileName=' . $imageFile->getImageCacheFileName(), $returnedObject[0]['thumb']); $this->assertFalse(file_exists($imageFile->getImageCachePath())); $this->assertFalse(file_exists($imageFile->getImageCachePath(true))); //Test getting the image $this->setGetArray(array('fileName' => $imageFile->getImageCacheFileName())); @$this->runControllerWithExitExceptionAndGetContent('zurmo/imageModel/getImage'); $this->assertTrue(file_exists($imageFile->getImageCachePath())); $this->assertFalse(file_exists($imageFile->getImageCachePath(true))); //Test getting the image thumb $this->setGetArray(array('fileName' => $imageFile->getImageCacheFileName())); @$this->runControllerWithExitExceptionAndGetContent('zurmo/imageModel/getThumb'); $this->assertTrue(file_exists($imageFile->getImageCachePath())); $this->assertTrue(file_exists($imageFile->getImageCachePath(true))); //Test uploading invalid image $pathToFiles = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files'); $filePath = $pathToFiles . DIRECTORY_SEPARATOR . 'testNote.txt'; self::resetAndPopulateFilesArrayByFilePathAndName('file', $filePath, 'testNote.txt'); $content = $this->runControllerWithNoExceptionsAndGetContent('zurmo/imageModel/upload'); $returnedObject = CJSON::decode($content); $this->assertEquals('Error uploading the image', $returnedObject[0]['error']); //Test uploading valid image $pathToFiles = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files'); $fileContents = file_get_contents($pathToFiles . DIRECTORY_SEPARATOR . 'testImage.png'); $filePath = $pathToFiles . DIRECTORY_SEPARATOR . 'testImage.png'; self::resetAndPopulateFilesArrayByFilePathAndName('file', $filePath, 'testImage.png'); $content = $this->runControllerWithNoExceptionsAndGetContent('zurmo/imageModel/upload'); $returnedObject = CJSON::decode($content); $this->assertContains('zurmo/imageModel/getImage?fileName=2_testImage.png', $returnedObject[0]['filelink']); // Not Coding Standard $createdImageFile = ImageFileModel::getById(2); $this->assertEquals($fileContents, $createdImageFile->fileContent->content); //Test deleting image $createdImageFile->inactive = false; $this->setGetArray(array('id' => 2)); $this->runControllerWithNoExceptionsAndGetContent('zurmo/imageModel/delete', true); RedBeanModel::forgetAll(); $deletedImageFile = ImageFileModel::getById(2); $deletedImageFile->inactive = true; }