<commit_before><?php
namespace Czim\CmsModels\Test\Integration\Controllers\Web;

use Czim\CmsModels\Support\Enums\OrderablePosition;
use Czim\CmsModels\Test\Integration\Controllers\AbstractControllerIntegrationTest;

/**
 * Class OrderableTest
 *
 * Tests for simple orderable model functions.
 *
 * @group integration
 * @group controllers
 */
class OrderableTest extends AbstractControllerIntegrationTest
{
    const ROUTE_BASE = 'cms::models.model.czim-cmsmodels-test-helpers-models-testauthor';


    /**
     * @test
     */
    function it_shows_a_list_of_models_as_an_orderable_listing()
    {
        $this->visitRoute(static::ROUTE_BASE . '.index')->seeStatusCode(200);

        // Check if we have orderable column cells
        static::assertCount(2, $this->crawler()->filter('td.column-orderable'));

        // Check if new sort order is by position
        $rows = $this->crawler()->filter('tr.records-row');
        static::assertEquals(1, $rows->first()->attr('data-id'), 'Order incorrect');
        static::assertEquals(2, $rows->last()->attr('data-id'), 'Order incorrect');
    }
    
    /**
     * @test
     * @depends it_shows_a_list_of_models_as_an_orderable_listing
     */
    function it_updates_the_position_for_an_orderable_record()
    {
        $this->visitRoute(static::ROUTE_BASE . '.index')->seeStatusCode(200);

        $token = $this->crawler()->filter('meta[name="csrf-token"]')->first()->attr('content');

        $this->route('POST', static::ROUTE_BASE . '.position', [2], [
            '_method'  => 'put',
            '_token'   => $token,
            'position' => OrderablePosition::TOP,
        ], [], [], $this->getAjaxHeaders());
        $this->seeJson(['success' => true]);

        // Check if order is now altered
        $this->visitRoute(static::ROUTE_BASE . '.index')->seeStatusCode(200);

        $rows = $this->crawler()->filter('tr.records-row');
        static::assertEquals(2, $rows->first()->attr('data-id'), 'Order incorrect');
        static::assertEquals(1, $rows->last()->attr('data-id'), 'Order incorrect');
    }

}<commit_msg>Improved orderable integration test<commit_after><?php
namespace Czim\CmsModels\Test\Integration\Controllers\Web;

use Czim\CmsModels\Support\Enums\OrderablePosition;
use Czim\CmsModels\Test\Integration\Controllers\AbstractControllerIntegrationTest;
use Illuminate\Http\RedirectResponse;

/**
 * Class OrderableTest
 *
 * Tests for simple orderable model functions.
 *
 * @group integration
 * @group controllers
 */
class OrderableTest extends AbstractControllerIntegrationTest
{
    const ROUTE_BASE = 'cms::models.model.czim-cmsmodels-test-helpers-models-testauthor';


    /**
     * @test
     */
    function it_shows_a_list_of_models_as_an_orderable_listing()
    {
        $this->visitRoute(static::ROUTE_BASE . '.index')->seeStatusCode(200);

        // Check if we have orderable column cells
        static::assertCount(2, $this->crawler()->filter('td.column-orderable'));

        // Check if new sort order is by position
        $rows = $this->crawler()->filter('tr.records-row');
        static::assertEquals(1, $rows->first()->attr('data-id'), 'Order incorrect');
        static::assertEquals(2, $rows->last()->attr('data-id'), 'Order incorrect');
    }
    
    /**
     * @test
     * @depends it_shows_a_list_of_models_as_an_orderable_listing
     */
    function it_updates_the_position_for_an_orderable_record()
    {
        $this->visitRoute(static::ROUTE_BASE . '.index')->seeStatusCode(200);

        $token = $this->crawler()->filter('meta[name="csrf-token"]')->first()->attr('content');

        $this->route('POST', static::ROUTE_BASE . '.position', [2], [
            '_method'  => 'put',
            '_token'   => $token,
            'position' => OrderablePosition::TOP,
        ], [], [], $this->getAjaxHeaders());
        $this->seeJson(['success' => true]);

        // Check if order is now altered
        $this->visitRoute(static::ROUTE_BASE . '.index')->seeStatusCode(200);

        $rows = $this->crawler()->filter('tr.records-row');
        static::assertEquals(2, $rows->first()->attr('data-id'), 'Order incorrect');
        static::assertEquals(1, $rows->last()->attr('data-id'), 'Order incorrect');
    }

    /**
     * @test
     */
    function it_redirects_back_after_toggling_activatable_record_for_non_ajax_request()
    {
        $this->visitRoute(static::ROUTE_BASE . '.index')->seeStatusCode(200);

        $token = $this->crawler()->filter('meta[name="csrf-token"]')->first()->attr('content');

        $this->route('POST', static::ROUTE_BASE . '.position', [2], [
            '_method'  => 'put',
            '_token'   => $token,
            'position' => OrderablePosition::TOP,
        ]);
        static::assertInstanceOf(RedirectResponse::class, $this->response);

        // Check if order is now altered
        $this->visitRoute(static::ROUTE_BASE . '.index')->seeStatusCode(200);

        $rows = $this->crawler()->filter('tr.records-row');
        static::assertEquals(2, $rows->first()->attr('data-id'), 'Order incorrect');
        static::assertEquals(1, $rows->last()->attr('data-id'), 'Order incorrect');
    }

}
{'fraction_non_alphanumeric': 0.17520789015664281, 'fraction_numerical': 0.007542061496809128, 'mean_word_length': 3.3316582914572863, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 84, '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': '4148089', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1579, 'n_words': 238}