diff --git a/appinfo/application.php b/appinfo/application.php index fec85b31..bfeecdb8 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -35,7 +35,6 @@ use OCA\Activity\FilesHooks; use OCA\Activity\MailQueueHandler; use OCA\Activity\Navigation; use OCA\Activity\Parameter\Factory; -use OCA\Activity\ParameterHelper; use OCA\Activity\UserSettings; use OCA\Activity\ViewInfoCache; use OCP\AppFramework\App; @@ -81,7 +80,6 @@ class Application extends App { $server->getUserManager(), $server->getURLGenerator(), $server->getContactsManager(), - $server->getConfig(), $c->query('OCA\Activity\ViewInfoCache'), $c->query('ActivityL10N'), $c->query('CurrentUID') diff --git a/lib/datahelper.php b/lib/datahelper.php index cd60e842..36a6656a 100644 --- a/lib/datahelper.php +++ b/lib/datahelper.php @@ -77,25 +77,21 @@ class DataHelper { * @param string $app The app where this event comes from * @param string $text The text including placeholders * @param IParameter[] $params The parameter for the placeholder - * @param bool $stripPath Shall we strip the path from file names? - * @param bool $highlightParams Shall we highlight the parameters in the string? - * They will be highlighted with ``, all data will be passed through - * \OCP\Util::sanitizeHTML() before, so no XSS is possible. * @return string translated */ - public function translation($app, $text, array $params, $stripPath = false, $highlightParams = false) { + public function translation($app, $text, array $params) { if (!$text) { return ''; } $preparedParams = []; foreach ($params as $parameter) { - $preparedParams[] = $parameter->format($highlightParams, !$stripPath); + $preparedParams[] = $parameter->format(); } // Allow apps to correctly translate their activities $translation = $this->activityManager->translate( - $app, $text, $preparedParams, $stripPath, $highlightParams, $this->l->getLanguageCode()); + $app, $text, $preparedParams, false, false, $this->l->getLanguageCode()); if ($translation !== false) { return $translation; @@ -132,17 +128,7 @@ class DataHelper { public function formatStrings($activity, $message) { $activity[$message . 'params'] = $activity[$message . 'params_array']; unset($activity[$message . 'params_array']); - - $activity[$message . '_prepared'] = $this->translation($activity['app'], $activity[$message], $activity[$message . 'params'], null, null); - - $activity[$message . 'formatted'] = array( - 'trimmed' => $this->translation($activity['app'], $activity[$message], $activity[$message . 'params'], true), - 'full' => $this->translation($activity['app'], $activity[$message], $activity[$message . 'params']), - 'markup' => array( - 'trimmed' => $this->translation($activity['app'], $activity[$message], $activity[$message . 'params'], true, true), - 'full' => $this->translation($activity['app'], $activity[$message], $activity[$message . 'params'], false, true), - ), - ); + $activity[$message . '_prepared'] = $this->translation($activity['app'], $activity[$message], $activity[$message . 'params']); return $activity; } diff --git a/lib/formatter/baseformatter.php b/lib/formatter/baseformatter.php index f85fb67b..cad3cf07 100644 --- a/lib/formatter/baseformatter.php +++ b/lib/formatter/baseformatter.php @@ -28,19 +28,9 @@ class BaseFormatter implements IFormatter { /** * @param IEvent $event * @param string $parameter The parameter to be formatted - * @param bool $allowHtml Should HTML be used to format the parameter? - * @param bool $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ - public function format(IEvent $event, $parameter, $allowHtml, $verbose = false) { - if ($allowHtml === null) { - return '' . Util::sanitizeHTML($parameter) . ''; - } - - if ($allowHtml) { - return '' . Util::sanitizeHTML($parameter) . ''; - } else { - return $parameter; - } + public function format(IEvent $event, $parameter) { + return '' . Util::sanitizeHTML($parameter) . ''; } } diff --git a/lib/formatter/cloudidformatter.php b/lib/formatter/cloudidformatter.php index 82d1ec40..42542538 100644 --- a/lib/formatter/cloudidformatter.php +++ b/lib/formatter/cloudidformatter.php @@ -44,11 +44,9 @@ class CloudIDFormatter implements IFormatter { /** * @param IEvent $event * @param string $parameter The parameter to be formatted - * @param bool $allowHtml Should HTML be used to format the parameter? - * @param bool $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ - public function format(IEvent $event, $parameter, $allowHtml, $verbose = false) { + public function format(IEvent $event, $parameter) { $displayName = $parameter; try { list($user, $server) = Helper::splitUserRemote($parameter); @@ -57,7 +55,7 @@ class CloudIDFormatter implements IFormatter { $server = ''; } - if (!$verbose && $server !== '') { + if ($server !== '') { $displayName = $user . '@…'; } @@ -65,17 +63,7 @@ class CloudIDFormatter implements IFormatter { $displayName = $this->getDisplayNameFromContact($parameter); } catch (\OutOfBoundsException $e) {} - - if ($allowHtml === null) { - return '' . Util::sanitizeHTML($parameter) . ''; - } - - if ($allowHtml) { - $title = ' title="' . Util::sanitizeHTML($parameter) . '"'; - return '' . Util::sanitizeHTML($displayName) . ''; - } else { - return $displayName; - } + return '' . Util::sanitizeHTML($parameter) . ''; } /** diff --git a/lib/formatter/fileformatter.php b/lib/formatter/fileformatter.php index dfccd7aa..b44c6c4e 100644 --- a/lib/formatter/fileformatter.php +++ b/lib/formatter/fileformatter.php @@ -53,11 +53,9 @@ class FileFormatter implements IFormatter { /** * @param IEvent $event * @param string $parameter The parameter to be formatted - * @param bool $allowHtml Should HTML be used to format the parameter? - * @param bool $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ - public function format(IEvent $event, $parameter, $allowHtml, $verbose = false) { + public function format(IEvent $event, $parameter) { $param = $this->fixLegacyFilename($parameter); // If the activity is about the very same file, we use the current path @@ -86,26 +84,9 @@ class FileFormatter implements IFormatter { } $param = trim($param, '/'); - list($path, $name) = $this->splitPathFromFilename($param); $fileLink = $this->urlGenerator->linkTo('files', 'index.php', $linkData); - if ($allowHtml === null) { - return '' . Util::sanitizeHTML($param) . ''; - } - - if ($verbose || $path === '') { - if (!$allowHtml) { - return $param; - } - return '' . Util::sanitizeHTML($param) . ''; - } - - if (!$allowHtml) { - return $name; - } - - $title = ' title="' . $this->l->t('in %s', array(Util::sanitizeHTML($path))) . '"'; - return '' . Util::sanitizeHTML($name) . ''; + return '' . Util::sanitizeHTML($param) . ''; } /** diff --git a/lib/formatter/iformatter.php b/lib/formatter/iformatter.php index 8213af70..e8476b59 100644 --- a/lib/formatter/iformatter.php +++ b/lib/formatter/iformatter.php @@ -27,9 +27,7 @@ interface IFormatter { /** * @param IEvent $event * @param string $parameter The parameter to be formatted - * @param bool $allowHtml Should HTML be used to format the parameter? - * @param bool $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ - public function format(IEvent $event, $parameter, $allowHtml, $verbose = false); + public function format(IEvent $event, $parameter); } diff --git a/lib/formatter/userformatter.php b/lib/formatter/userformatter.php index fd651f54..f95875d5 100644 --- a/lib/formatter/userformatter.php +++ b/lib/formatter/userformatter.php @@ -30,59 +30,34 @@ use OCP\Util; class UserFormatter implements IFormatter { /** @var IUserManager */ protected $manager; - /** @var IConfig */ - protected $config; /** @var IL10N */ protected $l; /** * @param IUserManager $userManager - * @param IConfig $config * @param IL10N $l */ - public function __construct(IUserManager $userManager, IConfig $config, IL10N $l) { + public function __construct(IUserManager $userManager, IL10N $l) { $this->manager = $userManager; - $this->config = $config; $this->l = $l; } /** * @param IEvent $event * @param string $parameter The parameter to be formatted - * @param bool $allowHtml Should HTML be used to format the parameter? - * @param bool $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ - public function format(IEvent $event, $parameter, $allowHtml, $verbose = false) { + public function format(IEvent $event, $parameter) { // If the username is empty, the action has been performed by a remote // user, or via a public share. We don't know the username in that case if ($parameter === '') { - if ($allowHtml === null) { - return '' . Util::sanitizeHTML('') . ''; - } - if ($allowHtml) { - return '' . $this->l->t('"remote user"') . ''; - } else { - return $this->l->t('"remote user"'); - } + return '' . Util::sanitizeHTML('') . ''; } $user = $this->manager->get($parameter); $displayName = ($user) ? $user->getDisplayName() : $parameter; $parameter = Util::sanitizeHTML($parameter); - if ($allowHtml === null) { - return '' . Util::sanitizeHTML($parameter) . ''; - } - - if ($allowHtml) { - $avatarPlaceholder = ''; - if ($this->config->getSystemValue('enable_avatars', true)) { - $avatarPlaceholder = '
'; - } - return $avatarPlaceholder . '' . Util::sanitizeHTML($displayName) . ''; - } else { - return $displayName; - } + return '' . Util::sanitizeHTML($parameter) . ''; } } diff --git a/lib/parameter/collection.php b/lib/parameter/collection.php index 98fba09e..11f5c8ab 100644 --- a/lib/parameter/collection.php +++ b/lib/parameter/collection.php @@ -81,72 +81,15 @@ class Collection implements IParameter { } /** - * @param bool $allowHtml Should HTML be used to format the parameter? - * @param bool $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ - public function format($allowHtml, $verbose = false) { + public function format() { $parameterList = $plainParameterList = []; foreach ($this->parameters as $parameter) { - $parameterList[] = $parameter->format($allowHtml, $verbose); - $plainParameterList[] = $parameter->format(false, false); + $parameterList[] = $parameter->format(); } - if ($allowHtml === null) { - return '' . $this->joinParameterList($parameterList, $plainParameterList, $allowHtml) . ''; - } - return $this->joinParameterList($parameterList, $plainParameterList, $allowHtml); - } - - /** - * Returns a list of grouped parameters - * - * 2 parameters are joined by "and": - * => A and B - * Up to 5 parameters are joined by "," and "and": - * => A, B, C, D and E - * More than 5 parameters are joined by "," and trimmed: - * => A, B, C and #n more - * - * @param array $parameterList - * @param array $plainParameterList - * @param bool $allowHtml - * @return string - */ - protected function joinParameterList($parameterList, $plainParameterList, $allowHtml) { - if (empty($parameterList)) { - return ''; - } - if ($allowHtml === null) { - return implode('', $parameterList); - } - - $count = sizeof($parameterList); - $lastItem = array_pop($parameterList); - - if ($count === 1) { - return $lastItem; - } else if ($count === 2) { - $firstItem = array_pop($parameterList); - return (string) $this->l->t('%s and %s', array($firstItem, $lastItem)); - } else if ($count <= 5) { - $list = implode($this->l->t(', '), $parameterList); - return (string) $this->l->t('%s and %s', array($list, $lastItem)); - } - - $firstParams = array_slice($parameterList, 0, 3); - $firstList = implode($this->l->t(', '), $firstParams); - $trimmedParams = array_slice($plainParameterList, 3); - $trimmedList = implode($this->l->t(', '), $trimmedParams); - - if ($allowHtml) { - return (string) $this->l->n( - '%s and %n more', - '%s and %n more', - $count - 3, - array($firstList, 'class="has-tooltip" title="' . Util::sanitizeHTML($trimmedList) . '"')); - } - return (string) $this->l->n('%s and %n more', '%s and %n more', $count - 3, array($firstList)); + return '' . implode('', $parameterList) . ''; } } diff --git a/lib/parameter/factory.php b/lib/parameter/factory.php index 05ebeed3..6f2f908b 100644 --- a/lib/parameter/factory.php +++ b/lib/parameter/factory.php @@ -49,9 +49,6 @@ class Factory { /** @var IL10N */ protected $l; - /** @var IConfig */ - protected $config; - /** @var ViewInfoCache */ protected $infoCache; @@ -66,7 +63,6 @@ class Factory { * @param IUserManager $userManager * @param IURLGenerator $urlGenerator * @param IContactsManager $contactsManager - * @param IConfig $config * @param ViewInfoCache $infoCache, * @param IL10N $l * @param string $user @@ -75,7 +71,6 @@ class Factory { IUserManager $userManager, IURLGenerator $urlGenerator, IContactsManager $contactsManager, - IConfig $config, ViewInfoCache $infoCache, IL10N $l, $user) { @@ -83,7 +78,6 @@ class Factory { $this->userManager = $userManager; $this->urlGenerator = $urlGenerator; $this->contactsManager = $contactsManager; - $this->config = $config; $this->infoCache = $infoCache; $this->l = $l; $this->user = $user; @@ -133,7 +127,7 @@ class Factory { if ($formatter === 'file') { return new FileFormatter($this->infoCache, $this->urlGenerator, $this->l, $this->user); } else if ($formatter === 'username') { - return new UserFormatter($this->userManager, $this->config, $this->l); + return new UserFormatter($this->userManager, $this->l); } else if ($formatter === 'federated_cloud_id') { return new CloudIDFormatter($this->contactsManager); } else { diff --git a/lib/parameter/iparameter.php b/lib/parameter/iparameter.php index c27d9b36..b76ea098 100644 --- a/lib/parameter/iparameter.php +++ b/lib/parameter/iparameter.php @@ -38,9 +38,7 @@ interface IParameter { public function getParameterInfo(); /** - * @param bool|null $allowHtml Should HTML be used to format the parameter? - * @param bool|null $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ - public function format($allowHtml, $verbose = false); + public function format(); } diff --git a/lib/parameter/parameter.php b/lib/parameter/parameter.php index 0c190ed5..c34750cd 100644 --- a/lib/parameter/parameter.php +++ b/lib/parameter/parameter.php @@ -78,11 +78,9 @@ class Parameter implements IParameter { } /** - * @param bool $allowHtml Should HTML be used to format the parameter? - * @param bool $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ - public function format($allowHtml, $verbose = false) { - return $this->formatter->format($this->event, $this->parameter, $allowHtml, $verbose); + public function format() { + return $this->formatter->format($this->event, $this->parameter); } } diff --git a/tests/datahelpertest.php b/tests/datahelpertest.php index f508d602..3fcd9b9e 100644 --- a/tests/datahelpertest.php +++ b/tests/datahelpertest.php @@ -22,10 +22,7 @@ namespace OCA\Activity\Tests; -use OC\ActivityManager; use OCA\Activity\DataHelper; -use OCA\Activity\Parameter\Factory; -use OCA\Activity\Tests\Mock\Extension; class DataHelperTest extends TestCase { protected $originalWEBROOT; @@ -91,33 +88,24 @@ class DataHelperTest extends TestCase { } } - protected function getParameter($allowHtml, $verbose, $return) { + protected function getParameter($return) { $parameter = $this->getMockBuilder('OCA\Activity\Parameter\IParameter') ->disableOriginalConstructor() ->getMock(); $parameter->expects($this->once()) ->method('format') - ->with($allowHtml, $verbose) ->willReturn($return); return $parameter; } public function dataTranslation() { return [ - ['app1', 'text1', [], [], true, true, false, 'lang'], - ['app2', 'text2', [], [], true, false, false, 'lang'], - ['app2', 'text2', [], [], false, true, false, 'lang'], - ['app2', 'text2', [], [], false, false, false, 'lang'], - ['app2', 'text2', [], [], false, false, 'manager', 'manager'], + ['app1', 'text1', [], [], false, 'lang'], + ['app2', 'text2', [], [], false, 'lang'], + ['app2', 'text2', [], [], 'manager', 'manager'], - ['app2', 'text2', [$this->getParameter(true, false, 'return1')], ['return1'], true, true, 'manager', 'manager'], - ['app2', 'text2', [$this->getParameter(true, true, 'return1')], ['return1'], false, true, 'manager', 'manager'], - ['app2', 'text2', [$this->getParameter(false, false, 'return1')], ['return1'], true, false, 'manager', 'manager'], - ['app2', 'text2', [$this->getParameter(false, true, 'return1')], ['return1'], false, false, 'manager', 'manager'], - ['app2', 'text2', [$this->getParameter(true, false, 'return2')], ['return2'], true, true, false, 'lang'], - ['app2', 'text2', [$this->getParameter(true, true, 'return2')], ['return2'], false, true, false, 'lang'], - ['app2', 'text2', [$this->getParameter(false, false, 'return2')], ['return2'], true, false, false, 'lang'], - ['app2', 'text2', [$this->getParameter(false, true, 'return2')], ['return2'], false, false, false, 'lang'], + ['app2', 'text2', [$this->getParameter('return1')], ['return1'], 'manager', 'manager'], + ['app2', 'text2', [$this->getParameter('return2')], ['return2'], false, 'lang'], ]; } @@ -128,16 +116,14 @@ class DataHelperTest extends TestCase { * @param string $text * @param array $params * @param array $prepared - * @param bool $stripPath - * @param bool $highlightParams * @param bool|string $managerReturn * @param string $expected */ - public function testTranslation($app, $text, array $params, array $prepared, $stripPath, $highlightParams, $managerReturn, $expected) { + public function testTranslation($app, $text, array $params, array $prepared, $managerReturn, $expected) { $this->activityManager->expects($this->once()) ->method('translate') - ->with($app, $text, $prepared, $stripPath, $highlightParams) + ->with($app, $text, $prepared, false, false) ->willReturn($managerReturn); if ($managerReturn === false) { $l = $this->getMockBuilder('OCP\IL10N') @@ -156,31 +142,16 @@ class DataHelperTest extends TestCase { $helper = $this->getHelper(); $this->assertSame( $expected, - (string) $helper->translation($app, $text, $params, $stripPath, $highlightParams) + (string) $helper->translation($app, $text, $params) ); } - public function dataTranslationNoText() { - return [ - [true, true], - [true, false], - [false, true], - [false, false], - ]; - } - - /** - * @dataProvider dataTranslationNoText - * - * @param bool $stripPath - * @param bool $highlightParams - */ - public function testTranslationNoText($stripPath, $highlightParams) { + public function testTranslationNoText() { $this->activityManager->expects($this->never()) ->method('translate'); $helper = $this->getHelper(); - $this->assertSame('', $helper->translation('', '', [], $stripPath, $highlightParams)); + $this->assertSame('', $helper->translation('', '', [])); } public function dataGetSpecialParameterList() { @@ -226,15 +197,7 @@ class DataHelperTest extends TestCase { 'message' => 'message1', 'messageparams_array' => [], 'subjectparams' => [], - 'subject_prepared' => 'translation1', - 'subjectformatted' => [ - 'trimmed' => 'translation2', - 'full' => 'translation3', - 'markup' => [ - 'trimmed' => 'translation4', - 'full' => 'translation5', - ], - ], + 'subject_prepared' => 'translation', ], ], [ @@ -252,15 +215,7 @@ class DataHelperTest extends TestCase { 'subjectparams_array' => [], 'message' => 'message1', 'messageparams' => [], - 'message_prepared' => 'translation1', - 'messageformatted' => [ - 'trimmed' => 'translation2', - 'full' => 'translation3', - 'markup' => [ - 'trimmed' => 'translation4', - 'full' => 'translation5', - ], - ], + 'message_prepared' => 'translation', ], ], ]; @@ -276,21 +231,11 @@ class DataHelperTest extends TestCase { public function testFormatString(array $activity, $message, array $expected) { $instance = $this->getHelper(['translation']); - global $call; - $call = 0; - $instance->expects($this->exactly(5)) + $instance->expects($this->once()) ->method('translation') - ->withConsecutive( - [$activity['app'], $activity[$message], $activity[$message . 'params_array'], null, null], - [$activity['app'], $activity[$message], $activity[$message . 'params_array'], true, false], - [$activity['app'], $activity[$message], $activity[$message . 'params_array'], false, false], - [$activity['app'], $activity[$message], $activity[$message . 'params_array'], true, true], - [$activity['app'], $activity[$message], $activity[$message . 'params_array'], false, true] - ) + ->with($activity['app'], $activity[$message], $activity[$message . 'params_array']) ->willReturnCallback(function() { - global $call; - $call++; - return 'translation' . $call; + return 'translation'; }); $this->assertSame($expected, $instance->formatStrings($activity, $message)); diff --git a/tests/formatter/baseformattertest.php b/tests/formatter/baseformattertest.php index fd162dc4..d616397a 100644 --- a/tests/formatter/baseformattertest.php +++ b/tests/formatter/baseformattertest.php @@ -46,11 +46,8 @@ class BaseFormatterTest extends TestCase { public function dataFormat() { return [ - ['paraeter1', true, true, 'para<m>eter1'], - ['paraeter1', false, true, 'paraeter1'], - ['paraeter1', true, false, 'para<m>eter1'], - ['paraeter1', false, false, 'paraeter1'], - ['paraeter1', null, null, 'para<m>eter1'], + ['paraeter1', 'para<m>eter1'], + ['paraeter2', 'para<m>eter2'], ]; } @@ -58,17 +55,15 @@ class BaseFormatterTest extends TestCase { * @dataProvider dataFormat * * @param string $parameter - * @param bool $allowHtml - * @param bool $verbose * @param string $expected */ - public function testFormat($parameter, $allowHtml, $verbose, $expected) { + public function testFormat($parameter, $expected) { /** @var \OCP\Activity\IEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder('OCP\Activity\IEvent') ->disableOriginalConstructor() ->getMock(); $formatter = $this->getFormatter(); - $this->assertSame($expected, $formatter->format($event, $parameter, $allowHtml, $verbose)); + $this->assertSame($expected, $formatter->format($event, $parameter)); } } diff --git a/tests/formatter/cloudidformattertest.php b/tests/formatter/cloudidformattertest.php index a00e17ac..cf9ceff5 100644 --- a/tests/formatter/cloudidformattertest.php +++ b/tests/formatter/cloudidformattertest.php @@ -59,21 +59,10 @@ class CloudIDFormatterTest extends TestCase { public function dataFormat() { return [ - ['test', true, true, 'test'], - ['test', false, true, 'test'], - ['test', true, false, 'test'], - ['test', false, false, 'test'], - - ['test@localhost', true, true, 'test@localhost'], - ['test@localhost', false, true, 'test@localhost'], - ['test@localhost', true, false, 'test@…'], - ['test@localhost', false, false, 'test@…'], - ['test@localhost', null, null, 'test@localhost'], - - ['tst@lcalhost', true, true, 't<e>st@l<o>calhost'], - ['tst@lcalhost', false, true, 'tst@lcalhost'], - ['tst@lcalhost', true, false, 't<e>st@…'], - ['tst@lcalhost', false, false, 'tst@…'], + ['test1', 'test1'], + ['test1@localhost1', 'test1@localhost1'], + ['test2@localhost2', 'test2@localhost2'], + ['tst@lcalhost', 't<e>st@l<o>calhost'], ]; } @@ -82,11 +71,9 @@ class CloudIDFormatterTest extends TestCase { * @dataProvider dataFormat * * @param string $parameter - * @param bool $allowHtml - * @param bool $verbose * @param string $expected */ - public function testFormat($parameter, $allowHtml, $verbose, $expected) { + public function testFormat($parameter, $expected) { /** @var \OCP\Activity\IEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder('OCP\Activity\IEvent') ->disableOriginalConstructor() @@ -97,7 +84,7 @@ class CloudIDFormatterTest extends TestCase { ->method('getDisplayNameFromContact') ->willThrowException(new \OutOfBoundsException()); - $this->assertSame($expected, $formatter->format($event, $parameter, $allowHtml, $verbose)); + $this->assertSame($expected, $formatter->format($event, $parameter)); } public function dataGetDisplayNameFromContact() { diff --git a/tests/formatter/fileformattertest.php b/tests/formatter/fileformattertest.php index ca3c28d8..4d71b467 100644 --- a/tests/formatter/fileformattertest.php +++ b/tests/formatter/fileformattertest.php @@ -98,33 +98,15 @@ class FileFormatterTest extends TestCase { ]; return [ - ['user1', '/test1', false, [], true, true, 'test1'], - ['user1', '/test1', true, [], true, true, 'test1'], - ['user1', '/test1', false, [], false, true, 'test1'], - ['user1', '/test1', true, [], false, true, 'test1'], - ['user1', '/test1', false, [], true, false, 'test1'], - ['user1', '/test1', true, [], true, false, 'test1'], - ['user1', '/test1', false, [], false, false, 'test1'], - ['user1', '/test1', true, [], false, false, 'test1'], - ['user1', '/test1/test2', false, [], true, true, 'test1/test2'], - ['user1', '/test1/test2', true, [], true, true, 'test1/test2'], - ['user1', '/test1/test2', false, [], false, true, 'test1/test2'], - ['user1', '/test1/test2', true, [], false, true, 'test1/test2'], - ['user1', '/test1/test2', false, [], true, false, 'test2'], - ['user1', '/test1/test2', true, [], true, false, 'test2'], - ['user1', '/test1/test2', false, [], false, false, 'test2'], - ['user1', '/test1/test2', true, [], false, false, 'test2'], + ['user1', '/test1', false, [], 'test1'], + ['user1', '/test1', true, [], 'test1'], + ['user1', '/test1/test2', false, [], 'test1/test2'], + ['user1', '/test1/test2', true, [], 'test1/test2'], - ['user1', '/test1/test2', false, $trash0, true, true, 'test1/test2'], - ['user1', '/test1/test2', true, $trash1, true, true, 'test1/test2'], - ['user1', '/test1/test2', false, $trash0, false, true, 'test1/test2'], - ['user1', '/test1/test2', true, $trash1, false, true, 'test1/test2'], - ['user1', '/test1/test2', false, $trash0, true, false, 'test2'], - ['user1', '/test1/test2', true, $trash1, true, false, 'test2'], - ['user1', '/test1/test2', false, $trash0, false, false, 'test2'], - ['user1', '/test1/test2', true, $trash1, false, false, 'test2'], + ['user1', '/test1/test2', false, $trash0, 'test1/test2'], + ['user1', '/test1/test2', true, $trash1, 'test1/test2'], - ['user2', '/test1', false, [], true, true, 'test1'], + ['user2', '/test1', false, [], 'test1'], ]; } @@ -135,11 +117,9 @@ class FileFormatterTest extends TestCase { * @param string $parameter * @param bool $isDir * @param array $info - * @param bool $allowHtml - * @param bool $verbose * @param string $expected */ - public function testFormat($user, $parameter, $isDir, array $info, $allowHtml, $verbose, $expected) { + public function testFormat($user, $parameter, $isDir, array $info, $expected) { /** @var \OCP\Activity\IEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder('OCP\Activity\IEvent') ->disableOriginalConstructor() @@ -190,7 +170,7 @@ class FileFormatterTest extends TestCase { ]); } - $this->assertSame($expected, $formatter->format($event, $parameter, $allowHtml, $verbose)); + $this->assertSame($expected, $formatter->format($event, $parameter)); } public function dataFixLegacyFilename() { diff --git a/tests/formatter/userformattertest.php b/tests/formatter/userformattertest.php index 25839161..14cab2d4 100644 --- a/tests/formatter/userformattertest.php +++ b/tests/formatter/userformattertest.php @@ -31,9 +31,6 @@ class UserFormatterTest extends TestCase { /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */ protected $userManager; - /** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */ - protected $config; - /** @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject */ protected $l; @@ -44,10 +41,6 @@ class UserFormatterTest extends TestCase { ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder('OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->l = $this->getMockBuilder('OCP\IL10N') ->disableOriginalConstructor() ->getMock(); @@ -61,14 +54,12 @@ class UserFormatterTest extends TestCase { if (empty($methods)) { return new UserFormatter( $this->userManager, - $this->config, $this->l ); } else { return $this->getMockBuilder('OCA\Activity\Formatter\UserFormatter') ->setConstructorArgs([ $this->userManager, - $this->config, $this->l, ]) ->setMethods($methods) @@ -78,22 +69,16 @@ class UserFormatterTest extends TestCase { public function dataFormatRemoteUser() { return [ - [true, true, '"remote user"'], - [false, true, '"remote user"'], - [true, false, '"remote user"'], - [false, false, '"remote user"'], - [null, null, ''], + [''], ]; } /** * @dataProvider dataFormatRemoteUser * - * @param bool $allowHtml - * @param bool $verbose * @param string $expected */ - public function testFormatRemoteUser($allowHtml, $verbose, $expected) { + public function testFormatRemoteUser($expected) { /** @var \OCP\Activity\IEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder('OCP\Activity\IEvent') ->disableOriginalConstructor() @@ -108,7 +93,7 @@ class UserFormatterTest extends TestCase { ->method('get'); $formatter = $this->getFormatter(); - $this->assertSame($expected, $formatter->format($event, '', $allowHtml, $verbose)); + $this->assertSame($expected, $formatter->format($event, '')); } protected function getUser($displayName) { @@ -123,27 +108,9 @@ class UserFormatterTest extends TestCase { public function dataFormat() { return [ - ['nouser', null, false, true, true, 'nouser'], - ['nouser', null, false, false, true, 'nouser'], - ['nouser', null, false, true, false, 'nouser'], - ['nouser', null, false, false, false, 'nouser'], - - ['user', $this->getUser('Display'), false, true, true, 'Display'], - ['user', $this->getUser('Display'), false, false, true, 'Display'], - ['user', $this->getUser('Display'), false, true, false, 'Display'], - ['user', $this->getUser('Display'), false, false, false, 'Display'], - - ['nouser1', null, true, true, true, '
nouser1'], - ['nouser2', null, true, false, true, 'nouser2'], - ['nouser3', null, true, true, false, '
nouser3'], - ['nouser4', null, true, false, false, 'nouser4'], - - ['user1', $this->getUser('Display'), true, true, true, '
Display'], - ['user2', $this->getUser('Display'), true, false, true, 'Display'], - ['user3', $this->getUser('Display'), true, true, false, '
Display'], - ['user4', $this->getUser('Display'), true, false, false, 'Display'], - ['user5', $this->getUser('Display5'), true, null, null, 'user5'], - ['user5', $this->getUser('Display5'), false, null, null, 'user5'], + ['nouser', null, 'nouser'], + ['user1', $this->getUser('Display1'), 'user1'], + ['user5', $this->getUser('Display5'), 'user5'], ]; } @@ -152,12 +119,9 @@ class UserFormatterTest extends TestCase { * * @param string $parameter * @param null|\OCP\IUser $user - * @param bool $avatarsEnabled - * @param bool $allowHtml - * @param bool $verbose * @param string $expected */ - public function testFormat($parameter, $user, $avatarsEnabled, $allowHtml, $verbose, $expected) { + public function testFormat($parameter, $user, $expected) { /** @var \OCP\Activity\IEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder('OCP\Activity\IEvent') ->disableOriginalConstructor() @@ -169,12 +133,8 @@ class UserFormatterTest extends TestCase { ->method('get') ->with($parameter) ->willReturn($user); - $this->config->expects($this->any()) - ->method('getSystemValue') - ->with('enable_avatars', true) - ->willReturn($avatarsEnabled); $formatter = $this->getFormatter(); - $this->assertSame($expected, $formatter->format($event, $parameter, $allowHtml, $verbose)); + $this->assertSame($expected, $formatter->format($event, $parameter)); } } diff --git a/tests/parameter/collectiontest.php b/tests/parameter/collectiontest.php index 78309703..677b157a 100644 --- a/tests/parameter/collectiontest.php +++ b/tests/parameter/collectiontest.php @@ -159,127 +159,29 @@ class CollectionTest extends TestCase { $this->assertCount(2, $this->invokePrivate($collection, 'parameters')); } - public function dataFormat() { - return [ - [true, true, ['One', 'Two'], ['OneFalse', 'TwoFalse']], - [true, false, ['One', 'Two'], ['OneFalse', 'TwoFalse']], - [false, true, ['One', 'Two'], ['OneFalse', 'TwoFalse']], - [false, false, ['OneFalse', 'TwoFalse'], ['OneFalse', 'TwoFalse']], - [null, null, ['OneNull', 'TwoNull'], ['OneFalse', 'TwoFalse'], 'return(joinParameterList)'], - ]; - } - - /** - * @dataProvider dataFormat - * - * @param bool $allowHtml - * @param bool $verbose - * @param array $parameterList - * @param array $plainParameterList - * @param string $expected - */ - public function testFormat($allowHtml, $verbose, array $parameterList, array $plainParameterList, $expected = 'return(joinParameterList)') { - $collection = $this->getCollection(['joinParameterList']); + public function testFormat() { + $collection = $this->getCollection(); /** @var \OCA\Activity\Parameter\IParameter|\PHPUnit_Framework_MockObject_MockObject $parameter1 */ $parameter1 = $this->getMockBuilder('OCA\Activity\Parameter\IParameter') ->disableOriginalConstructor() ->getMock(); - $parameter1->expects($this->exactly(2)) + $parameter1->expects($this->once()) ->method('format') - ->willReturnMap([ - [false, false, 'OneFalse'], - [null, null, 'OneNull'], - [$allowHtml, $verbose, 'One'], - ]); + ->willReturn('OneNull'); /** @var \OCA\Activity\Parameter\IParameter|\PHPUnit_Framework_MockObject_MockObject $parameter2 */ $parameter2 = $this->getMockBuilder('OCA\Activity\Parameter\IParameter') ->disableOriginalConstructor() ->getMock(); - $parameter2->expects($this->exactly(2)) + $parameter2->expects($this->once()) ->method('format') - ->willReturnMap([ - [false, false, 'TwoFalse'], - [null, null, 'TwoNull'], - [$allowHtml, $verbose, 'Two'], - ]); + ->willReturn('TwoNull'); $this->invokePrivate($collection, 'parameters', [ [$parameter1, $parameter2] ]); - $collection->expects($this->once()) - ->method('joinParameterList') - ->with($parameterList, $plainParameterList, $allowHtml) - ->willReturn('return(joinParameterList)'); - - $this->assertSame($expected, $collection->format($allowHtml, $verbose)); - } - - public function dataJoinParameterList() { - return [ - [0, true, ''], - [0, false, ''], - - [1, true, 'item1'], - [1, false, 'item1'], - - [2, true, 'item1 and item2'], - [2, false, 'item1 and item2'], - - [3, true, 'item1, item2 and item3'], - [3, false, 'item1, item2 and item3'], - [3, null, 'item1item2item3'], - [ - 6, true, - 'item1, item2, item3 and 3 more', - ], - [ - 6, false, - 'item1, item2, item3 and 3 more', - ], - ]; - } - - /** - * @dataProvider dataJoinParameterList - * - * @param int $numParameters - * @param bool $allowHtml - * @param string $expected - */ - public function testJoinParameterList($numParameters, $allowHtml, $expected) { - $parameterList = $plainParameterList = []; - for ($i = 1; $i <= $numParameters; $i++) { - if ($allowHtml) { - $parameterList[] = 'item' . $i . ''; - } else { - $parameterList[] = 'item' . $i; - } - $plainParameterList[] = 'item' . $i; - } - - $collection = $this->getCollection(); - - $this->l->expects($this->any()) - ->method('t') - ->willReturnCallback(function ($string, $parameters) { - return vsprintf($string, $parameters); - }); - $this->l->expects($this->any()) - ->method('n') - ->willReturnCallback(function ($singular, $plural, $count, $parameters) { - if ($count === 1) { - $string = str_replace('%n', $count, $singular); - } else { - $string = str_replace('%n', $count, $plural); - } - return vsprintf($string, $parameters); - }); - - $this->assertSame($expected, $this->invokePrivate($collection, 'joinParameterList', [ - $parameterList, $plainParameterList, $allowHtml - ])); + $this->assertSame('OneNullTwoNull', $collection->format()); } } diff --git a/tests/parameter/factorytest.php b/tests/parameter/factorytest.php index 18826e4d..ce4eca55 100644 --- a/tests/parameter/factorytest.php +++ b/tests/parameter/factorytest.php @@ -91,7 +91,6 @@ class FactoryTest extends TestCase { $this->userManager, $this->urlGenerator, $this->contactsManager, - $this->config, $this->infoCache, $this->l, $user @@ -103,7 +102,6 @@ class FactoryTest extends TestCase { $this->userManager, $this->urlGenerator, $this->contactsManager, - $this->config, $this->infoCache, $this->l, $user, diff --git a/tests/parameter/parametertest.php b/tests/parameter/parametertest.php index 27cdb5b2..62f039f5 100644 --- a/tests/parameter/parametertest.php +++ b/tests/parameter/parametertest.php @@ -109,10 +109,8 @@ class ParameterTest extends TestCase { public function dataFormat() { return [ - ['parameter1', true, true], - ['parameter2', true, false], - ['parameter3', false, true], - ['parameter4', false, false], + ['parameter1'], + ['parameter2'], ]; } @@ -120,17 +118,15 @@ class ParameterTest extends TestCase { * @dataProvider dataFormat * * @param string $parameter - * @param bool $allowHtml - * @param bool $verbose */ - public function testFormat($parameter, $allowHtml, $verbose) { + public function testFormat($parameter) { $instance = $this->getParameter($parameter); $this->formatter->expects($this->once()) ->method('format') - ->with($this->event, $parameter, $allowHtml, $verbose) + ->with($this->event, $parameter) ->willReturn('formatted()'); - $this->assertSame('formatted()', $instance->format($allowHtml, $verbose)); + $this->assertSame('formatted()', $instance->format()); } }