2013-08-17 11:16:48 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2024-05-10 15:09:14 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2013-08-17 11:16:48 +02:00
|
|
|
*/
|
|
|
|
|
2016-05-18 18:40:34 +02:00
|
|
|
namespace Test\AppFramework\Http;
|
2013-08-17 11:16:48 +02:00
|
|
|
|
2014-03-09 23:01:16 +01:00
|
|
|
use OCP\AppFramework\Http;
|
2019-11-22 20:52:10 +01:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2013-08-17 11:16:48 +02:00
|
|
|
|
2014-11-10 23:30:38 +01:00
|
|
|
class TemplateResponseTest extends \Test\TestCase {
|
2013-08-21 00:41:20 +02:00
|
|
|
/**
|
|
|
|
* @var \OCP\AppFramework\Http\TemplateResponse
|
|
|
|
*/
|
2013-08-17 11:16:48 +02:00
|
|
|
private $tpl;
|
2013-08-21 00:41:20 +02:00
|
|
|
|
2019-11-21 16:40:38 +01:00
|
|
|
protected function setUp(): void {
|
2014-11-10 23:30:38 +01:00
|
|
|
parent::setUp();
|
|
|
|
|
2018-01-15 14:11:02 +01:00
|
|
|
$this->tpl = new TemplateResponse('app', 'home');
|
2013-08-17 11:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-09 13:53:40 +02:00
|
|
|
public function testSetParamsConstructor(): void {
|
2020-03-26 09:30:18 +01:00
|
|
|
$params = ['hi' => 'yo'];
|
2018-01-15 14:11:02 +01:00
|
|
|
$this->tpl = new TemplateResponse('app', 'home', $params);
|
2014-05-06 16:29:19 +02:00
|
|
|
|
2020-03-26 09:30:18 +01:00
|
|
|
$this->assertEquals(['hi' => 'yo'], $this->tpl->getParams());
|
2014-05-06 16:29:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-09 13:53:40 +02:00
|
|
|
public function testSetRenderAsConstructor(): void {
|
2014-05-06 16:29:19 +02:00
|
|
|
$renderAs = 'myrender';
|
2020-03-26 09:30:18 +01:00
|
|
|
$this->tpl = new TemplateResponse('app', 'home', [], $renderAs);
|
2014-05-06 16:29:19 +02:00
|
|
|
|
|
|
|
$this->assertEquals($renderAs, $this->tpl->getRenderAs());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-09 13:53:40 +02:00
|
|
|
public function testSetParams(): void {
|
2020-03-26 09:30:18 +01:00
|
|
|
$params = ['hi' => 'yo'];
|
2013-08-17 11:16:48 +02:00
|
|
|
$this->tpl->setParams($params);
|
|
|
|
|
2020-03-26 09:30:18 +01:00
|
|
|
$this->assertEquals(['hi' => 'yo'], $this->tpl->getParams());
|
2013-08-17 11:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-09 13:53:40 +02:00
|
|
|
public function testGetTemplateName(): void {
|
2013-08-17 11:16:48 +02:00
|
|
|
$this->assertEquals('home', $this->tpl->getTemplateName());
|
|
|
|
}
|
|
|
|
|
2020-04-09 13:53:40 +02:00
|
|
|
public function testGetRenderAs(): void {
|
2013-08-17 11:16:48 +02:00
|
|
|
$render = 'myrender';
|
|
|
|
$this->tpl->renderAs($render);
|
|
|
|
$this->assertEquals($render, $this->tpl->getRenderAs());
|
|
|
|
}
|
|
|
|
|
2014-03-09 23:01:16 +01:00
|
|
|
public function testChainability(): void {
|
2020-03-26 09:30:18 +01:00
|
|
|
$params = ['hi' => 'yo'];
|
2014-03-09 23:01:16 +01:00
|
|
|
$this->tpl->setParams($params)
|
|
|
|
->setStatus(Http::STATUS_NOT_FOUND);
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_NOT_FOUND, $this->tpl->getStatus());
|
2020-03-26 09:30:18 +01:00
|
|
|
$this->assertEquals(['hi' => 'yo'], $this->tpl->getParams());
|
2014-03-09 23:01:16 +01:00
|
|
|
}
|
2013-08-17 11:16:48 +02:00
|
|
|
}
|