Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-01-16 14:00:22 +0400
committerArthur Schiwon <blizzz@owncloud.com>2014-02-10 17:53:59 +0400
commit1cf599d494e046e0b5a71c08c6f054b91174e142 (patch)
tree83a7399cff69466a64de5f697c6972aa90afc432
parent8a4dbdedcf6fe5aab1fc084c3e834e5a04e1bdf2 (diff)
Inject logger
-rw-r--r--lib/private/share/searchresultsorter.php9
-rw-r--r--tests/lib/share/searchresultsorter.php7
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php
index 4f8799494f5..f81a94c749d 100644
--- a/lib/private/share/searchresultsorter.php
+++ b/lib/private/share/searchresultsorter.php
@@ -12,16 +12,19 @@ class SearchResultSorter {
private $search;
private $encoding;
private $key;
+ private $log;
/**
* @param $search the search term as was given by the user
* @param $key the array key containing the value that should be compared
* against
* @param $encoding optional, encoding to use, defaults to UTF-8
+ * @param $log optional, an \OC\Log instance
*/
- public function __construct($search, $key, $encoding = 'UTF-8') {
+ public function __construct($search, $key, $encoding = 'UTF-8', \OC\Log $log = null) {
$this->encoding = $encoding;
$this->key = $key;
+ $this->log = is_null($log) ? new \OC\Log() : $log;
$this->search = mb_strtolower($search, $this->encoding);
}
@@ -32,8 +35,8 @@ class SearchResultSorter {
*/
public function sort($a, $b) {
if(!isset($a[$this->key]) || !isset($b[$this->key])) {
- \OCP\Util::writeLog('core', 'Sharing: cannot sort due to missing'.
- 'array key', \OC_Log::ERROR);
+ $this->log->error('Sharing dialogue: cannot sort due to missing array key',
+ array('app' => 'core'));
return 0;
}
$nameA = mb_strtolower($a[$this->key], $this->encoding);
diff --git a/tests/lib/share/searchresultsorter.php b/tests/lib/share/searchresultsorter.php
index f24e40ea059..efc3e1b7aa3 100644
--- a/tests/lib/share/searchresultsorter.php
+++ b/tests/lib/share/searchresultsorter.php
@@ -37,4 +37,11 @@ class Test_Share_Search extends \PHPUnit_Framework_TestCase {
$this->assertTrue($result[2]['foobar'] === 'Bicyclerepairwoman');
$this->assertTrue($result[3]['foobar'] === 'woot');
}
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testSortWrongLog() {
+ $sorter = new \OC\Share\SearchResultSorter('foo', 'bar', 'UTF-8', 'foobar');
+ }
}