Skip to content

Commit

Permalink
[POC - Behat] Add RepositoryContext trait (ezsystems#1584)
Browse files Browse the repository at this point in the history
* [Behat] add RepositoryContext trait

* Add Repository Context docs

* [Behat] Repository Context methods/attributes visibility more strict
  • Loading branch information
Miguel Jacinto authored and bdunogier committed May 3, 2016
1 parent c6b896d commit 3dc6777
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
19 changes: 19 additions & 0 deletions doc/behat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,23 @@ use EzSystems\PlatformBehatBundle\Context\SubContext\DeprecationNoticeSupressor;
class MyContextUsesDeprecatedCode implements Context
{
use DeprecationNoticeSupressor;
...
```

##### Using the Repository
To ease the usage and maintainability of the repository dependent
Behat Contexts a trait called `RespositoryContext` was created.
This trait includes all the methods, variables related directly
with the repository. To use this all that is needed is to use it
in your own Contexts. Ex:

``` php
...
/**
* My very own Behat Context
*/
class MyContext implements Context
{
use RepositoryContext;
...
```
56 changes: 56 additions & 0 deletions eZ/Bundle/PlatformBehatBundle/Context/RepositoryContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* File containing the Repository Context class for EzBehatBundle.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace EzSystems\PlatformBehatBundle\Context;

use eZ\Publish\API\Repository\Repository;
use eZ\Publish\Core\Repository\Values\User\UserReference;

/**
* Repository Context Trait.
* Everything repository related should go here.
* To be used by all the other behat contexts that need the repository.
* Any Context tha uses this trait will automatically login the admin user,
* so any operation that needs admin permissions can be executed.
*/
trait RepositoryContext
{
/**
* Default Administrator user id.
*/
private $adminUserId = 14;

/**
* @var eZ\Publish\API\Repository\Repository
*/
private $repository;

/**
* @param $repository eZ\Publish\API\Repository\Repository $repository
*/
protected function setRepository(Repository $repository)
{
$this->repository = $repository;
}

/**
* @return eZ\Publish\API\Repository\Repository $repository
*/
public function getRepository()
{
return $this->repository;
}

/**
* @BeforeScenario
*/
public function loginAdmin($event)
{
$this->repository->setCurrentUser(new UserReference($this->adminUserId));
}
}

0 comments on commit 3dc6777

Please sign in to comment.