/**
  * Create a new bookmark based on an url and options
  *
  * @param array $fields the fields parameters
  *
  * @throws Herisson\Model\Exception if bookmark is duplicate
  *
  * @return the id of the bookmark created
  */
 public static function createBookmark($fields = array())
 {
     if (!isset($fields['url'])) {
         throw new Exception(__("Missing Url. Can't create bookmark"));
     }
     $url = $fields['url'];
     if (WpHerissonBookmarksTable::checkDuplicate($url)) {
         throw new Exception(__("Ignoring duplicate entry : {$url}"));
     }
     $bookmark = new WpHerissonBookmarks();
     $bookmark->setProperties($fields);
     $bookmark->save();
     if (array_key_exists('tags', $fields) && $fields['tags']) {
         $bookmark->setTags($fields['tags']);
     }
     return $bookmark->id;
 }
 /**
  * Test adding a new bookmark and delete it
  *
  * @return void
  */
 public function testSearch()
 {
     // Check it's saved in the DB
     $bookmarks = WpHerissonBookmarksTable::getSearch('example');
     $this->assertEquals(0, sizeof($bookmarks));
     // Create a sample bookmark
     $f = new WpHerissonBookmarks();
     $f->url = $this->sampleUrl;
     $f->save();
     $f = new WpHerissonBookmarks();
     $f->title = $this->sampleName;
     $f->save();
     $f = new WpHerissonBookmarks();
     $f->description = $this->sampleDescription;
     $f->save();
     // Check it's saved in the DB
     $bookmarks = WpHerissonBookmarksTable::getSearch('example');
     $this->assertEquals(3, sizeof($bookmarks));
     // Delete it and verify it's not there anymore
     foreach ($bookmarks as $f) {
         $f->delete();
     }
     $bookmarks = WpHerissonBookmarksTable::getSearch('example');
     $this->assertEquals(0, sizeof($bookmarks));
 }
 /**
  * Create a sample bookmark
  *
  * @param array $fields an array of fields/values to feed the bookmark with fake data
  *
  * @return a bookmark object
  */
 private function _getBookmark($fields = array())
 {
     // Create a sample bookmark
     $b = new WpHerissonBookmarks();
     if (sizeof($fields)) {
         foreach ($fields as $key => $value) {
             $b->{$key} = $value;
         }
     }
     $b->save();
     return $b;
 }