@ -14,6 +14,7 @@ use OC\Files\Cache\Cache;
use OC\Files\Search\SearchComparison ;
use OC\Files\Search\SearchQuery ;
use OCP\Files\Search\ISearchComparison ;
use OCP\IUser ;
class LongId extends \OC\Files\Storage\Temporary {
public function getId () {
@ -397,6 +398,61 @@ class CacheTest extends \Test\TestCase {
}
}
function testSearchQueryByTag () {
$userId = static :: getUniqueID ( 'user' );
\OC :: $server -> getUserManager () -> createUser ( $userId , $userId );
static :: loginAsUser ( $userId );
$user = new \OC\User\User ( $userId , null );
$file1 = 'folder' ;
$file2 = 'folder/foobar' ;
$file3 = 'folder/foo' ;
$file4 = 'folder/foo2' ;
$file5 = 'folder/foo3' ;
$data1 = array ( 'size' => 100 , 'mtime' => 50 , 'mimetype' => 'foo/folder' );
$fileData = array ();
$fileData [ 'foobar' ] = array ( 'size' => 1000 , 'mtime' => 20 , 'mimetype' => 'foo/file' );
$fileData [ 'foo' ] = array ( 'size' => 20 , 'mtime' => 25 , 'mimetype' => 'foo/file' );
$fileData [ 'foo2' ] = array ( 'size' => 25 , 'mtime' => 28 , 'mimetype' => 'foo/file' );
$fileData [ 'foo3' ] = array ( 'size' => 88 , 'mtime' => 34 , 'mimetype' => 'foo/file' );
$id1 = $this -> cache -> put ( $file1 , $data1 );
$id2 = $this -> cache -> put ( $file2 , $fileData [ 'foobar' ]);
$id3 = $this -> cache -> put ( $file3 , $fileData [ 'foo' ]);
$id4 = $this -> cache -> put ( $file4 , $fileData [ 'foo2' ]);
$id5 = $this -> cache -> put ( $file5 , $fileData [ 'foo3' ]);
$tagManager = \OC :: $server -> getTagManager () -> load ( 'files' , null , null , $userId );
$this -> assertTrue ( $tagManager -> tagAs ( $id1 , 'tag1' ));
$this -> assertTrue ( $tagManager -> tagAs ( $id1 , 'tag2' ));
$this -> assertTrue ( $tagManager -> tagAs ( $id2 , 'tag2' ));
$this -> assertTrue ( $tagManager -> tagAs ( $id3 , 'tag1' ));
$this -> assertTrue ( $tagManager -> tagAs ( $id4 , 'tag2' ));
$results = $this -> cache -> searchQuery ( new SearchQuery (
new SearchComparison ( ISearchComparison :: COMPARE_EQUAL , 'tagname' , 'tag2' ),
0 , 0 , [], $user
));
$this -> assertEquals ( 3 , count ( $results ));
usort ( $results , function ( $value1 , $value2 ) {
return $value1 [ 'name' ] >= $value2 [ 'name' ];
});
$this -> assertEquals ( 'folder' , $results [ 0 ][ 'name' ]);
$this -> assertEquals ( 'foo2' , $results [ 1 ][ 'name' ]);
$this -> assertEquals ( 'foobar' , $results [ 2 ][ 'name' ]);
$tagManager -> delete ( 'tag1' );
$tagManager -> delete ( 'tag2' );
static :: logout ();
$user = \OC :: $server -> getUserManager () -> get ( $userId );
if ( $user !== null ) {
$user -> delete ();
}
}
function testSearchByQuery () {
$file1 = 'folder' ;
$file2 = 'folder/foobar' ;
@ -409,25 +465,27 @@ class CacheTest extends \Test\TestCase {
$this -> cache -> put ( $file1 , $data1 );
$this -> cache -> put ( $file2 , $fileData [ 'foobar' ]);
$this -> cache -> put ( $file3 , $fileData [ 'foo' ]);
/** @var IUser $user */
$user = $this -> createMock ( IUser :: class );
$this -> assertCount ( 1 , $this -> cache -> searchQuery ( new SearchQuery (
new SearchComparison ( ISearchComparison :: COMPARE_EQUAL , 'name' , 'foo' )
, 10 , 0 , [])));
, 10 , 0 , [], $user )));
$this -> assertCount ( 2 , $this -> cache -> searchQuery ( new SearchQuery (
new SearchComparison ( ISearchComparison :: COMPARE_LIKE , 'name' , 'foo%' )
, 10 , 0 , [])));
, 10 , 0 , [], $user )));
$this -> assertCount ( 2 , $this -> cache -> searchQuery ( new SearchQuery (
new SearchComparison ( ISearchComparison :: COMPARE_EQUAL , 'mimetype' , 'foo/file' )
, 10 , 0 , [])));
, 10 , 0 , [], $user )));
$this -> assertCount ( 3 , $this -> cache -> searchQuery ( new SearchQuery (
new SearchComparison ( ISearchComparison :: COMPARE_LIKE , 'mimetype' , 'foo/%' )
, 10 , 0 , [])));
, 10 , 0 , [], $user )));
$this -> assertCount ( 1 , $this -> cache -> searchQuery ( new SearchQuery (
new SearchComparison ( ISearchComparison :: COMPARE_GREATER_THAN , 'size' , 100 )
, 10 , 0 , [])));
, 10 , 0 , [], $user )));
$this -> assertCount ( 2 , $this -> cache -> searchQuery ( new SearchQuery (
new SearchComparison ( ISearchComparison :: COMPARE_GREATER_THAN_EQUAL , 'size' , 100 )
, 10 , 0 , [])));
, 10 , 0 , [], $user )));
}
function testMove () {