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.
		
		
		
		
			
				
					70 lines
				
				1.4 KiB
			
		
		
			
		
	
	
					70 lines
				
				1.4 KiB
			| 
								 
											12 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								namespace yiiunit\extensions\mongodb\file;
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								use yii\mongodb\file\Query;
							 | 
						||
| 
								 | 
							
								use yiiunit\extensions\mongodb\MongoDbTestCase;
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @group mongo
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								class QueryTest extends MongoDbTestCase
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								{
							 | 
						||
| 
								 | 
							
									protected function setUp()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										parent::setUp();
							 | 
						||
| 
								 | 
							
										$this->setUpTestRows();
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									protected function tearDown()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										$this->dropFileCollection();
							 | 
						||
| 
								 | 
							
										parent::tearDown();
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * Sets up test rows.
							 | 
						||
| 
								 | 
							
									 */
							 | 
						||
| 
								 | 
							
									protected function setUpTestRows()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										$collection = $this->getConnection()->getFileCollection();
							 | 
						||
| 
								 | 
							
										for ($i = 1; $i <= 10; $i++) {
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
											$collection->insertFileContent('content' . $i, [
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
												'filename' => 'name' . $i,
							 | 
						||
| 
								 | 
							
												'file_index' => $i,
							 | 
						||
| 
								 | 
							
											]);
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
										}
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									// Tests :
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									public function testAll()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										$connection = $this->getConnection();
							 | 
						||
| 
								 | 
							
										$query = new Query;
							 | 
						||
| 
								 | 
							
										$rows = $query->from('fs')->all($connection);
							 | 
						||
| 
								 | 
							
										$this->assertEquals(10, count($rows));
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									public function testOne()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										$connection = $this->getConnection();
							 | 
						||
| 
								 | 
							
										$query = new Query;
							 | 
						||
| 
								 | 
							
										$row = $query->from('fs')->one($connection);
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
										$this->assertTrue(is_array($row));
							 | 
						||
| 
								 | 
							
										$this->assertTrue($row['file'] instanceof \MongoGridFSFile);
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
									}
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
									public function testDirectMatch()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										$connection = $this->getConnection();
							 | 
						||
| 
								 | 
							
										$query = new Query;
							 | 
						||
| 
								 | 
							
										$rows = $query->from('fs')
							 | 
						||
| 
								 | 
							
											->where(['file_index' => 5])
							 | 
						||
| 
								 | 
							
											->all($connection);
							 | 
						||
| 
								 | 
							
										$this->assertEquals(1, count($rows));
							 | 
						||
| 
								 | 
							
										/** @var $file \MongoGridFSFile */
							 | 
						||
| 
								 | 
							
										$file = $rows[0];
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
										$this->assertEquals('name5', $file['filename']);
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
									}
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								}
							 |