зеркало из https://github.com/nextcloud/activity.git
Remove old code
This commit is contained in:
Родитель
3f691c8d05
Коммит
18a04281d9
|
@ -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')
|
||||
|
|
|
@ -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 `<strong>`, 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;
|
||||
}
|
||||
|
|
|
@ -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 '<parameter>' . Util::sanitizeHTML($parameter) . '</parameter>';
|
||||
}
|
||||
|
||||
if ($allowHtml) {
|
||||
return '<strong>' . Util::sanitizeHTML($parameter) . '</strong>';
|
||||
} else {
|
||||
return $parameter;
|
||||
}
|
||||
public function format(IEvent $event, $parameter) {
|
||||
return '<parameter>' . Util::sanitizeHTML($parameter) . '</parameter>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 '<federated-cloud-id display-name="' . Util::sanitizeHTML($displayName) . '" user="' . $user . '" server="' . $server . '">' . Util::sanitizeHTML($parameter) . '</federated-cloud-id>';
|
||||
}
|
||||
|
||||
if ($allowHtml) {
|
||||
$title = ' title="' . Util::sanitizeHTML($parameter) . '"';
|
||||
return '<strong class="has-tooltip"' . $title . '>' . Util::sanitizeHTML($displayName) . '</strong>';
|
||||
} else {
|
||||
return $displayName;
|
||||
}
|
||||
return '<federated-cloud-id display-name="' . Util::sanitizeHTML($displayName) . '" user="' . Util::sanitizeHTML($user) . '" server="' . Util::sanitizeHTML($server) . '">' . Util::sanitizeHTML($parameter) . '</federated-cloud-id>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 '<file link="' . $fileLink . '" id="' . Util::sanitizeHTML($fileId) . '">' . Util::sanitizeHTML($param) . '</file>';
|
||||
}
|
||||
|
||||
if ($verbose || $path === '') {
|
||||
if (!$allowHtml) {
|
||||
return $param;
|
||||
}
|
||||
return '<a class="filename" href="' . $fileLink . '">' . Util::sanitizeHTML($param) . '</a>';
|
||||
}
|
||||
|
||||
if (!$allowHtml) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
$title = ' title="' . $this->l->t('in %s', array(Util::sanitizeHTML($path))) . '"';
|
||||
return '<a class="filename has-tooltip" href="' . $fileLink . '"' . $title . '>' . Util::sanitizeHTML($name) . '</a>';
|
||||
return '<file link="' . $fileLink . '" id="' . Util::sanitizeHTML($fileId) . '">' . Util::sanitizeHTML($param) . '</file>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 '<user display-name="' . Util::sanitizeHTML($this->l->t('"remote user"')) . '">' . Util::sanitizeHTML('') . '</user>';
|
||||
}
|
||||
if ($allowHtml) {
|
||||
return '<strong>' . $this->l->t('"remote user"') . '</strong>';
|
||||
} else {
|
||||
return $this->l->t('"remote user"');
|
||||
}
|
||||
return '<user display-name="' . Util::sanitizeHTML($this->l->t('"remote user"')) . '">' . Util::sanitizeHTML('') . '</user>';
|
||||
}
|
||||
|
||||
$user = $this->manager->get($parameter);
|
||||
$displayName = ($user) ? $user->getDisplayName() : $parameter;
|
||||
$parameter = Util::sanitizeHTML($parameter);
|
||||
|
||||
if ($allowHtml === null) {
|
||||
return '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($parameter) . '</user>';
|
||||
}
|
||||
|
||||
if ($allowHtml) {
|
||||
$avatarPlaceholder = '';
|
||||
if ($this->config->getSystemValue('enable_avatars', true)) {
|
||||
$avatarPlaceholder = '<div class="avatar" data-user="' . $parameter . '"></div>';
|
||||
}
|
||||
return $avatarPlaceholder . '<strong>' . Util::sanitizeHTML($displayName) . '</strong>';
|
||||
} else {
|
||||
return $displayName;
|
||||
}
|
||||
return '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($parameter) . '</user>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 '<collection>' . $this->joinParameterList($parameterList, $plainParameterList, $allowHtml) . '</collection>';
|
||||
}
|
||||
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 <strong %s>%n more</strong>',
|
||||
'%s and <strong %s>%n more</strong>',
|
||||
$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 '<collection>' . implode('', $parameterList) . '</collection>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -46,11 +46,8 @@ class BaseFormatterTest extends TestCase {
|
|||
|
||||
public function dataFormat() {
|
||||
return [
|
||||
['para<m>eter1', true, true, '<strong>para<m>eter1</strong>'],
|
||||
['para<m>eter1', false, true, 'para<m>eter1'],
|
||||
['para<m>eter1', true, false, '<strong>para<m>eter1</strong>'],
|
||||
['para<m>eter1', false, false, 'para<m>eter1'],
|
||||
['para<m>eter1', null, null, '<parameter>para<m>eter1</parameter>'],
|
||||
['para<m>eter1', '<parameter>para<m>eter1</parameter>'],
|
||||
['para<m>eter2', '<parameter>para<m>eter2</parameter>'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,21 +59,10 @@ class CloudIDFormatterTest extends TestCase {
|
|||
|
||||
public function dataFormat() {
|
||||
return [
|
||||
['test', true, true, '<strong class="has-tooltip" title="test">test</strong>'],
|
||||
['test', false, true, 'test'],
|
||||
['test', true, false, '<strong class="has-tooltip" title="test">test</strong>'],
|
||||
['test', false, false, 'test'],
|
||||
|
||||
['test@localhost', true, true, '<strong class="has-tooltip" title="test@localhost">test@localhost</strong>'],
|
||||
['test@localhost', false, true, 'test@localhost'],
|
||||
['test@localhost', true, false, '<strong class="has-tooltip" title="test@localhost">test@…</strong>'],
|
||||
['test@localhost', false, false, 'test@…'],
|
||||
['test@localhost', null, null, '<federated-cloud-id display-name="test@…" user="test" server="localhost">test@localhost</federated-cloud-id>'],
|
||||
|
||||
['t<e>st@l<o>calhost', true, true, '<strong class="has-tooltip" title="t<e>st@l<o>calhost">t<e>st@l<o>calhost</strong>'],
|
||||
['t<e>st@l<o>calhost', false, true, 't<e>st@l<o>calhost'],
|
||||
['t<e>st@l<o>calhost', true, false, '<strong class="has-tooltip" title="t<e>st@l<o>calhost">t<e>st@…</strong>'],
|
||||
['t<e>st@l<o>calhost', false, false, 't<e>st@…'],
|
||||
['test1', '<federated-cloud-id display-name="test1" user="test1" server="">test1</federated-cloud-id>'],
|
||||
['test1@localhost1', '<federated-cloud-id display-name="test1@…" user="test1" server="localhost1">test1@localhost1</federated-cloud-id>'],
|
||||
['test2@localhost2', '<federated-cloud-id display-name="test2@…" user="test2" server="localhost2">test2@localhost2</federated-cloud-id>'],
|
||||
['t<e>st@l<o>calhost', '<federated-cloud-id display-name="t<e>st@…" user="t<e>st" server="l<o>calhost">t<e>st@l<o>calhost</federated-cloud-id>'],
|
||||
|
||||
];
|
||||
}
|
||||
|
@ -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() {
|
||||
|
|
|
@ -98,33 +98,15 @@ class FileFormatterTest extends TestCase {
|
|||
];
|
||||
|
||||
return [
|
||||
['user1', '/test1', false, [], true, true, '<a class="filename" href="files/index.php?dir=%2F&scrollto=test1">test1</a>'],
|
||||
['user1', '/test1', true, [], true, true, '<a class="filename" href="files/index.php?dir=%2Ftest1">test1</a>'],
|
||||
['user1', '/test1', false, [], false, true, 'test1'],
|
||||
['user1', '/test1', true, [], false, true, 'test1'],
|
||||
['user1', '/test1', false, [], true, false, '<a class="filename" href="files/index.php?dir=%2F&scrollto=test1">test1</a>'],
|
||||
['user1', '/test1', true, [], true, false, '<a class="filename" href="files/index.php?dir=%2Ftest1">test1</a>'],
|
||||
['user1', '/test1', false, [], false, false, 'test1'],
|
||||
['user1', '/test1', true, [], false, false, 'test1'],
|
||||
['user1', '/test1/test2', false, [], true, true, '<a class="filename" href="files/index.php?dir=%2Ftest1&scrollto=test2">test1/test2</a>'],
|
||||
['user1', '/test1/test2', true, [], true, true, '<a class="filename" href="files/index.php?dir=%2Ftest1%2Ftest2">test1/test2</a>'],
|
||||
['user1', '/test1/test2', false, [], false, true, 'test1/test2'],
|
||||
['user1', '/test1/test2', true, [], false, true, 'test1/test2'],
|
||||
['user1', '/test1/test2', false, [], true, false, '<a class="filename has-tooltip" href="files/index.php?dir=%2Ftest1&scrollto=test2" title="in test1">test2</a>'],
|
||||
['user1', '/test1/test2', true, [], true, false, '<a class="filename has-tooltip" href="files/index.php?dir=%2Ftest1%2Ftest2" title="in test1">test2</a>'],
|
||||
['user1', '/test1/test2', false, [], false, false, 'test2'],
|
||||
['user1', '/test1/test2', true, [], false, false, 'test2'],
|
||||
['user1', '/test1', false, [], '<file link="files/index.php?dir=%2F&scrollto=test1" id="">test1</file>'],
|
||||
['user1', '/test1', true, [], '<file link="files/index.php?dir=%2Ftest1" id="">test1</file>'],
|
||||
['user1', '/test1/test2', false, [], '<file link="files/index.php?dir=%2Ftest1&scrollto=test2" id="">test1/test2</file>'],
|
||||
['user1', '/test1/test2', true, [], '<file link="files/index.php?dir=%2Ftest1%2Ftest2" id="">test1/test2</file>'],
|
||||
|
||||
['user1', '/test1/test2', false, $trash0, true, true, '<a class="filename" href="files/index.php?dir=%2F&scrollto=test2&view=trashbin">test1/test2</a>'],
|
||||
['user1', '/test1/test2', true, $trash1, true, true, '<a class="filename" href="files/index.php?dir=%2Ftest2&view=trashbin">test1/test2</a>'],
|
||||
['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, '<a class="filename has-tooltip" href="files/index.php?dir=%2F&scrollto=test2&view=trashbin" title="in test1">test2</a>'],
|
||||
['user1', '/test1/test2', true, $trash1, true, false, '<a class="filename has-tooltip" href="files/index.php?dir=%2Ftest2&view=trashbin" title="in test1">test2</a>'],
|
||||
['user1', '/test1/test2', false, $trash0, false, false, 'test2'],
|
||||
['user1', '/test1/test2', true, $trash1, false, false, 'test2'],
|
||||
['user1', '/test1/test2', false, $trash0, '<file link="files/index.php?dir=%2F&scrollto=test2&view=trashbin" id="42">test1/test2</file>'],
|
||||
['user1', '/test1/test2', true, $trash1, '<file link="files/index.php?dir=%2Ftest2&view=trashbin" id="42">test1/test2</file>'],
|
||||
|
||||
['user2', '/test1', false, [], true, true, '<a class="filename" href="files/index.php?dir=%2F&scrollto=test1">test1</a>'],
|
||||
['user2', '/test1', false, [], '<file link="files/index.php?dir=%2F&scrollto=test1" id="">test1</file>'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
|
|
@ -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, '<strong>"remote user"</strong>'],
|
||||
[false, true, '"remote user"'],
|
||||
[true, false, '<strong>"remote user"</strong>'],
|
||||
[false, false, '"remote user"'],
|
||||
[null, null, '<user display-name=""remote user""></user>'],
|
||||
['<user display-name=""remote user""></user>'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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, '<strong>nouser</strong>'],
|
||||
['nouser', null, false, false, true, 'nouser'],
|
||||
['nouser', null, false, true, false, '<strong>nouser</strong>'],
|
||||
['nouser', null, false, false, false, 'nouser'],
|
||||
|
||||
['user', $this->getUser('Display'), false, true, true, '<strong>Display</strong>'],
|
||||
['user', $this->getUser('Display'), false, false, true, 'Display'],
|
||||
['user', $this->getUser('Display'), false, true, false, '<strong>Display</strong>'],
|
||||
['user', $this->getUser('Display'), false, false, false, 'Display'],
|
||||
|
||||
['nouser1', null, true, true, true, '<div class="avatar" data-user="nouser1"></div><strong>nouser1</strong>'],
|
||||
['nouser2', null, true, false, true, 'nouser2'],
|
||||
['nouser3', null, true, true, false, '<div class="avatar" data-user="nouser3"></div><strong>nouser3</strong>'],
|
||||
['nouser4', null, true, false, false, 'nouser4'],
|
||||
|
||||
['user1', $this->getUser('Display'), true, true, true, '<div class="avatar" data-user="user1"></div><strong>Display</strong>'],
|
||||
['user2', $this->getUser('Display'), true, false, true, 'Display'],
|
||||
['user3', $this->getUser('Display'), true, true, false, '<div class="avatar" data-user="user3"></div><strong>Display</strong>'],
|
||||
['user4', $this->getUser('Display'), true, false, false, 'Display'],
|
||||
['user5', $this->getUser('Display5'), true, null, null, '<user display-name="Display5">user5</user>'],
|
||||
['user5', $this->getUser('Display5'), false, null, null, '<user display-name="Display5">user5</user>'],
|
||||
['nouser', null, '<user display-name="nouser">nouser</user>'],
|
||||
['user1', $this->getUser('Display1'), '<user display-name="Display1">user1</user>'],
|
||||
['user5', $this->getUser('Display5'), '<user display-name="Display5">user5</user>'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'], '<collection>return(joinParameterList)</collection>'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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, '<strong>item1</strong>'],
|
||||
[1, false, 'item1'],
|
||||
|
||||
[2, true, '<strong>item1</strong> and <strong>item2</strong>'],
|
||||
[2, false, 'item1 and item2'],
|
||||
|
||||
[3, true, '<strong>item1</strong>, <strong>item2</strong> and <strong>item3</strong>'],
|
||||
[3, false, 'item1, item2 and item3'],
|
||||
[3, null, 'item1item2item3'],
|
||||
[
|
||||
6, true,
|
||||
'<strong>item1</strong>, <strong>item2</strong>, <strong>item3</strong> and <strong class="has-tooltip" title="item4, item5, item6">3 more</strong>',
|
||||
],
|
||||
[
|
||||
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[] = '<strong>item' . $i . '</strong>';
|
||||
} 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('<collection>OneNullTwoNull</collection>', $collection->format());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче