Skip to content

Commit 69f9d69

Browse files
authored
Additional cases for JSON formater tests. (empty string/false/true/incorrect json)
But I am not sure if in case of failure we should return false or null like is everywhere i.e. cache, dbresult, etc.
1 parent 211d485 commit 69f9d69

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

tests/system/Test/FeatureResponseTest.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,47 @@ public function testGetJSON()
211211
$this->assertEquals($formatter->format(['foo' => 'bar']), $this->feature->getJSON());
212212
}
213213

214-
public function testInvalidJSON()
214+
public function testEmptyJSON()
215+
{
216+
$this->getFeatureResponse('<h1>Hello World</h1>');
217+
$this->response->setJSON('');
218+
$config = new \Config\Format();
219+
$formatter = $config->getFormatter('application/json');
220+
221+
// this should be "" - json_encode('');
222+
$this->assertEquals("", $this->feature->getJSON());
223+
}
224+
225+
public function testFalseJSON()
215226
{
216227
$this->getFeatureResponse('<h1>Hello World</h1>');
217228
$this->response->setJSON('');
218229
$config = new \Config\Format();
219230
$formatter = $config->getFormatter('application/json');
220231

221-
// this should fail because of empty JSON
232+
// this should be FALSE - json_encode(false)
233+
$this->assertFalse($this->feature->getJSON());
234+
}
235+
236+
public function testTrueJSON()
237+
{
238+
$this->getFeatureResponse('<h1>Hello World</h1>');
239+
$this->response->setJSON('');
240+
$config = new \Config\Format();
241+
$formatter = $config->getFormatter('application/json');
242+
243+
// this should be TRUE - json_encode(true)
244+
$this->assertTrue($this->feature->getJSON());
245+
}
246+
247+
public function testInvalidJSON()
248+
{
249+
$this->getFeatureResponse('<h1>Hello World</h1>');
250+
$this->response->setBody(' test " case ');
251+
$config = new \Config\Format();
252+
$formatter = $config->getFormatter('application/json');
253+
254+
// this should be FALSE - invalid JSON - will see if this is working that way ;-)
222255
$this->assertFalse($this->feature->getJSON());
223256
}
224257

0 commit comments

Comments
 (0)