<commit_before><?php

namespace Aimeos\ShopBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;


class JsonapiControllerTest extends WebTestCase
{
	protected function setUp()
	{
		\Aimeos\MShop::cache( false );
		\Aimeos\Controller\Frontend::cache( false );
	}


	public function testOptionsAction()
	{
		$client = static::createClient();
		$client->request( 'OPTIONS', '/unittest/de/EUR/jsonapi' );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertArrayHasKey( 'resources', $json['meta'] );
		$this->assertGreaterThan( 1, count( $json['meta']['resources'] ) );
	}


	public function testPutAction()
	{
		$client = static::createClient();
		$client->request( 'PUT', '/unittest/de/EUR/jsonapi/basket' );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 403, $response->getStatusCode() );
		$this->assertArrayHasKey( 'errors', $json );
	}


	public function testGetAttributeAction()
	{
		$client = static::createClient();
		$client->request( 'GET', '/unittest/de/EUR/jsonapi/attribute', [] );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertEquals( 26, $json['meta']['total'] );
		$this->assertEquals( 25, count( $json['data'] ) );
	}


	public function testGetCatalogAction()
	{
		$client = static::createClient();
		$client->request( 'GET', '/unittest/de/EUR/jsonapi/catalog', [] );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertEquals( 1, $json['meta']['total'] );
		$this->assertEquals( 4, count( $json['data'] ) );
	}


	public function testGetLocaleAction()
	{
		$client = static::createClient();
		$client->request( 'GET', '/unittest/de/EUR/jsonapi/locale', [] );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertEquals( 1, $json['meta']['total'] );
		$this->assertEquals( 1, count( $json['data'] ) );
	}


	public function testGetProductAction()
	{
		$client = static::createClient();

		$params = ['filter' => ['f_search' => 'Cafe Noire Cap']];
		$client->request( 'GET', '/unittest/de/EUR/jsonapi/product', $params );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertEquals( 1, $json['meta']['total'] );
		$this->assertEquals( 1, count( $json['data'] ) );
		$this->assertArrayHasKey( 'id', $json['data'][0] );
		$this->assertEquals( 'CNC', $json['data'][0]['attributes']['product.code'] );

		$client->request( 'GET', '/unittest/de/EUR/jsonapi/product?id=' . $json['data'][0]['id'] );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertEquals( 1, $json['meta']['total'] );
		$this->assertArrayHasKey( 'id', $json['data'] );
		$this->assertEquals( 'CNC', $json['data']['attributes']['product.code'] );<commit_msg>Adapt to core change<commit_after><?php

namespace Aimeos\ShopBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;


class JsonapiControllerTest extends WebTestCase
{
	protected function setUp()
	{
		\Aimeos\MShop::cache( false );
		\Aimeos\Controller\Frontend::cache( false );
	}


	public function testOptionsAction()
	{
		$client = static::createClient();
		$client->request( 'OPTIONS', '/unittest/de/EUR/jsonapi' );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertArrayHasKey( 'resources', $json['meta'] );
		$this->assertGreaterThan( 1, count( $json['meta']['resources'] ) );
	}


	public function testPutAction()
	{
		$client = static::createClient();
		$client->request( 'PUT', '/unittest/de/EUR/jsonapi/basket' );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 403, $response->getStatusCode() );
		$this->assertArrayHasKey( 'errors', $json );
	}


	public function testGetAttributeAction()
	{
		$client = static::createClient();
		$client->request( 'GET', '/unittest/de/EUR/jsonapi/attribute', [] );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertEquals( 26, $json['meta']['total'] );
		$this->assertEquals( 25, count( $json['data'] ) );
	}


	public function testGetCatalogAction()
	{
		$client = static::createClient();
		$client->request( 'GET', '/unittest/de/EUR/jsonapi/catalog', [] );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertEquals( 1, $json['meta']['total'] );
		$this->assertEquals( 4, count( $json['data'] ) );
	}


	public function testGetLocaleAction()
	{
		$client = static::createClient();
		$client->request( 'GET', '/unittest/de/EUR/jsonapi/locale', [] );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertEquals( 1, $json['meta']['total'] );
		$this->assertEquals( 1, count( $json['data'] ) );
	}


	public function testGetProductAction()
	{
		$client = static::createClient();

		$params = ['filter' => ['f_search' => 'Cafe Noire Cap']];
		$client->request( 'GET', '/unittest/de/EUR/jsonapi/product', $params );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertEquals( 2, $json['meta']['total'] );
		$this->assertEquals( 2, count( $json['data'] ) );
		$this->assertArrayHasKey( 'id', $json['data'][0] );
		$this->assertEquals( 'CNC', $json['data'][0]['attributes']['product.code'] );

		$client->request( 'GET', '/unittest/de/EUR/jsonapi/product?id=' . $json['data'][0]['id'] );
		$response = $client->getResponse();

		$json = json_decode( $response->getContent(), true );

		$this->assertNotNull( $json );
		$this->assertEquals( 200, $response->getStatusCode() );
		$this->assertEquals( 1, $json['meta']['total'] );
		$this->assertArrayHasKey( 'id', $json['data'] );
		$this->assertEquals( 'CNC', $json['data']['attributes']['product.code'] );
{'fraction_non_alphanumeric': 0.21659437526234784, 'fraction_numerical': 0.010074156988946412, 'mean_word_length': 5.194107452339688, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 123, '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': '4111606', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2312, 'n_words': 413}