<commit_before><?php

namespace Tests\Feature;

use Sijot\Events;
use Sijot\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class EventsTest extends TestCase
{
    use DatabaseMigrations, DatabaseTransactions;

    /**
     * Test the backend routes for the events section.
     *
     * @test
     * @group all
     */
    public function testIndexRoute()
    {
        $user = factory(User::class)->create();

        $this->actingAs($user)
            ->seeIsAuthenticatedAs($user)
            ->get(route('events.index'))
            ->assertStatus(200);
    }

    /**
     * Test event creation in the database (with validation errors).
     *
     * @test
     * @group all
     */
    public function testEventStoreWithValidationErr()
    {
        $user = factory(User::class)->create();

        $this->actingAs($user)
            ->seeIsAuthenticatedAs($user)
            ->post(route('events.store'), [])
            ->assertStatus(200)
            ->assertSessionHasErrors()
            ->assertSessionMissing([
                'class'   => 'alert alert-success',
                'message' => trans('events.flash-event-create'),
            ]);
    }

    /**
     * Test event creation in the database (without validation errors).
     *
     * @test
     * @group all
     */
    public function testEventStoreWithoutValidationErr()
    {
        $user = factory(User::class)->create();

        $input = [
            'author_id'     => $user->id,
            'title'         => 'Ik ben een titel',
            'description'   => 'Ik ben een beschrijving',
            'start_date'    => '10/10/1995',
            'end_date'      => '11/10/1996',
            'status'        => 'Y',
            'end_hour'      => '10:10',
            'start_hour'    => '12:10',
        ];

        $this->actingAs($user)
            ->seeIsAuthenticatedAs($user)
            ->post(route('events.store'), $input)
            ->assertStatus(302)
            ->assertSessionHasAll([
                'class'   => 'alert alert-success',
                'message' => trans('events.flash-event-create'),
            ]);

        $this->assertDatabaseHas('events', [
            'author_id'     => $user->id,
            'title'         => 'Ik ben een titel',
            'description'   => 'Ik ben een beschrijving',
        ]);
    }

    /**
     * Test the response when an event id is valid.
     *
     * @test
     * @group all
     */
    public function testShowEventValidId()
    {
        $event = factory(Events::class)->create(['id' => 4]);

        $this->get(route('events.show', $event->id))
            ->assertStatus(200);
    }

    /**
     * Test the response when an event id in invalid.
     *
     * @test
     * @group all
     */
    public function testShowEventInvalidId()
    {
        $this->get(route('events.show', 1000))
            ->assertStatus(404);
    }
}
<commit_msg>Implement event status test<commit_after><?php

namespace Tests\Feature;

use Sijot\Events;
use Sijot\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class EventsTest extends TestCase
{
    use DatabaseMigrations, DatabaseTransactions;

    /**
     * Test the backend routes for the events section.
     *
     * @test
     * @group all
     */
    public function testIndexRoute()
    {
        $user = factory(User::class)->create();

        $this->actingAs($user)
            ->seeIsAuthenticatedAs($user)
            ->get(route('events.index'))
            ->assertStatus(200);
    }

    /**
     * Test event creation in the database (with validation errors).
     *
     * @test
     * @group all
     */
    public function testEventStoreWithValidationErr()
    {
        $user = factory(User::class)->create();

        $this->actingAs($user)
            ->seeIsAuthenticatedAs($user)
            ->post(route('events.store'), [])
            ->assertStatus(200)
            ->assertSessionHasErrors()
            ->assertSessionMissing([
                'class' => 'alert alert-success',
                'message' => trans('events.flash-event-create'),
            ]);
    }

    /**
     * Test event creation in the database (without validation errors).
     *
     * @test
     * @group all
     */
    public function testEventStoreWithoutValidationErr()
    {
        $user = factory(User::class)->create();

        $input = [
            'author_id' => $user->id,
            'title' => 'Ik ben een titel',
            'description' => 'Ik ben een beschrijving',
            'start_date' => '10/10/1995',
            'end_date' => '11/10/1996',
            'status' => 'Y',
            'end_hour' => '10:10',
            'start_hour' => '12:10',
        ];

        $this->actingAs($user)
            ->seeIsAuthenticatedAs($user)
            ->post(route('events.store'), $input)
            ->assertStatus(302)
            ->assertSessionHasAll([
                'class' => 'alert alert-success',
                'message' => trans('events.flash-event-create'),
            ]);

        $this->assertDatabaseHas('events', [
            'author_id' => $user->id,
            'title' => 'Ik ben een titel',
            'description' => 'Ik ben een beschrijving',
        ]);
    }

    /**
     * Test the response when an event id is valid.
     *
     * @test
     * @group all
     */
    public function testShowEventValidId()
    {
        $event = factory(Events::class)->create(['id' => 4]);

        $this->get(route('events.show', $event->id))
            ->assertStatus(200);
    }

    /**
     * Test the response when an event id in invalid.
     *
     * @test
     * @group all
     */
    public function testShowEventInvalidId()
    {
        $this->get(route('events.show', 1000))
            ->assertStatus(404);
    }

    public function testEventStatusInvalidId()
    {
        $event  = factory(Events::class)->create(['id' => 1]);
        $user   = factory(User::class)->create();
        $params = ['status' => 0, 'id' => 1000];

        $this->actingAs($user)
            ->seeIsAuthenticatedAs($user)
            ->get(route('events.status', $params))
            ->assertStatus(404);
    }

    /**
     * Test if an event can be converted to draft.
     *
     * @test
     * @group all
     */
    public function testEventStatusDraft()
    {
        $event  = factory(Events::class)->create();
        $user   = factory(User::class)->create();
        $params = ['status' => 0, 'id' => $event->id];

        $this->actingAs($user)
            ->seeIsAuthenticatedAs($user)
            ->get(route('events.status', $params))
            ->assertStatus(302)
            ->assertSessionHas([
                'class'   => 'alert alert-success',
                'message' => trans('events.flash-event-draft')
            ]);
    }

    /**
     * Test if an event can be published
     *
     * @test
     * @group all
     */
    public function testEventPublish()
    {
        $event  = factory(Events::class)->create();
        $user   = factory(User::class)->create();
        $params = ['status' => 1, 'id' => $event->id];

        $this->actingAs($user)
            ->seeIsAuthenticatedAs($user)
            ->get(route('events.status', $params))
            ->assertStatus(302)
            ->assertSessionHas([
                'class'   => 'alert alert-success',
                'message' => trans('events.flash-publish')
            ]);
    }
}

{'fraction_non_alphanumeric': 0.15029277813923228, 'fraction_numerical': 0.013662979830839297, 'mean_word_length': 1.83511619328661, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 122, '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': '942998', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2179, 'n_words': 435}