1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-26 11:40:48 +03:00

review user autorization method

This commit is contained in:
vatseek 2012-11-29 18:03:07 +02:00
parent c3a786cc32
commit c530b41b5a
3 changed files with 16 additions and 11 deletions

View file

@ -54,7 +54,11 @@ Feature: LiveStreet standart features
5) При написании дополнительных тестов используются следующие правила:
а) Доступ из всех контектов з контексту MINK должен производится через функцию getMinkContext()
а) Доступ из базового контекcта к контексту MINK должен производится через функцию getMinkContext()
Пример получения доступа к сессии: $this->getMinkContext()->getSession()
б) Получение доступа к базовому обьекту Engine производится посредством метода: $this->getEngine()
б) Получение доступа к базовому обьекту Engine производится посредством метода: $this->getEngine()
Прим: public function getEngine() {
return $this->getSubcontext('base')->getEngine();
}

View file

@ -4,6 +4,7 @@ use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\MinkExtension\Context\MinkContext,
Behat\Mink\Exception\ExpectationException,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
@ -154,17 +155,18 @@ class BaseFeatureContext extends BehatContext
*/
public function iWantToLoginAs($sUserLogin)
{
$moduleUser = $this->getEngine()->GetModuleObject('ModuleUser');
$oUser = $moduleUser->GetUserByLogin($sUserLogin);
$oUser = $this->getEngine()->User_GetUserByLogin($sUserLogin);
if (!$oUser) {
throw new ExpectationException( sprintf('User %s not found', $sUserLogin), $this->getMinkContext()->getSession());
}
$moduleUser->Authorization($oUser, true);
$sSessionKey = $moduleUser->GetSessionByUserId($oUser->getId())->getKey();
$this->getEngine()->User_Authorization($oUser, true);
$oSession = $this->getEngine()->User_GetSessionByUserId($oUser->getId());
if (!$oSession) {
throw new ExpectationException( 'Session non created', $this->getMinkContext()->getSession());
}
$this->getMinkContext()->getSession()->getDriver()->setCookie("key", $sSessionKey);
$this->getMinkContext()->getSession()->getDriver()->setCookie("key", $oSession->getKey());
}
/**

View file

@ -14,8 +14,7 @@ class FeatureContext extends MinkContext
$this->useContext('base', new BaseFeatureContext($parameters));
}
public function getMinkContext()
{
return $this->getMainContext();
public function getEngine() {
return $this->getSubcontext('base')->getEngine();
}
}