Skip to content

Commit

Permalink
Merge 3aea3e6 into 96d75d5
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszUrbanowicz committed Nov 27, 2015
2 parents 96d75d5 + 3aea3e6 commit 609d86f
Show file tree
Hide file tree
Showing 3 changed files with 414 additions and 0 deletions.
81 changes: 81 additions & 0 deletions tests/_support/FunctionalTester.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php namespace platform;

use Faker\Factory;
use Gzero\Entity\Content;
use Gzero\Repository\ContentRepository;
use Gzero\Repository\UserRepository;
use Gzero\Entity\User;
use Illuminate\Events\Dispatcher;

/**
* Inherited Methods
* @method void wantToTest($text)
Expand All @@ -19,6 +26,29 @@ class FunctionalTester extends \Codeception\Actor {

use _generated\FunctionalTesterActions;

/**
* @var UserRepository
*/
private $userRepo;

/**
* @var ContentRepository
*/
private $contentRepo;

/**
* @var \Faker\Generator
*/
private $faker;

public function __construct(\Codeception\Scenario $scenario)
{
$this->faker = Factory::create();
$this->categoryRepo = new ContentRepository(new Content(), new Dispatcher());
$this->userRepo = new UserRepository(new User(), new Dispatcher());
parent::__construct($scenario);
}

/**
* Login in to page
*
Expand Down Expand Up @@ -60,4 +90,55 @@ public function logout()
$I->dontSeeAuthentication();
}

/**
* Create user and return entity
*
* @param array $attributes
*
* @return User
*/
public function haveUser($attributes = [])
{
$fakeAttributes = [
'firstName' => $this->faker->firstName,
'lastName' => $this->faker->lastName,
'email' => $this->faker->email
];

$fakeAttributes = array_merge($fakeAttributes, $attributes);

return $this->userRepo->create($fakeAttributes);
}

/**
* Create content and return entity
*
* @param bool|false $attributes
* @param null $user
*
* @return Content
*/
public function haveContent($attributes = false, $user = null)
{
$fakeAttributes = [
'type' => ['category', 'content'][rand(0, 1)],
'isActive' => 1,
'publishedAt' => date('Y-m-d H:i:s'),
'translations' => [
'langCode' => 'en',
'title' => $this->faker->realText(38, 1),
'teaser' => '<p>' . $this->faker->realText(300) . '</p>',
'body' => $this->faker->realText(1000),
'seoTitle' => $this->faker->realText(60, 1),
'seoDescription' => $this->faker->realText(160, 1),
'isActive' => rand(0, 1)
]
];

$fakeAttributes = array_merge($fakeAttributes, $attributes);

return $this->categoryRepo->create($fakeAttributes, $user);
}


}
29 changes: 29 additions & 0 deletions tests/functional/AdminCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php namespace platform;

class AdminCest {

public function _before(FunctionalTester $I)
{
}

public function _after(FunctionalTester $I)
{
}

// tests
public function cantAccessAdminPanelAsRegularUser(FunctionalTester $I)
{
$I->wantTo('access admin panel as regular user');
$I->amOnPage('/admin');
$I->seeResponseCodeIs(404);
}

public function canAccessAdminPanelAsAdmin(FunctionalTester $I){
$I->wantTo('access admin panel as admin');
$I->loginAsAdmin();
$I->amOnPage('/admin');
$I->seeResponseCodeIs(200);
}

}

Loading

0 comments on commit 609d86f

Please sign in to comment.