HummingBirdAnimeClient/tests/Ion/View/JsonViewTest.php

43 lines
946 B
PHP
Raw Normal View History

2015-10-15 09:25:30 -04:00
<?php
use Aviat\Ion\Friend;
2016-01-08 11:40:24 -05:00
include_once __DIR__ . "/HttpViewTest.php";
2015-10-15 09:25:30 -04:00
2016-01-08 11:40:24 -05:00
class JsonViewTest extends HttpViewTest {
2015-10-15 09:25:30 -04:00
public function setUp()
{
parent::setUp();
$this->view = new TestJsonView($this->container);
$this->friend = new Friend($this->view);
}
2016-03-03 16:53:17 -05:00
public function testSetOutputJSON()
2015-10-15 09:25:30 -04:00
{
// Extend view class to remove destructor which does output
$view = new TestJsonView($this->container);
// Json encode non-string
$content = ['foo' => 'bar'];
$expected = json_encode($content);
2016-03-03 16:53:17 -05:00
$view->setOutput($content);
2015-10-15 09:25:30 -04:00
$this->assertEquals($expected, $this->view->getOutput());
2016-03-03 16:53:17 -05:00
}
2015-10-15 09:25:30 -04:00
2016-03-03 16:53:17 -05:00
public function testSetOutput()
{
2015-10-15 09:25:30 -04:00
// Directly set string
2016-03-03 16:53:17 -05:00
$view = new TestJsonView($this->container);
2015-10-15 09:25:30 -04:00
$content = '{}';
$expected = '{}';
2016-03-03 16:53:17 -05:00
$view->setOutput($content);
$this->assertEquals($expected, $view->getOutput());
2015-10-15 09:25:30 -04:00
}
public function testOutput()
{
$this->assertEquals('application/json', $this->friend->contentType);
}
}