File: D:/HostingSpaces/SBogers10/ehbo.today/tests/Browser/PostTest.php
<?php
namespace Tests\Browser;
use App\KommaApp\Shop\Tests\DuskTestCase;
use App\KommaApp\Sites\Models\Site;
use App\KommaApp\Users\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Laravel\Dusk\Browser;
use Tests\Browser\Pages\PostSectionTestPage;
class PostTest extends DuskTestCase
{
use DatabaseTransactions; //Automatically rolls back database actions after tests
/**
* @group PostTest
* @test
*/
public function testCreatePost()
{
$site = Site::first();
$postName = 'Dusk_test_post_'.mt_rand(1, 9999);
$counter = 0;
$this->browse(function (Browser $browser) use ($site, $postName, $counter) {
$browser->loginAs(User::find(1))
//Go to the section and press the add button
->visit(new PostSectionTestPage())
->screenshot($this->getName().'-'.++$counter)
->assertSee(__('kms/posts.sub_title'))
->click('@addButton')
->screenshot($this->getName().'-'.++$counter)
//Select the site
->type('@siteInput', $site->title)->pause(350)
->keys('@siteInput', '{down}')->pause(350)
->keys('@siteInput', '{enter}')->pause(350)
//Disable the active button
->click('@activeToggle')
->assertInputValue('#OnOff-active', '0')
->screenshot($this->getName())
//Set a date
->keys('@DatePickerDate', '{backspace}', '{backspace}', '{backspace}', '{backspace}', '{backspace}', '{backspace}', '{backspace}', '{backspace}', '{backspace}', '{backspace}') //Clear date
->type('@DatePickerDate', '02/10/2017')
->keys('@DatePickerDate', '{enter}')
//...And a time
->type('@DatePickerHours', '09')
->type('@DatePickerMinutes', '01')
//Set the dutch title
->click('@nlTab')
->type('#TextField-name-nl', $postName)
//Save
->click('@saveButton')
->assertSee($postName)
//Validate general tab
->click('@generalTab')
->pause(350)
->screenshot($this->getName().'-'.++$counter)
->assertSeeIn('#AutocompleteInput-site_id_items > p', $site->title)
->assertInputValue('#OnOff-active', '0')
->assertInputValue('@DatePickerDate', '02/10/2017')
->assertInputValue('@DatePickerHours', '09')
->assertInputValue('@DatePickerMinutes', '01')
//Delete the post
->type('@searchInput', $postName)
->screenshot($this->getName(false).'-'.++$counter)
->assertSeeIn('#search-result-counter', '1')
->click('#posts-searchlist > li.entities-list-item.active > a')
->screenshot($this->getName(false).'-'.++$counter)
->assertSeeIn('#entity > div.entity-header > div.entity-header-attributes > h2', $postName)
->click('@deleteButton')
->assertSee(__('kms/global.confirm_deletion'))
->click('@confirmYes')
->assertSee(__('kms/global.removed'))
->screenshot($this->getName(false).'-'.++$counter);
});
}
}