Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#79: improve test structure, implement acceptance testing block
- Loading branch information
Showing
63 changed files
with
820 additions
and
624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace DachcomBundle\Test; | ||
|
||
/** | ||
* Class AcceptanceTester | ||
* | ||
* @package DachcomBundle\Test | ||
*/ | ||
class AcceptanceTester extends \Codeception\Actor | ||
{ | ||
use _generated\AcceptanceTesterActions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
|
||
namespace DachcomBundle\Test\Helper\Browser; | ||
|
||
use Codeception\Module; | ||
use Codeception\Lib; | ||
use Codeception\Exception\ModuleException; | ||
use DachcomBundle\Test\Helper\PimcoreCore; | ||
use DachcomBundle\Test\Helper\PimcoreUser; | ||
use Pimcore\Model\User; | ||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
use Symfony\Component\BrowserKit\Cookie; | ||
|
||
class PhpBrowser extends Module implements Lib\Interfaces\DependsOnModule | ||
{ | ||
const PIMCORE_ADMIN_CSRF_TOKEN_NAME = 'MOCK_CSRF_TOKEN'; | ||
|
||
/** | ||
* @var Cookie | ||
*/ | ||
protected $sessionSnapShot; | ||
|
||
/** | ||
* @var PimcoreCore | ||
*/ | ||
protected $pimcoreCore; | ||
|
||
/** | ||
* @return array|mixed | ||
*/ | ||
public function _depends() | ||
{ | ||
return [ | ||
'Codeception\Module\Symfony' => 'PhpBrowser needs the pimcore core framework to work.' | ||
]; | ||
} | ||
|
||
/** | ||
* @param PimcoreCore $pimcoreCore | ||
*/ | ||
public function _inject($pimcoreCore) | ||
{ | ||
$this->pimcoreCore = $pimcoreCore; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function _initialize() | ||
{ | ||
$this->sessionSnapShot = []; | ||
|
||
parent::_initialize(); | ||
} | ||
|
||
/** | ||
* Actor Function to see a page with enabled edit-mode | ||
* | ||
* @param string $page | ||
*/ | ||
public function amOnPageInEditMode(string $page) | ||
{ | ||
$this->pimcoreCore->amOnPage(sprintf('%s?pimcore_editmode=true', $page)); | ||
} | ||
|
||
/** | ||
* Actor Function to login into Pimcore Backend | ||
* | ||
* @param $username | ||
*/ | ||
public function amLoggedInAs($username) | ||
{ | ||
$firewallName = 'admin'; | ||
|
||
try { | ||
/** @var PimcoreUser $userModule */ | ||
$userModule = $this->getModule('\\' . PimcoreUser::class); | ||
} catch (ModuleException $pimcoreModule) { | ||
$this->debug('[PIMCORE BUNDLE MODULE] could not load pimcore user module'); | ||
return; | ||
} | ||
|
||
$pimcoreUser = $userModule->getUser($username); | ||
|
||
if (!$pimcoreUser instanceof User) { | ||
$this->debug(sprintf('[PIMCORE BUNDLE MODULE] could not fetch user %s.', $username)); | ||
return; | ||
} | ||
|
||
/** @var Session $session */ | ||
$session = $this->pimcoreCore->getContainer()->get('session'); | ||
|
||
$this->pimcoreCore->client->getCookieJar()->clear(); | ||
|
||
$user = new \Pimcore\Bundle\AdminBundle\Security\User\User($pimcoreUser); | ||
$token = new UsernamePasswordToken($user, null, $firewallName, $pimcoreUser->getRoles()); | ||
$this->pimcoreCore->getContainer()->get('security.token_storage')->setToken($token); | ||
|
||
\Pimcore\Tool\Session::useSession(function (AttributeBagInterface $adminSession) use ($pimcoreUser) { | ||
\Pimcore\Tool\Session::regenerateId(); | ||
$adminSession->set('user', $pimcoreUser); | ||
$adminSession->set('csrfToken', self::PIMCORE_ADMIN_CSRF_TOKEN_NAME); | ||
}); | ||
|
||
// allow re-usage of session in same cest. | ||
if (!empty($this->sessionSnapShot)) { | ||
$cookie = $this->sessionSnapShot; | ||
} else { | ||
$cookie = new Cookie($session->getName(), $session->getId()); | ||
$this->sessionSnapShot = $cookie; | ||
} | ||
|
||
$this->pimcoreCore->client->getCookieJar()->set($cookie); | ||
|
||
} | ||
|
||
/** | ||
* Actor Function to send tokenized ajax request in backend | ||
* | ||
* @param string $url | ||
* @param array $params | ||
*/ | ||
public function sendTokenAjaxPostRequest(string $url, array $params = []) | ||
{ | ||
$params['csrfToken'] = self::PIMCORE_ADMIN_CSRF_TOKEN_NAME; | ||
$this->pimcoreCore->sendAjaxPostRequest($url, $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace DachcomBundle\Test\Helper\Browser; | ||
|
||
use Codeception\Module; | ||
|
||
class WebDriver extends Module\WebDriver | ||
{ | ||
/** | ||
* Actor Function to see a page with enabled edit-mode | ||
* | ||
* @param string $page | ||
*/ | ||
public function amOnPageInEditMode(string $page) | ||
{ | ||
$this->amOnPage(sprintf('%s?pimcore_editmode=true', $page)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.