You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.3 KiB
98 lines
2.3 KiB
11 years ago
|
<?php
|
||
|
|
||
11 years ago
|
namespace yiiunit\extensions\mongodb\file;
|
||
11 years ago
|
|
||
11 years ago
|
use yiiunit\extensions\mongodb\MongoDbTestCase;
|
||
11 years ago
|
|
||
11 years ago
|
/**
|
||
|
* @group mongo
|
||
|
*/
|
||
11 years ago
|
class CollectionTest extends MongoDbTestCase
|
||
11 years ago
|
{
|
||
|
protected function tearDown()
|
||
|
{
|
||
|
$this->dropFileCollection('fs');
|
||
|
parent::tearDown();
|
||
|
}
|
||
|
|
||
|
// Tests :
|
||
|
|
||
11 years ago
|
public function testGetChunkCollection()
|
||
|
{
|
||
|
$collection = $this->getConnection()->getFileCollection();
|
||
|
$chunkCollection = $collection->getChunkCollection();
|
||
11 years ago
|
$this->assertTrue($chunkCollection instanceof \yii\mongodb\Collection);
|
||
11 years ago
|
$this->assertTrue($chunkCollection->mongoCollection instanceof \MongoCollection);
|
||
|
}
|
||
|
|
||
11 years ago
|
public function testFind()
|
||
|
{
|
||
|
$collection = $this->getConnection()->getFileCollection();
|
||
|
$cursor = $collection->find();
|
||
|
$this->assertTrue($cursor instanceof \MongoGridFSCursor);
|
||
|
}
|
||
|
|
||
11 years ago
|
public function testInsertFile()
|
||
11 years ago
|
{
|
||
|
$collection = $this->getConnection()->getFileCollection();
|
||
|
|
||
|
$filename = __FILE__;
|
||
11 years ago
|
$id = $collection->insertFile($filename);
|
||
11 years ago
|
$this->assertTrue($id instanceof \MongoId);
|
||
|
|
||
|
$files = $this->findAll($collection);
|
||
|
$this->assertEquals(1, count($files));
|
||
|
|
||
|
/** @var $file \MongoGridFSFile */
|
||
|
$file = $files[0];
|
||
|
$this->assertEquals($filename, $file->getFilename());
|
||
|
$this->assertEquals(file_get_contents($filename), $file->getBytes());
|
||
|
}
|
||
|
|
||
11 years ago
|
public function testInsertFileContent()
|
||
11 years ago
|
{
|
||
|
$collection = $this->getConnection()->getFileCollection();
|
||
|
|
||
|
$bytes = 'Test file content';
|
||
11 years ago
|
$id = $collection->insertFileContent($bytes);
|
||
11 years ago
|
$this->assertTrue($id instanceof \MongoId);
|
||
|
|
||
|
$files = $this->findAll($collection);
|
||
|
$this->assertEquals(1, count($files));
|
||
|
|
||
|
/** @var $file \MongoGridFSFile */
|
||
|
$file = $files[0];
|
||
|
$this->assertEquals($bytes, $file->getBytes());
|
||
|
}
|
||
|
|
||
|
/**
|
||
11 years ago
|
* @depends testInsertFileContent
|
||
11 years ago
|
*/
|
||
|
public function testGet()
|
||
|
{
|
||
|
$collection = $this->getConnection()->getFileCollection();
|
||
|
|
||
|
$bytes = 'Test file content';
|
||
11 years ago
|
$id = $collection->insertFileContent($bytes);
|
||
11 years ago
|
|
||
|
$file = $collection->get($id);
|
||
|
$this->assertTrue($file instanceof \MongoGridFSFile);
|
||
|
$this->assertEquals($bytes, $file->getBytes());
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @depends testGet
|
||
|
*/
|
||
|
public function testDelete()
|
||
|
{
|
||
|
$collection = $this->getConnection()->getFileCollection();
|
||
|
|
||
|
$bytes = 'Test file content';
|
||
11 years ago
|
$id = $collection->insertFileContent($bytes);
|
||
11 years ago
|
|
||
|
$this->assertTrue($collection->delete($id));
|
||
|
|
||
|
$file = $collection->get($id);
|
||
|
$this->assertNull($file);
|
||
|
}
|
||
|
}
|