<?php

// ReadPage

declare(strict_types=1);

namespace {{ tree.getFullNameSpaceOfFile(file, entity, action) }};

use App\Base\ReadPageParameter;

class {{ helper.getClassName(file, entity, action) }} extends {{ helper.getClassName(helper.findFile('AbstractItemTestBase'), entity, action) }}
{
    protected static function getPath(): string
    {
        return "{{ entity.name }}/{{ action }}";
    }

    public function test{{ action + entity.name }}()
    {
        $User = $this->createUser();
        $Item = $this->makeItem($User);
        $Item->save();

        $Data = (new ReadPageParameter())->toArray();
        $Response = $this->getJsonWithData($this->makeUri(), $Data)
            ->assertStatus(401);

        $this->actingAs($User);

        $Response = $this->getJsonWithData($this->makeUri(), $Data)
            ->assertStatus(422);
        $Response->assertJsonValidationErrorFor('Filter.Status');

{% for column in columnzz %}
        $Data['Filter'] = [
            '{{ column.alias }}' => $Item->{{ column.alias }},
        ];
        $Response = $this->getJsonWithData($this->makeUri(), $Data)
            ->assertStatus(200);
        $this->seePage($Response);
        $Response->assertJsonPath('Page.data.0.{{ column.alias }}', $Item->{{ column.alias }});
{% endfor %}

        $Response = $this->getJsonWithData($this->makeUri(), $Data)
            ->assertStatus(200);
        $Response->assertJsonCount(1, 'Page.data');
        $Response->assertJsonIsObject('Page.data.0.User');
        $Response->assertJsonPath('Page.data.0.Id', $Item->Id);

        $OtherUser = $this->createUser();
        $this->actingAs($OtherUser);

        $Response = $this->getJsonWithData($this->makeUri(), $Data)
            ->assertStatus(200);
        $Response->assertJsonCount(0, 'Page.data');
    }
}
