public function testGetChildrenOf()
 {
     $entity = new Entity();
     $childrenRelationIndex = $entity->getChildrenRelationIndex();
     $collection = new Collection([$entity, new Entity(), new Entity()]);
     $collection->get(0)->setRelation($childrenRelationIndex, new Collection([new Entity(), new Entity(), new Entity()]));
     $children = $collection->getChildrenOf(0);
     $this->assertInstanceOf('Franzose\\ClosureTable\\Extensions\\Collection', $children);
     $this->assertCount(3, $children);
 }
Beispiel #2
0
 public function setUp()
 {
     parent::setUp();
     $this->app->bind('Franzose\\ClosureTable\\Contracts\\EntityInterface', 'Franzose\\ClosureTable\\Models\\Entity');
     $this->app->bind('Franzose\\ClosureTable\\Contracts\\ClosureTableInterface', 'Franzose\\ClosureTable\\Models\\ClosureTable');
     if (!static::$sqlite_in_memory) {
         DB::statement('DROP TABLE IF EXISTS entities_closure');
         DB::statement('DROP TABLE IF EXISTS entities;');
         DB::statement('DROP TABLE IF EXISTS migrations');
     }
     $artisan = $this->app->make('Illuminate\\Contracts\\Console\\Kernel');
     $artisan->call('migrate', ['--database' => 'closuretable', '--path' => '../tests/migrations']);
     $artisan->call('db:seed', ['--class' => 'Franzose\\ClosureTable\\Tests\\Seeds\\EntitiesSeeder']);
     if (static::$debug) {
         Entity::$debug = true;
         Event::listen('illuminate.query', function ($sql, $bindings, $time) {
             $sql = str_replace(array('%', '?'), array('%%', '%s'), $sql);
             $full_sql = vsprintf($sql, $bindings);
             echo PHP_EOL . '- BEGIN QUERY -' . PHP_EOL . $full_sql . PHP_EOL . '- END QUERY -' . PHP_EOL;
         });
     }
 }
Beispiel #3
0
 public function testMoveNodeToBecomeRoot()
 {
     $item = Entity::find(1);
     $item->moveTo(0, 2);
     $item = Entity::find(2);
     $item->moveTo(0, 3);
     $item = Entity::find(3);
     $item->moveTo(0, 4);
     $item = Entity::find(4);
     $item->moveTo(0, 5);
     $item = Entity::find(1);
     $item->moveTo(0);
     $this->assertEquals(1, ClosureTable::whereDescendant(1)->count());
 }