/** * @dataProvider prepareParametersData */ public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '') { if ($createFolder !== '') { $this->view->mkdir('/' . \OCP\User::getUser() . '/files/' . $createFolder); } $this->assertEquals($expected, $this->parameterHelper->prepareParameters($params, $filePosition, $stripPath, $highlightParams)); }
/** * @dataProvider prepareParametersData */ public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '', $enableAvatars = true) { if ($createFolder !== '') { $this->view->expects($this->any())->method('is_dir')->with($createFolder)->willReturn(true); } $this->config->expects($this->any())->method('getSystemValue')->with('enable_avatars', true)->willReturn($enableAvatars); $this->assertEquals($expected, $this->parameterHelper->prepareParameters($params, $filePosition, $stripPath, $highlightParams)); }
/** * @brief Translate an event string with the translations from the app where it was send from * @param string $app The app where this event comes from * @param string $text The text including placeholders * @param array $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, $params, $stripPath = false, $highlightParams = false) { if (!$text) { return ''; } $preparedParams = $this->parameterHelper->prepareParameters($params, $this->parameterHelper->getSpecialParameterList($app, $text), $stripPath, $highlightParams); // Allow apps to correctly translate their activities $translation = $this->activityManager->translate($app, $text, $preparedParams, $stripPath, $highlightParams, $this->l->getLanguageCode()); if ($translation !== false) { return $translation; } $l = Util::getL10N($app, $this->l->getLanguageCode()); return $l->t($text, $preparedParams); }
/** * @brief Translate an event string with the translations from the app where it was send from * @param string $app The app where this event comes from * @param string $text The text including placeholders * @param array $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, $params, $stripPath = false, $highlightParams = false) { if (!$text) { return ''; } $preparedParams = $this->parameterHelper->prepareParameters($params, $this->parameterHelper->getSpecialParameterList($app, $text), $stripPath, $highlightParams); if ($app === 'files') { switch ($text) { case 'created_self': return $this->l->t('You created %1$s', $preparedParams); case 'created_by': return $this->l->t('%2$s created %1$s', $preparedParams); case 'created_public': return $this->l->t('%1$s was created in a public folder', $preparedParams); case 'changed_self': return $this->l->t('You changed %1$s', $preparedParams); case 'changed_by': return $this->l->t('%2$s changed %1$s', $preparedParams); case 'deleted_self': return $this->l->t('You deleted %1$s', $preparedParams); case 'deleted_by': return $this->l->t('%2$s deleted %1$s', $preparedParams); case 'restored_self': return $this->l->t('You restored %1$s', $preparedParams); case 'restored_by': return $this->l->t('%2$s restored %1$s', $preparedParams); case 'shared_user_self': return $this->l->t('You shared %1$s with %2$s', $preparedParams); case 'shared_group_self': return $this->l->t('You shared %1$s with group %2$s', $preparedParams); case 'shared_with_by': return $this->l->t('%2$s shared %1$s with you', $preparedParams); case 'shared_link_self': return $this->l->t('You shared %1$s via link', $preparedParams); } } // Allow other apps to correctly translate their activities $translation = $this->activityManager->translate($app, $text, $preparedParams, $stripPath, $highlightParams, $this->l->getLanguageCode()); if ($translation !== false) { return $translation; } $l = Util::getL10N($app); return $l->t($text, $preparedParams); }
/** * @dataProvider prepareParametersData */ public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '', $enableAvatars = true, $contactsResult = false) { if ($createFolder !== '') { $this->view->expects($this->any())->method('is_dir')->with($createFolder)->willReturn(true); } if ($contactsResult) { $this->contactsManager->expects($this->any())->method('search')->with($params[0], ['CLOUD'])->willReturn([['FN' => 'User3 @ Localhost'], ['FN' => 'User2 @ Localhost', 'CLOUD' => []], ['FN' => 'User @ Localhost', 'CLOUD' => ['username@localhost']]]); } else { $this->contactsManager->expects($this->any())->method('search')->with($this->anything(), ['CLOUD'])->willReturn([]); } $this->config->expects($this->any())->method('getSystemValue')->with('enable_avatars', true)->willReturn($enableAvatars); $this->assertEquals($expected, $this->parameterHelper->prepareParameters($params, $filePosition, $stripPath, $highlightParams)); }