* This file is part of the sfSearch package.
 * (c) Carl Vondrick <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
require 'service/xfService.class.php';
require 'mock/service/xfMockIdentifier.class.php';
require 'mock/builder/xfMockBuilder.class.php';
require 'mock/result/xfMockRetort.class.php';
$t = new lime_test(12, new lime_output_color());
$identifier = new xfMockIdentifier();
$service = new xfService($identifier);
$t->diag('->getIdentifier()');
$t->is($service->getIdentifier(), $identifier, '->getIdentifier() returns the identifier');
$t->diag('->addBuilder(), ->buildDocument()');
$doc = $service->buildDocument(42);
$t->is($doc->getGuid(), $identifier->getGuid(42), '->buildDocument() builds a document with the correct GUID');
$t->is(count($doc->getFields()), 1, '->buildDocument() builds a document with one field only with no builders');
$t->is($doc->getField('_service')->getValue(), 'foobar', '->buildDocument() builds a document with a field "_service" as the name of the service');
$service->addBuilder(new xfMockBuilder());
$doc = $service->buildDocument(42);
$t->is($doc->getField('foobar')->getValue(), 'bar', '->buildDocument() acknowledges registered builders');
$t->diag('->addRetort(), ->getRetorts()');
$retort = new xfMockRetort();
$service->addRetort($retort);
$t->is($service->getRetorts(), array($retort), '->getRetorts() returns the retorts registered');
$t->diag('->setOption(), ->getOption(), ->hasOption()');
$t->ok(!$service->hasOption('foobar'), '->hasOption() returns false for unset options');
$t->is($service->getOption('foobar'), null, '->getOption() returns null for unset options');
 /**
  * Registers a new service.
  *
  * @param xfService $service The service
  */
 public function register(xfService $service)
 {
     $this->services[$service->getIdentifier()->getName()] = $service;
 }