<commit_before><commit_msg>Test for JsonHttpError trait (cherry picked from commit 9c2e5ec)<commit_after><?php
/**
 * ownCloud - galleryplus
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 *
 * @copyright <NAME> 2015
 */
namespace OCA\GalleryPlus\Controller;

use OCP\AppFramework\Http;

use OCA\GalleryPlus\Environment\NotFoundEnvException;
use OCA\GalleryPlus\Service\NotFoundServiceException;
use OCA\GalleryPlus\Service\ForbiddenServiceException;

/**
 * Class JsonHttpErrorTest
 *
 * @package OCA\Gallery\Controller
 */
class JsonHttpErrorTest extends \Test\TestCase {

	/**
	 * @dataProvider providesExceptionData
	 *
	 * @param \Exception $exception
	 * @param String $message
	 * @param String $status
	 */
	public function testError($exception, $message, $status) {
		$jsonHttpError = $this->getMockForTrait('OCA\Gallery\Controller\JsonHttpError');
		$response = $jsonHttpError->error($exception);

		$this->assertEquals(['message' => $message, 'success' => false], $response->getData());
		$this->assertEquals($status, $response->getStatus());
	}

	/**
	 * @return array
	 */
	public function providesExceptionData() {
		$notFoundEnvMessage = 'Not found in env';
		$notFoundEnvException = new NotFoundEnvException($notFoundEnvMessage);
		$notFoundEnvStatus = Http::STATUS_NOT_FOUND;

		$notFoundServiceMessage = 'Not found in service';
		$notFoundServiceException = new NotFoundServiceException($notFoundServiceMessage);
		$notFoundServiceStatus = Http::STATUS_NOT_FOUND;

		$forbiddenServiceMessage = 'Forbidden in service';
		$forbiddenServiceException = new ForbiddenServiceException($forbiddenServiceMessage);
		$forbiddenServiceStatus = Http::STATUS_FORBIDDEN;

		return [
			[$notFoundEnvException, $notFoundEnvMessage, $notFoundEnvStatus],
			[$notFoundServiceException, $notFoundServiceMessage, $notFoundServiceStatus],
			[$forbiddenServiceException, $forbiddenServiceMessage, $forbiddenServiceStatus],

		];
	}
}
{'fraction_non_alphanumeric': 0.11877772301626417, 'fraction_numerical': 0.003942828979793002, 'mean_word_length': 5.928327645051194, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6878163', 'n_tokens_mistral': 624, 'n_tokens_neox': 591, 'n_words': 124}