/** * @return array */ private function loadStorageFromFile() { $fileName = $this->getFilename(); $group = new \Bookmarks\Group(); $group->title = 'my group'; $data = array('groups' => array($group->toArray())); file_put_contents($fileName, json_encode($data)); $storage = new \Bookmarks\Storage($fileName); return array($group, $storage); }
/** * @test */ public function showGroupReplacesUserVariables() { $group = new \Bookmarks\Group(); $group->title = 'any {domain}'; $link = new \Bookmarks\Link(); $link->title = 'this is {title}'; $link->url = 'http://{domain}.de'; $group->addLink($link); $env = new \Bookmarks\Environment(); $env->inject('domain', 'abc'); $env->inject('title', 'my group'); $view = new \Bookmarks\View(); $view->injectEnvironment($env); $actual = (string) $view->showGroup($group); $this->assertStringContains('any abc', $actual, 'html should replace {domain} and contain "any abc" title'); $this->assertStringContains('this is my group', $actual, 'html should replace {title} and contain tag "this is my group"'); $this->assertStringContains('http://abc.de', $actual, 'html should replace {domain} and contain url "http://abc.de"'); }
/** * @test */ public function findWordsReturnsWordWithInjectedVars() { $group = new \Bookmarks\Group(); $group->title = '{group.title}'; $link = new \Bookmarks\Link(); $link->title = '{link.title}'; $link->url = 'http://{link.domain}.de'; $link->tags = array('{link.tag}'); $group->addLink($link); $config = new \Bookmarks\Config(); $config->addGroup($group); $env = new \Bookmarks\Environment(); $env->inject('group.title', 'mytitle'); $env->inject('link.title', 'mylinktitle'); $env->inject('link.domain', 'mydomain'); $env->inject('link.tag', 'mytag'); $search = new \Bookmarks\Search($config); $search->injectEnvironment($env); $this->assertEquals(array('mytitle'), $search->findWords('mytitle'), 'search should find replaced string in group title'); $this->assertEquals(array('mylinktitle'), $search->findWords('mylinktitle'), 'search should find replaced string in link title'); $this->assertEquals(array('mydomain'), $search->findWords('mydomain'), 'search should find replaced string in link url'); $this->assertEquals(array('mytag'), $search->findWords('mytag'), 'search should find replaced string in link tag'); }
/** * @test */ public function postRequestShow() { $group = new \Bookmarks\Group(); $group->title = 'search engine'; $this->config->expects($this->once())->method('getGroups')->will($this->returnValue(array($group))); $this->view->expects($this->at(0))->method('header')->with($this->equalTo('Cache-Control: no-cache, must-revalidate')); $this->view->expects($this->at(1))->method('header')->with($this->equalTo('Expires: Mon, 26 Jul 1997 05:00:00 GMT')); $this->view->expects($this->at(2))->method('header')->with($this->equalTo('Content-type: application/json')); $this->assertEquals(json_encode(array($group->getId())), $this->controller->parseRequest('POST', array('action' => 'show', 'search' => 'engine'))); }