public function testIterator()
 {
     $nodeData = array('alpha', 'alpha/a', 'alpha/a/b', 'alpha/a/b/c');
     $nodes = array();
     $c = new Collection();
     foreach ($nodeData as $path) {
         $n = new Node($path);
         $nodes[$path] = $n;
         $c->addNode($n);
     }
     $c->rewind();
     $this->assertEquals($nodes['alpha'], $c->current());
     $this->assertEquals('alpha', $c->key());
     $this->assertEquals(true, $c->valid());
     $c->next();
     $this->assertEquals($nodes['alpha/a'], $c->current());
     $this->assertEquals('alpha/a', $c->key());
     $this->assertEquals(true, $c->valid());
     $c->next();
     $this->assertEquals($nodes['alpha/a/b'], $c->current());
     $this->assertEquals('alpha/a/b', $c->key());
     $this->assertEquals(true, $c->valid());
     $c->next();
     $this->assertEquals($nodes['alpha/a/b/c'], $c->current());
     $this->assertEquals('alpha/a/b/c', $c->key());
     $this->assertEquals(true, $c->valid());
     $c->next();
     $this->assertEquals(false, $c->valid());
     $c->rewind();
     $this->assertEquals($nodes['alpha'], $c->current());
     $this->assertEquals('alpha', $c->key());
     $this->assertEquals(true, $c->valid());
 }
 public function updateCollection()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     if (Input::has('id')) {
         try {
             $collection = Collection::findorFail((int) Input::get('id'));
         } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return App::abort(404);
         }
         $message = 'has been updated successful.';
     } else {
         $collection = new Collection();
         $message = 'has been created successful.';
     }
     if (Input::has('name')) {
         $collection->name = Input::get('name');
         $collection->short_name = Str::slug($collection->name);
     }
     if (Input::has('type_id')) {
         $collection->type_id = Input::get('type_id');
     }
     if (Input::has('on_screen')) {
         $collection->on_screen = (int) Input::get('on_screen');
     }
     $pass = $collection->valid();
     if ($pass->passes()) {
         $collection->save();
         return ['status' => 'ok', 'message' => 'Collection <b>' . $collection->name . '</b> ' . $message, 'data' => $collection];
     }
     $message = '';
     $arrErr = $pass->messages()->all();
     foreach ($arrErr as $value) {
         $message .= "{$value}\n";
     }
     return ['status' => 'error', 'message' => $message];
 }