Lestah
2 months ago
153
3
Laravel

Laravel Testing Asserting

Posted 2 months ago by Lestah

here's the code for the test I did


public function a_super_user_can_view_a_paginated_list_of_all_discussions()
    {
        // Arrangements
        $this->withoutExceptionHandling();
        $this->actingAs($user = $this->superAdmin);
        $discussions = factory(Discussion::class, 5)->create();


        // Actions
        $response = $this->get(route('discussions.index'));


        // Assertions
        $response->assertSuccessful()
                 ->assertViewHas('resources')
                 ->assertViewIs('course::discussions.index')
                 ->assertSeeText(trans('All Discussions'))
                 ->assertSeeText(trans('Add Discussion'))
                 ->assertSeeTextInOrder($discussions->pluck('body')->toArray());
                 // ->assertSeeTextInOrder($discussions->pluck('commentable_type')->toArray())
                 // ->assertSeeTextInOrder($discussions->pluck('user_id')->toArray())
                 // ->assertSeeTextInOrder($discussions->pluck('parent_id')->toArray())
                 // ->assertSeeTextInOrder([trans('Edit'), trans('Move to Trash')]);
    }

and on my index.blade.php i asserted that a body $resource->body is on there

@section('page:content')
  @container(['attr' => 'grid-list-xl'])
    @layout(['attr' => 'row wrap'])
      @flex(['attr' => 'xs12'])

        @foreach ($resources as $resource)
          <p>@a($resource->body, ['url' => route('discussions.show', $resource->id)])</p>
          <p>{{ $resource->body }}</p>  =========== here it is
          {{-- <p>{{ $resource->commentable_id }}</p>
          <p>{{ $resource->commentable_type }}</p>
          <p>{{ $resource->user_id }}</p>
          <p>{{ $resource->parent_id }}</p> --}}
          <p>
            @can('discussions.edit')
              @a('Edit', [
                'icon' => 'mdi mdi-pencil-outline',
                'url' => route('discussions.edit', $resource->id),
              ])
            @endcan
          </p>
          <p>
            @can('discussions.destroy')
              @a('Move to Trash', [
                'icon' => 'mdi mdi-delete-outline',
                'url' => route('discussions.destroy', $resource->id),
              ])
            @endcan
          </p>
        @endforeach

but the error says that it's not there any idea what could have been wrong

Please sign in or create an account to participate in this conversation.