File: D:/HostingSpaces/SBogers95/rentman.io/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\User;
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
*/
public function testProductsGroupMenuItem()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(User::find(1))
->visit(new ProductCompositeSectionTestPage())
->screenshot($this->getName(false));
});
}
/**
* @group ProductCompositeSecction
* @test
*/
public function testNewProductGroupScreen()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(User::find(1))
->visit(new ProductCompositeSectionTestPage())
->click('@addButton')
->assertSee('Nieuwe samengestelde product groep')
->screenshot($this->getName(false));
});
}
/**
* @group ProductCompositeSection
* @test
*/
public function testAddingOfEmptyProductGroupFailure()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(User::find(1))
->visit(new ProductCompositeSectionTestPage())
->click('@addButton')
->assertSee('Nieuwe samengestelde product groep')
->click('@saveButton')
->assertSee('titel is verplicht.')
->screenshot($this->getName(false));
});
}
/**
* @group ProductCompositeSection
* @test
*/
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(User::find(1))
->visit(new ProductCompositeSectionTestPage())
->click('@addButton')
->assertSee('Nieuwe samengestelde product groep')
->click('@nlTab')
->type('TextField-name-nl', $productCompositeName)
->click('@deTab')
->type('TextField-name-de', $productCompositeName)
->click('@enTab')
->type('TextField-name-en', $productCompositeName)
->screenshot($this->getName(false).'-'.++$counter)
->click('@generalTab')
->pause(2000)
->type('@groupsSelector', $productGroupTranslation->name)->pause(1000)
->keys('@groupsSelector', '{down}')->pause(1000)
->keys('@groupsSelector', '{enter}')->pause(1000)
->assertSee($productGroupTranslation->name)->pause(1000)
->screenshot($this->getName(false).'-'.++$counter)->pause(1000)
->type('@groupsSelector', $productGroupTranslationTwo->name)->pause(1000)
->keys('@groupsSelector', '{down}')->pause(1000)
->keys('@groupsSelector', '{enter}')->pause(1000)
->assertSee($productGroupTranslationTwo->name)
->screenshot($this->getName(false).'-'.++$counter)
->click('@saveButton')
->assertSeeIn('#main-entities-list > ul', $productCompositeName)
->screenshot($this->getName(false));
});
$counter = 0;
$this->browse(function (Browser $browser) use ($productCompositeName, $counter) {
$browser->visit(new ProductCompositeSectionTestPage())
->type('@searchInput', $productCompositeName)
->screenshot($this->getName(false).'-'.++$counter)
->assertSeeIn('#search-result-counter', '1')
->click('#productcomposites-searchlist > li.entities-list-item.active > a')
->screenshot($this->getName(false).'-'.++$counter)
->assertSeeIn('#entity > div.entity-header > div.entity-header-attributes > h2', $productCompositeName)
->click('@deleteButton')
->assertSee(__('kms/global.confirm_deletion'))
->click('@confirmYes')
->assertSee(__('kms/global.removed'))
->screenshot($this->getName(false).'-'.++$counter);
});
}
}