8 namespace Fossology\Lib\UI;
31 protected function setUp() :
void
33 $this->folderDao = M::mock(FolderDao::class);
34 $this->
dbManager = M::mock(DbManager::class);
37 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
40 protected function tearDown() :
void
42 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
46 protected function getFormattedItem($row)
48 return Reflectory::invokeObjectsMethodnameWith($this->folderNav,
'getFormattedItem', array($row,$this->uri));
51 protected function prepareShowFolderTree($parentFolderId=
'parentFolderId')
53 $this->folderDao->shouldReceive(
'getFolderTreeCte')->with($parentFolderId)
54 ->andReturn($parentFolderId.
'Cte');
55 $this->
dbManager->shouldReceive(
'prepare')->withArgs(array(anything(),startsWith($parentFolderId.
'Cte')));
56 $this->
dbManager->shouldReceive(
'execute')->withArgs(array(anything(),array($parentFolderId)))
57 ->andReturn($res=$parentFolderId.
'Res');
58 $this->
dbManager->shouldReceive(
'freeResult')->with($res);
62 public function testShowFolderTreeWithoutContent()
64 $res = $this->prepareShowFolderTree($parentFolderId=
'foo');
65 $this->
dbManager->shouldReceive(
'fetchArray')->with($res)
66 ->andReturn($rowA=array(
'folder_pk'=>1,
'folder_name'=>
'A',
'folder_desc'=>
'',
'depth'=>0),
false);
67 $out = $this->folderNav->showFolderTree($parentFolderId);
68 assertThat($out, equalTo(
'<ul id="tree"><li>'.$this->getFormattedItem($rowA).
'</li></ul>'));
71 public function testShowFolderTreeWithContent()
73 $res = $this->prepareShowFolderTree($parentFolderId=
'foo');
74 $this->
dbManager->shouldReceive(
'fetchArray')->with($res)
75 ->andReturn($rowTop=array(
'folder_pk'=>1,
'folder_name'=>
'Top',
'folder_desc'=>
'',
'depth'=>0),
76 $rowA=array(
'folder_pk'=>2,
'folder_name'=>
'B',
'folder_desc'=>
'/A',
'depth'=>1),
77 $rowB=array(
'folder_pk'=>3,
'folder_name'=>
'B',
'folder_desc'=>
'/A/B',
'depth'=>2),
78 $rowC=array(
'folder_pk'=>4,
'folder_name'=>
'C',
'folder_desc'=>
'/C',
'depth'=>1),
80 $out = $this->folderNav->showFolderTree($parentFolderId);
81 assertThat(str_replace(
"\n",
'',$out), equalTo(
'<ul id="tree"><li>'.$this->getFormattedItem($rowTop).
'<ul><li>'
82 .$this->getFormattedItem($rowA).
'<ul><li>'
83 .$this->getFormattedItem($rowB).
'</li></ul></li><li>'
84 .$this->getFormattedItem($rowC).
'</li></ul></li></ul>'));
Traceback_uri()
Get the URI without query to this location.
fo_dbManager * dbManager
fo_dbManager object