|
|
|
@ -43,7 +43,7 @@ class ActiveRecordTest extends MongoTestCase
|
|
|
|
|
'status' => $i, |
|
|
|
|
]; |
|
|
|
|
$content = 'content' . $i; |
|
|
|
|
$record['_id'] = $collection->storeBytes($content, $record); |
|
|
|
|
$record['_id'] = $collection->insertFileContent($content, $record); |
|
|
|
|
$record['content'] = $content; |
|
|
|
|
$rows[] = $record; |
|
|
|
|
} |
|
|
|
@ -116,4 +116,144 @@ class ActiveRecordTest extends MongoTestCase
|
|
|
|
|
$this->assertTrue($customers['1-1'] instanceof CustomerFile); |
|
|
|
|
$this->assertTrue($customers['2-2'] instanceof CustomerFile); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testInsert() |
|
|
|
|
{ |
|
|
|
|
$record = new CustomerFile; |
|
|
|
|
$record->tag = 'new new'; |
|
|
|
|
$record->status = 7; |
|
|
|
|
|
|
|
|
|
$this->assertTrue($record->isNewRecord); |
|
|
|
|
|
|
|
|
|
$record->save(); |
|
|
|
|
|
|
|
|
|
$this->assertTrue($record->_id instanceof \MongoId); |
|
|
|
|
$this->assertFalse($record->isNewRecord); |
|
|
|
|
|
|
|
|
|
$fileContent = $record->getFileContent(); |
|
|
|
|
$this->assertEmpty($fileContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @depends testInsert |
|
|
|
|
*/ |
|
|
|
|
public function testInsertFile() |
|
|
|
|
{ |
|
|
|
|
$record = new CustomerFile; |
|
|
|
|
$record->tag = 'new new'; |
|
|
|
|
$record->status = 7; |
|
|
|
|
|
|
|
|
|
$fileName = __FILE__; |
|
|
|
|
$record->setAttribute('file', $fileName); |
|
|
|
|
|
|
|
|
|
$record->save(); |
|
|
|
|
|
|
|
|
|
$this->assertTrue($record->_id instanceof \MongoId); |
|
|
|
|
$this->assertFalse($record->isNewRecord); |
|
|
|
|
|
|
|
|
|
$fileContent = $record->getFileContent(); |
|
|
|
|
$this->assertEquals(file_get_contents($fileName), $fileContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @depends testInsert |
|
|
|
|
*/ |
|
|
|
|
public function testInsertFileContent() |
|
|
|
|
{ |
|
|
|
|
$record = new CustomerFile; |
|
|
|
|
$record->tag = 'new new'; |
|
|
|
|
$record->status = 7; |
|
|
|
|
|
|
|
|
|
$newFileContent = 'Test new file content'; |
|
|
|
|
$record->setAttribute('newFileContent', $newFileContent); |
|
|
|
|
|
|
|
|
|
$record->save(); |
|
|
|
|
|
|
|
|
|
$this->assertTrue($record->_id instanceof \MongoId); |
|
|
|
|
$this->assertFalse($record->isNewRecord); |
|
|
|
|
|
|
|
|
|
$fileContent = $record->getFileContent(); |
|
|
|
|
$this->assertEquals($newFileContent, $fileContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @depends testInsert |
|
|
|
|
*/ |
|
|
|
|
public function testUpdate() |
|
|
|
|
{ |
|
|
|
|
$record = new CustomerFile; |
|
|
|
|
$record->tag = 'new new'; |
|
|
|
|
$record->status = 7; |
|
|
|
|
$record->save(); |
|
|
|
|
|
|
|
|
|
// save |
|
|
|
|
$record = CustomerFile::find($record->_id); |
|
|
|
|
$this->assertTrue($record instanceof CustomerFile); |
|
|
|
|
$this->assertEquals(7, $record->status); |
|
|
|
|
$this->assertFalse($record->isNewRecord); |
|
|
|
|
|
|
|
|
|
$record->status = 9; |
|
|
|
|
$record->save(); |
|
|
|
|
$this->assertEquals(9, $record->status); |
|
|
|
|
$this->assertFalse($record->isNewRecord); |
|
|
|
|
$record2 = CustomerFile::find($record->_id); |
|
|
|
|
$this->assertEquals(9, $record2->status); |
|
|
|
|
|
|
|
|
|
// updateAll |
|
|
|
|
$pk = ['_id' => $record->_id]; |
|
|
|
|
$ret = CustomerFile::updateAll(['status' => 55], $pk); |
|
|
|
|
$this->assertEquals(1, $ret); |
|
|
|
|
$record = CustomerFile::find($pk); |
|
|
|
|
$this->assertEquals(55, $record->status); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @depends testUpdate |
|
|
|
|
* @depends testInsertFileContent |
|
|
|
|
*/ |
|
|
|
|
public function testUpdateFile() |
|
|
|
|
{ |
|
|
|
|
$record = new CustomerFile; |
|
|
|
|
$record->tag = 'new new'; |
|
|
|
|
$record->status = 7; |
|
|
|
|
$newFileContent = 'Test new file content'; |
|
|
|
|
$record->setAttribute('newFileContent', $newFileContent); |
|
|
|
|
$record->save(); |
|
|
|
|
|
|
|
|
|
$updateFileName = __FILE__; |
|
|
|
|
$record = CustomerFile::find($record->_id); |
|
|
|
|
$record->setAttribute('file', $updateFileName); |
|
|
|
|
$record->status = 55; |
|
|
|
|
$record->save(); |
|
|
|
|
$this->assertEquals(file_get_contents($updateFileName), $record->getFileContent()); |
|
|
|
|
|
|
|
|
|
$record2 = CustomerFile::find($record->_id); |
|
|
|
|
$this->assertEquals($record->status, $record2->status); |
|
|
|
|
$this->assertEquals(file_get_contents($updateFileName), $record2->getFileContent()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @depends testUpdate |
|
|
|
|
* @depends testInsertFileContent |
|
|
|
|
*/ |
|
|
|
|
public function testUpdateFileContent() |
|
|
|
|
{ |
|
|
|
|
$record = new CustomerFile; |
|
|
|
|
$record->tag = 'new new'; |
|
|
|
|
$record->status = 7; |
|
|
|
|
$newFileContent = 'Test new file content'; |
|
|
|
|
$record->setAttribute('newFileContent', $newFileContent); |
|
|
|
|
$record->save(); |
|
|
|
|
|
|
|
|
|
$updateFileContent = 'New updated file content'; |
|
|
|
|
$record = CustomerFile::find($record->_id); |
|
|
|
|
$record->setAttribute('newFileContent', $updateFileContent); |
|
|
|
|
$record->status = 55; |
|
|
|
|
$record->save(); |
|
|
|
|
$this->assertEquals($updateFileContent, $record->getFileContent()); |
|
|
|
|
|
|
|
|
|
$record2 = CustomerFile::find($record->_id); |
|
|
|
|
$this->assertEquals($record->status, $record2->status); |
|
|
|
|
$this->assertEquals($updateFileContent, $record2->getFileContent()); |
|
|
|
|
} |
|
|
|
|
} |