public function testFindingTagsByPath()
 {
     $path = Vector::create('task runners', 'gulp');
     $results = $this->coll->findByPath($path);
     $this->assertEquals(3, $results->count());
     foreach ($results as $tag) {
         $this->assertNotNull($tag->getParent());
         $this->assertTrue($tag->getName()->matches('gulp'));
         $this->assertTrue($tag->getParent()->getName()->matches('task runners'));
         $grandpa = $tag->getParent()->getParent();
         $name = $tag->getParent()->getParent()->getName();
         $this->assertTrue($grandpa->getName()->matches('development tools') || $grandpa->getName()->matches('node js'));
         if ($grandpa->getName()->matches('node js')) {
             $ggp = $grandpa->getParent();
             $this->assertTrue($ggp->getName()->matches('javascript') || $ggp->getName()->matches('asynchronous event-driven programming'));
         } else {
             $this->assertEquals($grandpa, $this->coll->findFirst('development tools'));
         }
     }
 }
Exemplo n.º 2
0
<?php

use Tag\Tag;
use Tag\Factory;
include 'vendor/autoload.php';
$logger = new Logger('test.log');
exec('rm -f test.sqlite');
$database = new Database(':memory:', $logger);
// $database = new Database('test.sqlite', $logger);
$factory = new Factory($database, $logger);
$collection = $factory->getCollection();
$data = json_decode(file_get_contents('groph.json'), true);
$fixtures = $data['tags'];
$collection->load($fixtures);
$t = $collection->findFirst('programming languages');
echo $t->ref, PHP_EOL;
$tag1 = $collection->findFirst('software development');
$path = Vector::create('programming languages', 'interpreted programming languages', 'javascript');
$steps = 0;
$names = Vector::create();
$tag1->visitPath($path, function (Tag $tag) use(&$steps, &$names) {
    echo "{$tag} [" . $tag->getId() . ']', PHP_EOL;
    $steps++;
    $names->append($tag->getName());
});
echo $path->count() . ' = ' . $steps, PHP_EOL;
Exemplo n.º 3
0
function export($file)
{
    global $tagCollection, $resCollection;
    $tags = array();
    foreach ($tagCollection->findLike(array('')) as $tag) {
        $parentPath = $tag->getParent() ? $tag->getParent()->getUniquePath()->implode(':') : '';
        $tags[] = array((string) $tag->getName() => $parentPath);
    }
    $resources = array();
    foreach ($resCollection->findLike(array('')) as $res) {
        $resources[$res->getLink()] = array($res->getTitle(), $res->getTags()->toStringsArray());
    }
    file_put_contents($file, Vector::create(array('tags' => $tags, 'resources' => $resources))->toJson());
}