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
			| 
											12 years ago
										 | <?php
 | ||
|  | 
 | ||
| 
											12 years ago
										 | namespace yiiunit\extensions\mongodb\file;
 | ||
| 
											12 years ago
										 | 
 | ||
| 
											12 years ago
										 | use yiiunit\extensions\mongodb\MongoDbTestCase;
 | ||
| 
											12 years ago
										 | 
 | ||
| 
											12 years ago
										 | /**
 | ||
|  |  * @group mongo
 | ||
|  |  */
 | ||
| 
											12 years ago
										 | class CollectionTest extends MongoDbTestCase
 | ||
| 
											12 years ago
										 | {
 | ||
|  | 	protected function tearDown()
 | ||
|  | 	{
 | ||
|  | 		$this->dropFileCollection('fs');
 | ||
|  | 		parent::tearDown();
 | ||
|  | 	}
 | ||
|  | 
 | ||
|  | 	// Tests :
 | ||
|  | 
 | ||
| 
											12 years ago
										 | 	public function testGetChunkCollection()
 | ||
|  | 	{
 | ||
|  | 		$collection = $this->getConnection()->getFileCollection();
 | ||
|  | 		$chunkCollection = $collection->getChunkCollection();
 | ||
| 
											12 years ago
										 | 		$this->assertTrue($chunkCollection instanceof \yii\mongodb\Collection);
 | ||
| 
											12 years ago
										 | 		$this->assertTrue($chunkCollection->mongoCollection instanceof \MongoCollection);
 | ||
|  | 	}
 | ||
|  | 
 | ||
| 
											12 years ago
										 | 	public function testFind()
 | ||
|  | 	{
 | ||
|  | 		$collection = $this->getConnection()->getFileCollection();
 | ||
|  | 		$cursor = $collection->find();
 | ||
|  | 		$this->assertTrue($cursor instanceof \MongoGridFSCursor);
 | ||
|  | 	}
 | ||
|  | 
 | ||
| 
											12 years ago
										 | 	public function testInsertFile()
 | ||
| 
											12 years ago
										 | 	{
 | ||
|  | 		$collection = $this->getConnection()->getFileCollection();
 | ||
|  | 
 | ||
|  | 		$filename = __FILE__;
 | ||
| 
											12 years ago
										 | 		$id = $collection->insertFile($filename);
 | ||
| 
											12 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());
 | ||
|  | 	}
 | ||
|  | 
 | ||
| 
											12 years ago
										 | 	public function testInsertFileContent()
 | ||
| 
											12 years ago
										 | 	{
 | ||
|  | 		$collection = $this->getConnection()->getFileCollection();
 | ||
|  | 
 | ||
|  | 		$bytes = 'Test file content';
 | ||
| 
											12 years ago
										 | 		$id = $collection->insertFileContent($bytes);
 | ||
| 
											12 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());
 | ||
|  | 	}
 | ||
|  | 
 | ||
|  | 	/**
 | ||
| 
											12 years ago
										 | 	 * @depends testInsertFileContent
 | ||
| 
											12 years ago
										 | 	 */
 | ||
|  | 	public function testGet()
 | ||
|  | 	{
 | ||
|  | 		$collection = $this->getConnection()->getFileCollection();
 | ||
|  | 
 | ||
|  | 		$bytes = 'Test file content';
 | ||
| 
											12 years ago
										 | 		$id = $collection->insertFileContent($bytes);
 | ||
| 
											12 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';
 | ||
| 
											12 years ago
										 | 		$id = $collection->insertFileContent($bytes);
 | ||
| 
											12 years ago
										 | 
 | ||
|  | 		$this->assertTrue($collection->delete($id));
 | ||
|  | 
 | ||
|  | 		$file = $collection->get($id);
 | ||
|  | 		$this->assertNull($file);
 | ||
|  | 	}
 | ||
|  | }
 |