silverstripe-fulltextsearch/tests/Solr4ServiceTest.php

74 lines
2.2 KiB
PHP
Raw Normal View History

2014-06-17 07:56:46 +02:00
<?php
/**
* Test solr 4.0 compatibility
*/
2015-11-21 07:19:20 +01:00
class Solr4ServiceTest extends SapphireTest
{
/**
*
* @return Solr4ServiceTest_RecordingService
*/
protected function getMockService()
{
return new Solr4ServiceTest_RecordingService();
}
protected function getMockDocument($id)
{
$document = new Apache_Solr_Document();
$document->setField('id', $id);
$document->setField('title', "Item $id");
return $document;
}
public function testAddDocument()
{
$service = $this->getMockService();
$sent = $service->addDocument($this->getMockDocument('A'), false);
$this->assertEquals(
'<add overwrite="true"><doc><field name="id">A</field><field name="title">Item A</field></doc></add>',
$sent
);
$sent = $service->addDocument($this->getMockDocument('B'), true);
$this->assertEquals(
'<add overwrite="false"><doc><field name="id">B</field><field name="title">Item B</field></doc></add>',
$sent
);
}
public function testAddDocuments()
{
$service = $this->getMockService();
$sent = $service->addDocuments(array(
$this->getMockDocument('C'),
$this->getMockDocument('D')
), false);
$this->assertEquals(
'<add overwrite="true"><doc><field name="id">C</field><field name="title">Item C</field></doc><doc><field name="id">D</field><field name="title">Item D</field></doc></add>',
$sent
);
$sent = $service->addDocuments(array(
$this->getMockDocument('E'),
$this->getMockDocument('F')
), true);
$this->assertEquals(
'<add overwrite="false"><doc><field name="id">E</field><field name="title">Item E</field></doc><doc><field name="id">F</field><field name="title">Item F</field></doc></add>',
$sent
);
}
2014-06-17 07:56:46 +02:00
}
2015-11-21 07:19:20 +01:00
class Solr4ServiceTest_RecordingService extends Solr4Service_Core
{
protected function _sendRawPost($url, $rawPost, $timeout = false, $contentType = 'text/xml; charset=UTF-8')
{
return $rawPost;
}
protected function _sendRawGet($url, $timeout = false)
{
return $url;
}
2014-06-17 07:56:46 +02:00
}