_query = new Solarium_Query_Update;
$this->_builder = new Solarium_Client_RequestBuilder_Update;
}
public function testGetMethod()
{
$request = $this->_builder->build($this->_query);
$this->assertEquals(
Solarium_Client_Request::METHOD_POST,
$request->getMethod()
);
}
public function testGetUri()
{
$request = $this->_builder->build($this->_query);
$this->assertEquals(
'update?wt=json',
$request->getUri()
);
}
public function testBuildAddXmlNoParamsSingleDocument()
{
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => 1)));
$this->assertEquals(
'1',
$this->_builder->buildAddXml($command)
);
}
public function testBuildAddXmlWithParams()
{
$command = new Solarium_Query_Update_Command_Add(array('overwrite' => true,'commitwithin' => 100));
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => 1)));
$this->assertEquals(
'1',
$this->_builder->buildAddXml($command)
);
}
public function testBuildAddXmlSpecialCharacters()
{
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => 1, 'text' => 'test < 123 > test')));
$this->assertEquals(
'1test < 123 > test',
$this->_builder->buildAddXml($command)
);
}
public function testBuildAddXmlMultivalueField()
{
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => array(1,2,3), 'text' => 'test < 123 > test')));
$this->assertEquals(
'123test < 123 > test',
$this->_builder->buildAddXml($command)
);
}
public function testBuildAddXmlSingleDocumentWithBoost()
{
$doc = new Solarium_Document_ReadWrite(array('id' => 1));
$doc->setBoost(2.5);
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument($doc);
$this->assertEquals(
'1',
$this->_builder->buildAddXml($command)
);
}
public function testBuildAddXmlSingleDocumentWithFieldBoost()
{
$doc = new Solarium_Document_ReadWrite(array('id' => 1));
$doc->setFieldBoost('id',2.1);
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument($doc);
$this->assertEquals(
'1',
$this->_builder->buildAddXml($command)
);
}
public function testBuildAddXmlMultipleDocuments()
{
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => 1)));
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => 2)));
$this->assertEquals(
'12',
$this->_builder->buildAddXml($command)
);
}
public function testBuildDeleteXml()
{
$command = new Solarium_Query_Update_Command_Delete;
$this->assertEquals(
'',
$this->_builder->buildDeleteXml($command)
);
}
public function testBuildDeleteXmlSingleId()
{
$command = new Solarium_Query_Update_Command_Delete;
$command->addId(123);
$this->assertEquals(
'123',
$this->_builder->buildDeleteXml($command)
);
}
public function testBuildDeleteXmlMultipleIds()
{
$command = new Solarium_Query_Update_Command_Delete;
$command->addId(123);
$command->addId(456);
$this->assertEquals(
'123456',
$this->_builder->buildDeleteXml($command)
);
}
public function testBuildDeleteXmlSingleQuery()
{
$command = new Solarium_Query_Update_Command_Delete;
$command->addQuery('*:*');
$this->assertEquals(
'*:*',
$this->_builder->buildDeleteXml($command)
);
}
public function testBuildDeleteXmlMultipleQueries()
{
$command = new Solarium_Query_Update_Command_Delete;
$command->addQuery('published:false');
$command->addQuery('id:[10 TO 20]');
$this->assertEquals(
'published:falseid:[10 TO 20]',
$this->_builder->buildDeleteXml($command)
);
}
public function testBuildDeleteXmlIdsAndQueries()
{
$command = new Solarium_Query_Update_Command_Delete;
$command->addId(123);
$command->addId(456);
$command->addQuery('published:false');
$command->addQuery('id:[10 TO 20]');
$this->assertEquals(
'123456published:falseid:[10 TO 20]',
$this->_builder->buildDeleteXml($command)
);
}
public function testBuildDeleteXmlIdAndQuerySpecialChars()
{
$command = new Solarium_Query_Update_Command_Delete;
$command->addId('specialid');
$command->addQuery('id:specialid');
$this->assertEquals(
'special<char>idid:special<char>id',
$this->_builder->buildDeleteXml($command)
);
}
public function testBuildOptimizeXml()
{
$command = new Solarium_Query_Update_Command_Optimize;
$this->assertEquals(
'',
$this->_builder->buildOptimizeXml($command)
);
}
public function testBuildOptimizeXmlWithParams()
{
$command = new Solarium_Query_Update_Command_Optimize(array('waitflush'=>true,'waitsearcher'=>false,'maxsegments'=>10));
$this->assertEquals(
'',
$this->_builder->buildOptimizeXml($command)
);
}
public function testBuildCommitXml()
{
$command = new Solarium_Query_Update_Command_Commit;
$this->assertEquals(
'',
$this->_builder->buildCommitXml($command)
);
}
public function testBuildCommitXmlWithParams()
{
$command = new Solarium_Query_Update_Command_Commit(array('waitflush'=>true,'waitsearcher'=>false,'expungedeletes'=>true));
$this->assertEquals(
'',
$this->_builder->buildCommitXml($command)
);
}
public function testBuildRollbackXml()
{
$command = new Solarium_Query_Update_Command_Rollback;
$this->assertEquals(
'',
$this->_builder->buildRollbackXml($command)
);
}
public function testCompleteRequest()
{
$this->_query->addDeleteById(1);
$this->_query->addRollback();
$this->_query->addDeleteQuery('*:*');
$this->_query->addDocument(new Solarium_Document_ReadWrite(array('id' => 1)));
$this->_query->addCommit();
$this->_query->addOptimize();
$this->assertEquals(
''
. '1'
. ''
. '*:*'
. '1'
. ''
. ''
. '',
$this->_builder->getRawData($this->_query)
);
}
public function testInvalidCommandInRequest()
{
$this->_query->add('invalidcommand',new InvalidCommand);
$this->setExpectedException('Solarium_Exception');
$this->_builder->build($this->_query);
}
}
class InvalidCommand extends StdClass
{
public function getType()
{
return 'invalid';
}
}