public function testOutputContent() { $obj = new _Json(); $json_data = ['first_element' => 'test', 'second_element' => ['a' => 'test a', 'b' => 'test b']]; # Empty output $expected_result = '[]'; $json_output = $obj->outputContent([], false, true); $this->string($json_output)->isEqualTo($expected_result); # Pretty output $expected_result = file_get_contents(TEST_FILES . 'test_output_pretty.json'); $json_output = $obj->outputContent($json_data, false, true); $this->string($json_output)->isEqualTo($expected_result); # Standard output $expected_result = file_get_contents(TEST_FILES . 'test_output.json'); $json_output = $obj->outputContent($json_data, false, false); $this->string($json_output)->isEqualTo($expected_result); # JSONP Output $expected_result = 'testJS(' . file_get_contents(TEST_FILES . 'test_output.json') . ')'; $json_output = $obj->outputContent($json_data, 'testJS', false); $this->string($json_output)->isEqualTo($expected_result); }
<?php namespace Transvision; use Json\Json; /* * This view outputs a JSON or JSONP representation of search results */ // Log script performance in PHP integrated developement server console Utils::logScriptPerformances(); // We die here because we never want to send anything more after the JSON file $json_data = new Json(); die($json_data->outputContent($json, isset($_GET['callback']) ? $_GET['callback'] : false));
$source_path = "{$root_folder}/tests/testfiles/"; } else { $source_path = "{$root_folder}/app/sources/"; } // Query request $type = Utils::getQueryParam('type'); $repo = Utils::getQueryParam('repo'); $bugzilla = Utils::getQueryParam('bugzilla'); $tool = Utils::getQueryParam('tool'); $repos = new Repositories($source_path); $json_data = new Json(); // Only one repo requested if ($repo != '') { $locales = $repos->getSingleRepository($repo); if ($locales) { die($json_data->outputContent($locales)); } else { http_response_code(400); die('ERROR: unknown repository.'); } } // Only one type of repo requested if ($type != '') { die($json_data->outputContent($repos->getTypeRepositories($type))); } // Bugzilla components if ($bugzilla != '') { $bugzilla_query = new Bugzilla($source_path); die($json_data->outputContent($bugzilla_query->getBugzillaComponents($bugzilla))); } // Locales working in tools