File: D:/HostingSpaces/brameda/brameda.nl/app/Komma/Shop/Tests/Browser/ProductCompositeTest.php
<?php
namespace App\Komma\Shop\Tests\Browser;
use App\Komma\Shop\Products\Product\ProductTranslation;
use App\Komma\Shop\Products\ProductGroup\ProductGroup;
use App\Komma\Shop\Products\ProductGroup\ProductGroupTranslation;
use App\Komma\Shop\Products\ProductGroupBehaviour\ProductGroupBehaviour;
use App\Komma\Shop\Tests\Browser\Pages\ProductCompositeSectionTestPage;
use App\Komma\Shop\Tests\DuskTestCase;
use App\Komma\Users\Models\KmsUser;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Laravel\Dusk\Browser;
class ProductCompositeTest extends DuskTestCase
{
// use DatabaseTransactions; //Automatically rolls back database actions after tests
/**
* @group ProductCompositeSection
* @test
* @throws \Throwable
*/
public function testProductsGroupMenuItem()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(KmsUser::find(1), 'kms')
->visit(new ProductCompositeSectionTestPage())
->screenshot($this->getName(false));
});
}
/**
* @group ProductCompositeSection
* @test
* @throws \Throwable
*/
public function testNewProductGroupScreen()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(KmsUser::find(1), 'kms')
->visit(new ProductCompositeSectionTestPage())
->click('@add_button')
->assertSee('Nieuwe samengestelde product groep')
->screenshot($this->getName(false));
});
}
/**
* @group ProductCompositeSection
* @test
* @throws \Throwable
*/
public function testAddingOfEmptyProductGroupFailure()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(KmsUser::find(1), 'kms')
->visit(new ProductCompositeSectionTestPage())
->click('@add_button')
->assertSee('Nieuwe samengestelde product groep')
->click('@save_button')
->assertSee(__('validation.required', ['attribute' => __('kms/global.title')])) //titel is verplicht
->screenshot($this->getName(false));
});
}
/**
* @group ProductCompositeSection
* @test
* @throws \Throwable
*/
public function testAddingProductCompositeCorrectlyAndDeletingIt()
{
$productCompositeName = 'Dusk test composite group ' . mt_rand(0, 99999);
//Create 1 product that we add to the groups for testing purposes
/** @var ProductTranslation $productTranslation */
$productTranslation = factory(ProductTranslation::class)->create();
/** @var $behaviourOr $behaviourOr */
$behaviourOr = factory(ProductGroupBehaviour::class)->create();
$behaviourOr->save();
/** @var ProductGroupTranslation $productGroupTranslation */
$productGroupTranslation = factory(ProductGroupTranslation::class)->create();
/** @var ProductGroup $productGroup */
$productGroup = $productGroupTranslation->translatable()->first();
$productGroup->productGroupBehaviour()->associate($behaviourOr);
$productGroup->save();
$productGroup->products()->attach($productTranslation->translatable()->first());
/** @var ProductGroupTranslation $productGroupTranslation */
$productGroupTranslationTwo = factory(ProductGroupTranslation::class)->create();
/** @var ProductGroup $productGroup */
$productGroup = $productGroupTranslationTwo->translatable()->first();
$productGroup->productGroupBehaviour()->associate($behaviourOr);
$productGroup->save();
$productGroup->products()->attach($productTranslation->translatable()->first());
$counter = 0;
$this->browse(function (Browser $browser) use ($productCompositeName, $counter, $productGroupTranslation, $productGroupTranslationTwo) {
$browser->loginAs(KmsUser::find(1), 'kms')
->visit(new ProductCompositeSectionTestPage())
->click('@add_button')
->assertSee('Nieuwe samengestelde product groep')
->click('@entity_tab_nl')
->type('TextField-name-nl', $productCompositeName)
->click('@entity_tab_de')
->type('TextField-name-de', $productCompositeName)
->click('@entity_tab_en')
->type('TextField-name-en', $productCompositeName)
->screenshot($this->getName(false) . '-' . ++$counter)
->click('@entity_tab_algemeen')
->type('@MultiSelect-groups-fake', $productGroupTranslation->name)->pause(1000)
->keys('@MultiSelect-groups-fake', '{down}')->pause(1000)
->keys('@MultiSelect-groups-fake', '{enter}')->pause(1000)
->assertSee($productGroupTranslation->name)->pause(1000)
->screenshot($this->getName(false) . '-' . ++$counter)->pause(1000)
->type('@MultiSelect-groups-fake', $productGroupTranslationTwo->name)->pause(1000)
->keys('@MultiSelect-groups-fake', '{down}')->pause(1000)
->keys('@MultiSelect-groups-fake', '{enter}')->pause(1000)
->assertSee($productGroupTranslationTwo->name)
->screenshot($this->getName(false) . '-' . ++$counter)
->click('@save_button')
->assertSeeIn('@regular_list', $productCompositeName)
->screenshot($this->getName(false));
});
$counter = 0;
$this->browse(function (Browser $browser) use ($productCompositeName, $counter) {
$browser->visit(new ProductCompositeSectionTestPage())
->type('@entity_search_input', $productCompositeName)
->screenshot($this->getName(false) . '-' . ++$counter)
->assertSeeIn('@search-result-counter', '1')
->click('@found_search_item')
->screenshot($this->getName(false) . '-' . ++$counter)
->assertSeeIn('@entity_header', $productCompositeName)
->click('@delete_button')
->assertSee(__('kms/global.confirm_deletion'))
->click('@confirmation_confirm')
->assertSee(__('kms/global.removed'))
->screenshot($this->getName(false) . '-' . ++$counter);
});
}
}