activity/tests/Parameter/ParameterTest.php

132 строки
3.3 KiB
PHP
Исходник Обычный вид История

2015-10-13 14:04:13 +03:00
<?php
/**
2016-02-12 11:14:27 +03:00
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Joas Schilling <coding@schilljs.com>
*
2016-02-12 11:14:27 +03:00
* @license AGPL-3.0
2015-10-13 14:04:13 +03:00
*
2016-02-12 11:14:27 +03:00
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
2015-10-13 14:04:13 +03:00
*
2016-02-12 11:14:27 +03:00
* This program is distributed in the hope that it will be useful,
2015-10-13 14:04:13 +03:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2016-02-12 11:14:27 +03:00
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
2015-10-13 14:04:13 +03:00
*
*/
namespace OCA\Activity\Tests\Parameter;
use OCA\Activity\Parameter\Parameter;
use OCA\Activity\Tests\TestCase;
class ParameterTest extends TestCase {
/** @var \OCP\Activity\IEvent|\PHPUnit_Framework_MockObject_MockObject */
protected $event;
/** @var \OCA\Activity\Formatter\IFormatter|\PHPUnit_Framework_MockObject_MockObject */
protected $formatter;
protected function setUp() {
parent::setUp();
$this->event = $this->getMockBuilder('OCP\Activity\IEvent')
->disableOriginalConstructor()
->getMock();
$this->formatter = $this->getMockBuilder('OCA\Activity\Formatter\IFormatter')
->disableOriginalConstructor()
->getMock();
}
/**
* @param string $parameter
* @param string $type
2015-10-13 14:04:13 +03:00
* @return Parameter
*/
public function getParameter($parameter = 'parameter', $type = 'type') {
2015-10-13 14:04:13 +03:00
return new Parameter(
$parameter,
$this->event,
$this->formatter,
$type
2015-10-13 14:04:13 +03:00
);
}
public function dataGetParameter() {
return [
['parameter1', '', 0, 'parameter1'],
['parameter2', '', 0, 'parameter2'],
['parameter1', 'files', 23, 'files#23'],
['parameter1', 'item', 42, 'item#42'],
];
}
/**
* @dataProvider dataGetParameter
* @param string $parameter
* @param string $objectType
* @param int $objectId
* @param string $expected
*/
public function testGetParameter($parameter, $objectType, $objectId, $expected) {
$instance = $this->getParameter($parameter);
$this->event->expects($this->atLeastOnce())
->method('getObjectType')
->willReturn($objectType);
$this->event->expects($this->any())
->method('getObjectId')
->willReturn($objectId);
$this->assertSame($expected, $instance->getParameter());
}
public function dataGetParameterInfo() {
return [
['parameter1', 'files'],
['parameter2', 'item'],
];
}
/**
* @dataProvider dataGetParameterInfo
* @param string $parameter
* @param string $type
*/
public function testGetParameterInfo($parameter, $type) {
$instance = $this->getParameter($parameter, $type);
$this->assertSame([
'value' => $parameter,
'type' => $type,
], $instance->getParameterInfo());
}
2015-10-13 14:04:13 +03:00
public function dataFormat() {
return [
2016-01-12 14:21:43 +03:00
['parameter1'],
['parameter2'],
2015-10-13 14:04:13 +03:00
];
}
/**
* @dataProvider dataFormat
*
* @param string $parameter
*/
2016-01-12 14:21:43 +03:00
public function testFormat($parameter) {
2015-10-13 14:04:13 +03:00
$instance = $this->getParameter($parameter);
$this->formatter->expects($this->once())
->method('format')
2016-01-12 14:21:43 +03:00
->with($this->event, $parameter)
2015-10-13 14:04:13 +03:00
->willReturn('formatted()');
2016-01-12 14:21:43 +03:00
$this->assertSame('formatted()', $instance->format());
2015-10-13 14:04:13 +03:00
}
}