Blame view
sources/apps/activity/tests/parameterhelpertest.php
6.57 KB
|
6d9380f96
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
<?php
/**
* ownCloud - Activity App
*
* @author Joas Schilling
* @copyright 2014 Joas Schilling nickvergessen@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCA\Activity\Tests;
class ParameterHelperTest extends \PHPUnit_Framework_TestCase {
/** @var string */
protected $originalWEBROOT;
/** @var \OCA\Activity\ParameterHelper */
protected $parameterHelper;
/** @var \OC\Files\View */
protected $view;
public function setUp() {
parent::setUp();
$this->originalWEBROOT =\OC::$WEBROOT;
\OC::$WEBROOT = '';
$l = \OCP\Util::getL10N('activity');
$this->view = new \OC\Files\View('');
$this->parameterHelper = new \OCA\Activity\ParameterHelper($this->view, $l);
}
public function tearDown() {
\OC::$WEBROOT = $this->originalWEBROOT;
parent::tearDown();
}
public function prepareParametersData() {
return array(
array(array(), false, false, false, array()),
// No file position: no path strip
array(array('/foo/bar.file'), array(), false, false, array('/foo/bar.file')),
array(array('/foo/bar.file'), array(), true, false, array('/foo/bar.file')),
array(array('/foo/bar.file'), array(), false, true, array('<strong>/foo/bar.file</strong>')),
array(array('/foo/bar.file'), array(), true, true, array('<strong>/foo/bar.file</strong>')),
// Valid file position
array(array('/foo/bar.file'), array(0 => 'file'), true, false, array('bar.file')),
array(array('/folder/trailingslash/fromsharing/'), array(0 => 'file'), true, false, array('fromsharing')),
array(array('/foo/bar.file'), array(0 => 'file'), false, false, array('foo/bar.file')),
array(array('/folder/trailingslash/fromsharing/'), array(0 => 'file'), false, false, array('folder/trailingslash/fromsharing')),
array(array('/foo/bar.file'), array(0 => 'file'), true, true, array(
'<a class="filename tooltip" href="/index.php/apps/files?dir=%2Ffoo" title="in foo">bar.file</a>',
)),
array(array('/0/bar.file'), array(0 => 'file'), true, true, array(
'<a class="filename tooltip" href="/index.php/apps/files?dir=%2F0" title="in 0">bar.file</a>',
)),
array(array('/foo/bar.file'), array(1 => 'file'), true, false, array('/foo/bar.file')),
array(array('/foo/bar.file'), array(1 => 'file'), true, true, array('<strong>/foo/bar.file</strong>')),
// Legacy: stored without leading slash
array(array('foo/bar.file'), array(0 => 'file'), false, false, array('foo/bar.file')),
array(array('foo/bar.file'), array(0 => 'file'), false, true, array(
'<a class="filename" href="/index.php/apps/files?dir=%2Ffoo">foo/bar.file</a>',
)),
array(array('foo/bar.file'), array(0 => 'file'), true, false, array('bar.file')),
array(array('foo/bar.file'), array(0 => 'file'), true, true, array(
'<a class="filename tooltip" href="/index.php/apps/files?dir=%2Ffoo" title="in foo">bar.file</a>',
)),
// Valid file position
array(array('UserA', '/foo/bar.file'), array(1 => 'file'), true, false, array('UserA', 'bar.file')),
array(array('UserA', '/foo/bar.file'), array(1 => 'file'), true, true, array(
'<strong>UserA</strong>',
'<a class="filename tooltip" href="/index.php/apps/files?dir=%2Ffoo" title="in foo">bar.file</a>',
)),
array(array('UserA', '/foo/bar.file'), array(2 => 'file'), true, false, array('UserA', '/foo/bar.file')),
array(array('UserA', '/foo/bar.file'), array(2 => 'file'), true, true, array(
'<strong>UserA</strong>',
'<strong>/foo/bar.file</strong>',
)),
array(array('UserA', '/foo/bar.file'), array(0 => 'username'), true, true, array(
'<div class="avatar" data-user="UserA"></div><strong>UserA</strong>',
'<strong>/foo/bar.file</strong>',
)),
array(array('U<ser>A', '/foo/bar.file'), array(0 => 'username'), true, true, array(
'<div class="avatar" data-user="U<ser>A"></div><strong>U<ser>A</strong>',
'<strong>/foo/bar.file</strong>',
)),
array(array('UserA', '/foo/bar.file'), array(0 => 'username', 1 => 'file'), true, true, array(
'<div class="avatar" data-user="UserA"></div><strong>UserA</strong>',
'<a class="filename tooltip" href="/index.php/apps/files?dir=%2Ffoo" title="in foo">bar.file</a>',
)),
array(array('UserA', '/tmp/test'), array(0 => 'username', 1 => 'file'), true, true, array(
'<div class="avatar" data-user="UserA"></div><strong>UserA</strong>',
'<a class="filename tooltip" href="/index.php/apps/files?dir=%2Ftmp%2Ftest" title="in tmp">test</a>',
), 'tmp/test/'),
);
}
/**
* @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)
);
}
public function prepareArrayParametersData() {
return array(
array(array(), 'file', true, true, ''),
array(array('A/B.txt', 'C/D.txt'), 'file', true, false, 'B.txt and D.txt'),
array(array('A/B.txt', 'C/D.txt'), '', true, false, 'A/B.txt and C/D.txt'),
);
}
/**
* @dataProvider prepareArrayParametersData
*/
public function testPrepareArrayParameters($params, $paramType, $stripPath, $highlightParams, $expected) {
$this->assertEquals(
$expected,
(string) $this->parameterHelper->prepareArrayParameter($params, $paramType, $stripPath, $highlightParams)
);
}
public function getSpecialParameterListData() {
return array(
array('files', 'shared_group_self', array(0 => 'file')),
array('files', 'shared_group', array(0 => 'file', 1 => 'username')),
array('files', '', array(0 => 'file', 1 => 'username')),
array('calendar', 'shared_group', array()),
array('calendar', '', array()),
);
}
/**
* @dataProvider getSpecialParameterListData
*/
public function testGetSpecialParameterList($app, $text, $expected) {
$this->assertEquals($expected, $this->parameterHelper->getSpecialParameterList($app, $text));
}
}
|