8 namespace Fossology\Lib\Report;
 
   13 use Mockery\MockInterface;
 
   15 include_once(dirname(dirname(__DIR__)).
"/common-string.php");
 
   19   public function __construct($groupBy = 
"content")
 
   21     parent::__construct($groupBy);
 
   24   protected function getStatements($uploadId, $uploadTreeTableName, $userId = 
null, $groupId=
null)
 
   27       array(
"licenseId" => 
"371", 
"risk" => 
"5", 
"content" => 
"1", 
"text" => 
"t1", 
"comments" => 
"c1", 
"uploadtree_pk" => 1),
 
   28       array(
"licenseId" => 
"213", 
"risk" => 
"4", 
"content" => 
"1", 
"text" => 
"t2", 
"comments" => 
"c1", 
"uploadtree_pk" => 2),
 
   29       array(
"licenseId" => 
"243", 
"risk" => 
"4", 
"content" => 
"2", 
"text" => 
"t3", 
"comments" => 
"c3", 
"uploadtree_pk" => 3),
 
   36   public function __construct($groupBy = 
"content")
 
   38     parent::__construct($groupBy);
 
   41   protected function getStatements($uploadId, $uploadTreeTableName, $userId = 
null, $groupId=
null)
 
   45   public function getCleared($uploadId, $objectAgent, $groupId = 
null, $extended = 
true, $agentcall = 
null, $isUnifiedReport = 
false)
 
   48       array(
"good" => 
"漢", 
"esc" => 
"esc␛ape", 
"uml" => 
' ü ')
 
   60   protected function setUp() : 
void 
   62     $this->uploadDao = M::mock(UploadDao::class);
 
   63     $this->treeDao = M::mock(TreeDao::class);
 
   65     $container = M::mock(
'ContainerBuilder');
 
   66     $GLOBALS[
'container'] = $container;
 
   68     $container->shouldReceive(
'get')->with(
'dao.upload')->andReturn($this->uploadDao);
 
   69     $container->shouldReceive(
'get')->with(
'dao.tree')->andReturn($this->treeDao);
 
   70     $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
 
   73   protected function tearDown() : 
void 
   75     $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
 
   78   public function testGetFileNames()
 
   84     $uploadTreeTableName = 
"ut";
 
   87          ->shouldReceive(
'getUploadtreeTableName')
 
   89          ->andReturn($uploadTreeTableName);
 
   92          ->shouldReceive(
'getMinimalCoveringItem')
 
   93          ->with($uploadId,$uploadTreeTableName)
 
   94          ->andReturn($parentId);
 
   97          ->shouldReceive(
'getFullPath')
 
   98          ->with(1, $uploadTreeTableName, $parentId)
 
  102          ->shouldReceive(
'getItemHashes')
 
  104          ->andReturn(array(
'sha1'=> 
"9B12538E" ,
'md5'=> 
"MD52538E"));
 
  107          ->shouldReceive(
'getFullPath')
 
  108          ->with(2, $uploadTreeTableName, $parentId)
 
  112          ->shouldReceive(
'getItemHashes')
 
  114          ->andReturn(array(
'sha1'=> 
"8C2275AE" ,
'md5'=> 
"MD5275AE"));
 
  117          ->shouldReceive(
'getFullPath')
 
  118          ->with(3, $uploadTreeTableName, $parentId)
 
  119          ->andReturn(
"a/b/1");
 
  122          ->shouldReceive(
'getItemHashes')
 
  124          ->andReturn(array(
'sha1'=> 
"CA10238C" ,
'md5'=> 
"MD50238C"));
 
  127          ->shouldReceive(
'getFullPath')
 
  128          ->with(4, $uploadTreeTableName, $parentId)
 
  132          ->shouldReceive(
'getItemHashes')
 
  134          ->andReturn(array(
'sha1'=> 
"AB12838A" ,
'md5'=> 
"MD52838A"));
 
  136     $statements = $this->clearedGetterTest->getCleared($uploadId, 
null);
 
  138       "statements" => array(
 
  140           "licenseId" => 
"371",
 
  145           "files" => array(
"a/1", 
"a/2"),
 
  146           "hash" => array(
"9B12538E",
"8C2275AE")
 
  149           "licenseId" => 
"213",
 
  154           "files" => array(
"a/1"),
 
  155           "hash" => array(
"9B12538E")
 
  158           "licenseId" => 
"243",
 
  163           "files" => array(
"a/4"),
 
  164           "hash" => array(
"AB12838A")
 
  172           "files" => array(
"a/b/1"),
 
  173           "hash" => array(
"CA10238C")
 
  177     assertThat(arsort($expected), equalTo($statements));
 
  180   public function testGetFileNamesGroupByText()
 
  185     $uploadTreeTableName = 
"ut";
 
  188          ->shouldReceive(
'getUploadtreeTableName')
 
  190          ->andReturn($uploadTreeTableName);
 
  193          ->shouldReceive(
'getMinimalCoveringItem')
 
  194          ->with($uploadId,$uploadTreeTableName)
 
  195          ->andReturn($parentId);
 
  198          ->shouldReceive(
'getFullPath')
 
  199          ->with(1, $uploadTreeTableName, $parentId)
 
  203          ->shouldReceive(
'getItemHashes')
 
  205          ->andReturn(array(
'sha1'=> 
"9B12538E" ,
'md5'=> 
"MD52538E"));
 
  208          ->shouldReceive(
'getFullPath')
 
  209          ->with(2, $uploadTreeTableName, $parentId)
 
  213          ->shouldReceive(
'getItemHashes')
 
  215          ->andReturn(array(
'sha1'=> 
"8C2275AE" ,
'md5'=> 
"MD5275AE"));
 
  218          ->shouldReceive(
'getFullPath')
 
  219          ->with(3, $uploadTreeTableName, $parentId)
 
  220          ->andReturn(
"a/b/1");
 
  223          ->shouldReceive(
'getItemHashes')
 
  225          ->andReturn(array(
'sha1'=> 
"CA10238C" ,
'md5'=> 
"MD50238C"));
 
  228          ->shouldReceive(
'getFullPath')
 
  229          ->with(4, $uploadTreeTableName, $parentId)
 
  233          ->shouldReceive(
'getItemHashes')
 
  235          ->andReturn(array(
'sha1'=> 
"AB12838A" ,
'md5'=> 
"MD52838A"));
 
  238     $statements = $tester->getCleared($uploadId, 
null);
 
  240       "statements" => array(
 
  242           "licenseId" => 
"371",
 
  247           "files" => array(
"a/1"),
 
  248           "hash" => array(
"9B12538E")
 
  251           "licenseId" => 
"243",
 
  256           "files" => array(
"a/2"),
 
  257           "hash" => array(
"8C2275AE")
 
  260           "licenseId" => 
"243",
 
  265           "files" => array(
"a/b/1"),
 
  266           "hash" => array(
"CA10238C")
 
  274           "files" => array(
"a/4"),
 
  275           "hash" => array(
"AB12838A")
 
  279     assertThat(arsort($expected), equalTo($statements));
 
  282   function testWeirdChars()
 
  284     $weirdCharclearedGetter = 
new WeirdCharclearedGetter();
 
  285     $json = $weirdCharclearedGetter->cJson(0);
 
  286     assertThat($json, containsString(
'"good":"\\u6f22"'));
 
  287     assertThat($json, containsString(
'"esc":"escape"'));
 
  288     assertThat($json, containsString(
'"uml":" \\u00fc "'));