本文整理汇总了PHP中FileModel::getCount方法的典型用法代码示例。如果您正苦于以下问题:PHP FileModel::getCount方法的具体用法?PHP FileModel::getCount怎么用?PHP FileModel::getCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileModel
的用法示例。
在下文中一共展示了FileModel::getCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFileControllerActions
public function testFileControllerActions()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
$this->assertEquals(0, FileModel::getCount());
$pathToFiles = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files');
$filePath = $pathToFiles . DIRECTORY_SEPARATOR . 'testNote.txt';
$contents = file_get_contents($pathToFiles . DIRECTORY_SEPARATOR . 'testNote.txt');
//upload a file
$filePath = $pathToFiles . DIRECTORY_SEPARATOR . 'testNote.txt';
self::resetAndPopulateFilesArrayByFilePathAndName('aTest', $filePath, 'testNote.txt');
$this->resetPostArray();
$this->SetGetArray(array('filesVariableName' => 'aTest'));
$content = $this->runControllerWithExitExceptionAndGetContent('zurmo/fileModel/upload');
//Confirm the file has actually been uploaded
$files = FileModel::getAll();
// Begin Not Coding Standard
$compareJsonString = '[{"name":"testNote.txt","type":"text\\/plain","size":"6.34KB","id":' . $files[0]->id . ',"thumbnail_url":null}]';
// End Not Coding Standard
$this->assertEquals($compareJsonString, $content);
$fileModels = FileModel::getAll();
$this->assertEquals(1, count($fileModels));
$this->assertEquals($contents, $fileModels[0]->fileContent->content);
//add fileModel to a model.
$model = new ModelWithAttachmentTestItem();
$model->member = 'test';
$model->files->add($fileModels[0]);
$this->assertTrue($model->save());
$modelId = $model->id;
$model->forget();
//download a file.
$this->setGetArray(array('id' => $fileModels[0]->id, 'modelId' => $modelId, 'modelClassName' => 'ModelWithAttachmentTestItem'));
$this->resetPostArray();
$content = $this->runControllerWithExitExceptionAndGetContent('zurmo/fileModel/download');
$compareContent = 'Testing download.';
$this->assertEquals($compareContent, $content);
//todo: test all file errors.
//Test deleting a file.
$this->assertEquals(1, FileModel::getCount());
$this->assertEquals(1, FileContent::getCount());
$this->setGetArray(array('id' => $fileModels[0]->id));
$this->resetPostArray();
$this->runControllerWithNoExceptionsAndGetContent('zurmo/fileModel/delete', true);
//Now confirm that there are no file models or content in the system.
$this->assertEquals(0, FileModel::getCount());
$this->assertEquals(0, FileContent::getCount());
//Test GlobalSearchAutoComplete
$this->assertTrue(ContactsModule::loadStartingData());
$this->setGetArray(array('term' => 'something'));
$this->resetPostArray();
$content = $this->runControllerWithNoExceptionsAndGetContent('zurmo/default/globalSearchAutoComplete');
$compareContent = '[{"href":"","label":"No Results Found","iconClass":""}';
// Not Coding Standard
$this->assertContains($compareContent, $content);
}
示例2: testResolveModelsHasManyFilesFromPost
public function testResolveModelsHasManyFilesFromPost()
{
$fileCount = FileModel::getCount();
$this->assertEquals(0, $fileCount);
$file1 = ZurmoTestHelper::createFileModel('testNote.txt');
$file2 = ZurmoTestHelper::createFileModel('testNote.txt');
$file3 = ZurmoTestHelper::createFileModel('testNote.txt');
$model = new ModelWithAttachmentTestItem();
$_POST['myTest'] = array($file1->id, $file2->id, $file3->id);
FileModelUtil::resolveModelsHasManyFilesFromPost($model, 'files', 'myTest');
$model->member = 'test';
$saved = $model->save();
$this->assertTrue($saved);
$fileCount = FileModel::getCount();
$this->assertEquals(3, $fileCount);
$modelId = $model->id;
$model->forget();
$model = ModelWithAttachmentTestItem::getById($modelId);
$this->assertEquals(3, $model->files->count());
//Add a fourth file.
$file4 = ZurmoTestHelper::createFileModel('testNote.txt');
$_POST['myTest'] = array($file1->id, $file2->id, $file3->id, $file4->id);
FileModelUtil::resolveModelsHasManyFilesFromPost($model, 'files', 'myTest');
$saved = $model->save();
$this->assertTrue($saved);
$fileCount = FileModel::getCount();
$this->assertEquals(4, $fileCount);
$model->forget();
$model = ModelWithAttachmentTestItem::getById($modelId);
$this->assertEquals(4, $model->files->count());
//Remove the 2nd file.
$_POST['myTest'] = array($file1->id, $file3->id, $file4->id);
FileModelUtil::resolveModelsHasManyFilesFromPost($model, 'files', 'myTest');
$saved = $model->save();
$this->assertTrue($saved);
$fileCount = FileModel::getCount();
$this->assertEquals(3, $fileCount);
$model->forget();
$model = ModelWithAttachmentTestItem::getById($modelId);
$this->assertEquals(3, $model->files->count());
$compareIds = array($file1->id, $file3->id, $file4->id);
foreach ($model->files as $fileModel) {
$this->assertTrue(in_array($fileModel->id, $compareIds));
}
}
示例3: testDeleteAutoresponder
/**
* @depends testCreateAndGetAutoresponderById
*/
public function testDeleteAutoresponder()
{
$autoresponders = Autoresponder::getAll();
$this->assertCount(7, $autoresponders);
$autoresponderId = $autoresponders[0]->id;
$processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
$contact = ContactTestHelper::createContactByNameForOwner('autoresponderContact', Yii::app()->user->userModel);
$saved = AutoresponderItem::addNewItem(0, $processDateTime, $contact, $autoresponders[0]);
$this->assertTrue($saved);
$autoresponderItems = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderId);
$this->assertNotEmpty($autoresponderItems);
$this->assertCount(1, $autoresponderItems);
$fileNames = array('testImage.png', 'testZip.zip', 'testPDF.pdf');
$files = array();
foreach ($fileNames as $index => $fileName) {
$file = ZurmoTestHelper::createFileModel($fileName);
$files[$index]['name'] = $fileName;
$files[$index]['type'] = $file->type;
$files[$index]['size'] = $file->size;
$files[$index]['contents'] = $file->fileContent->content;
$autoresponders[0]->files->add($file);
}
$this->assertTrue($autoresponders[0]->save());
$autoresponders = Autoresponder::getAll();
$this->assertNotEmpty($autoresponders[0]->files);
$this->assertCount(count($files), $autoresponders[0]->files);
$this->assertEquals(count($files), FileModel::getCount());
$autoresponders[0]->delete();
$autoresponders = Autoresponder::getAll();
$this->assertEquals(6, count($autoresponders));
$autoresponderitems = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderId);
$this->assertEquals(0, count($autoresponderitems));
$this->assertEquals(0, FileModel::getCount());
}
示例4: testModelWithAttachmentTestItem
public function testModelWithAttachmentTestItem()
{
$pathToFiles = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files');
$filePath = $pathToFiles . DIRECTORY_SEPARATOR . 'testNote.txt';
// create 2 extra file model which should persist when $model is delete, their content should also persist.
$pdfFile = FileModelUtil::makeByFilePathAndName($filePath, 'testPDF.pdf');
$pdfFileId = $pdfFile->id;
$pdfFileName = $pdfFile->name;
$pdfFileContent = $pdfFile->fileContent->content;
$pdfFileType = $pdfFile->type;
$pdfFileSize = $pdfFile->size;
$pdfFile->forgetAll();
unset($pdfFile);
$zipFile = FileModelUtil::makeByFilePathAndName($filePath, 'testZip.zip');
$zipFileId = $zipFile->id;
$zipFileName = $zipFile->name;
$zipFileContent = $zipFile->fileContent->content;
$zipFileType = $zipFile->type;
$zipFileSize = $zipFile->size;
$zipFile->forgetAll();
unset($zipFile);
$model = new ModelWithAttachmentTestItem();
$fileModel = FileModelUtil::makeByFilePathAndName($filePath, 'testNote.txt');
$firstFileModelId = $fileModel->id;
$this->assertTrue($fileModel instanceof FileModel);
$this->assertEquals(6495, strlen($fileModel->fileContent->content));
$theContent = $fileModel->fileContent->content;
$model->files->add($fileModel);
$model->member = 'test';
$saved = $model->save();
$this->assertTrue($saved);
$modelId = $model->id;
$model->forget();
$model = ModelWithAttachmentTestItem::getById($modelId);
$this->assertEquals($theContent, $model->files[0]->fileContent->content);
$this->assertEquals('testNote.txt', $model->files[0]->name);
$this->assertEquals('text/plain', $model->files[0]->type);
$this->assertEquals(6495, $model->files[0]->size);
//Now try using CUploadedFile.
self::resetAndPopulateFilesArrayByFilePathAndName('aTest', $filePath, 'testNote.txt');
$uploadedFile = CUploadedFile::getInstanceByName('aTest');
$this->assertTrue($uploadedFile instanceof CUploadedFile);
$fileModel = FileModelUtil::makeByUploadedFile($uploadedFile);
$this->assertTrue($fileModel instanceof FileModel);
$this->assertTrue($fileModel->id != $firstFileModelId);
$this->assertTrue($fileModel->id > 0);
$model = ModelWithAttachmentTestItem::getById($modelId);
$model->files->add($fileModel);
$saved = $model->save();
$this->assertTrue($saved);
$modelId = $model->id;
$model->forget();
RedBeanModel::forgetAll();
$model = ModelWithAttachmentTestItem::getById($modelId);
$this->assertEquals(2, $model->files->count());
//Delete the model and confirm the related models are removed
$this->assertEquals(1, ModelWithAttachmentTestitem::getCount());
$this->assertEquals(4, FileModel::getCount());
$this->assertEquals(4, FileContent::getCount());
$this->assertTrue($model->delete());
$this->assertEquals(0, ModelWithAttachmentTestitem::getCount());
$this->assertEquals(2, FileModel::getCount());
$this->assertEquals(2, FileContent::getCount());
$pdfFile = FileModel::getById($pdfFileId);
$this->assertEquals($pdfFileContent, $pdfFile->fileContent->content);
$this->assertEquals($pdfFileName, $pdfFile->name);
$this->assertEquals($pdfFileType, $pdfFile->type);
$this->assertEquals($pdfFileSize, $pdfFile->size);
$zipFile = FileModel::getById($zipFileId);
$this->assertEquals($zipFileContent, $zipFile->fileContent->content);
$this->assertEquals($zipFileName, $zipFile->name);
$this->assertEquals($zipFileType, $zipFile->type);
$this->assertEquals($zipFileSize, $zipFile->size);
}