_plugin = new Solarium_Plugin_BufferedAdd(); $this->_plugin->init(new Solarium_Client(), array()); } public function testSetAndGetBufferSize() { $this->_plugin->setBufferSize(500); $this->assertEquals(500, $this->_plugin->getBufferSize()); } public function testAddDocument() { $doc = new Solarium_Document_ReadWrite(); $doc->id = '123'; $doc->name = 'test'; $this->_plugin->addDocument($doc); $this->assertEquals(array($doc), $this->_plugin->getDocuments()); } public function testCreateDocument() { $data = array('id' => '123', 'name' => 'test'); $doc = new Solarium_Document_ReadWrite($data); $this->_plugin->createDocument($data); $this->assertEquals(array($doc), $this->_plugin->getDocuments()); } public function testAddDocuments() { $doc1 = new Solarium_Document_ReadWrite(); $doc1->id = '123'; $doc1->name = 'test'; $doc2 = new Solarium_Document_ReadWrite(); $doc2->id = '234'; $doc2->name = 'test2'; $docs = array($doc1, $doc2); $this->_plugin->addDocuments($docs); $this->assertEquals($docs, $this->_plugin->getDocuments()); } public function testAddDocumentAutoFlush() { $observer = $this->getMock('Solarium_Plugin_BufferedAdd', array('flush')); $observer->expects($this->once())->method('flush'); $observer->setBufferSize(1); $doc1 = new Solarium_Document_ReadWrite(); $doc1->id = '123'; $doc1->name = 'test'; $doc2 = new Solarium_Document_ReadWrite(); $doc2->id = '234'; $doc2->name = 'test2'; $docs = array($doc1, $doc2); $observer->addDocuments($docs); } public function testClear() { $doc = new Solarium_Document_ReadWrite(); $doc->id = '123'; $doc->name = 'test'; $this->_plugin->addDocument($doc); $this->_plugin->clear(); $this->assertEquals(array(), $this->_plugin->getDocuments()); } public function testFlushEmptyBuffer() { $this->assertEquals(false, $this->_plugin->flush()); } public function testFlush() { $data = array('id' => '123', 'name' => 'test'); $doc = new Solarium_Document_ReadWrite($data); $mockUpdate = $this->getMock('Solarium_Query_Update', array('addDocuments')); $mockUpdate->expects($this->once())->method('addDocuments')->with($this->equalTo(array($doc)),$this->equalTo(true),$this->equalTo(12)); $mockClient = $this->getMock('Solarium_Client', array('createUpdate', 'update', 'triggerEvent')); $mockClient->expects($this->exactly(2))->method('createUpdate')->will($this->returnValue($mockUpdate)); $mockClient->expects($this->once())->method('update')->will($this->returnValue('dummyResult')); $mockClient->expects($this->exactly(2))->method('triggerEvent'); $plugin = new Solarium_Plugin_BufferedAdd(); $plugin->init($mockClient, array()); $plugin->addDocument($doc); $this->assertEquals('dummyResult', $plugin->flush(true,12)); } public function testCommit() { $data = array('id' => '123', 'name' => 'test'); $doc = new Solarium_Document_ReadWrite($data); $mockUpdate = $this->getMock('Solarium_Query_Update', array('addDocuments', 'addCommit')); $mockUpdate->expects($this->once())->method('addDocuments')->with($this->equalTo(array($doc)),$this->equalTo(true)); $mockUpdate->expects($this->once())->method('addCommit')->with($this->equalTo(false),$this->equalTo(true),$this->equalTo(false)); $mockClient = $this->getMock('Solarium_Client', array('createUpdate', 'update', 'triggerEvent')); $mockClient->expects($this->exactly(2))->method('createUpdate')->will($this->returnValue($mockUpdate)); $mockClient->expects($this->once())->method('update')->will($this->returnValue('dummyResult')); $mockClient->expects($this->exactly(2))->method('triggerEvent'); $plugin = new Solarium_Plugin_BufferedAdd(); $plugin->init($mockClient, array()); $plugin->addDocument($doc); $this->assertEquals('dummyResult', $plugin->commit(true, false, true, false)); } }