コード例 #1
0
$doc = new xfDocument('guid');
$doc->addField(new xfFieldValue(new xfField('name', xfField::KEYWORD), 'carl'));
$doc->addField(new xfFieldValue(new xfField('age', xfField::STORED), 18));
$engine->add($doc);
$engine->commit();
$t->is($engine->count(), 1, '->add() adds a document');
$parent = new xfDocument('parent');
$child = new xfDocument('child');
$pet = new xfDocument('pet');
$parent->addChild($child);
$child->addChild($pet);
$engine->add($parent);
$engine->commit();
$t->is($engine->count(), 4, '->add() adds a document and every subdocument');
$t->diag('->findGuid()');
$doc = $engine->findGuid('guid');
$t->isa_ok($doc, 'xfDocument', '->findGuid() returns an xfDocument');
$t->is($doc->getGuid(), 'guid', '->findGuid() returns the correct document');
$doc = $engine->findGuid('parent');
$children = $doc->getChildren();
$t->is(count($children), 1, '->findGuid() rebuilds subdocuments correctly');
$t->is($children['child']->getGuid(), 'child', '->findGuid() rebuilds subdocuments in correct order');
$children = $children['child']->getChildren();
$t->is($children['pet']->getGuid(), 'pet', '->findGuid() rebuilds subdocuments recursively');
try {
    $msg = '->findGuid() fails if the GUID does not exist';
    $engine->findGuid('foobar');
    $t->fail($msg);
} catch (Exception $e) {
    $t->pass($msg);
}