diff --git a/tests/Readme.RU.md b/tests/Readme.RU.md index 2dc9a4e9..3954db09 100644 --- a/tests/Readme.RU.md +++ b/tests/Readme.RU.md @@ -54,7 +54,11 @@ Feature: LiveStreet standart features 5) При написании дополнительных тестов используются следующие правила: - а) Доступ из всех контектов з контексту MINK должен производится через функцию getMinkContext() + а) Доступ из базового контекcта к контексту MINK должен производится через функцию getMinkContext() Пример получения доступа к сессии: $this->getMinkContext()->getSession() - б) Получение доступа к базовому обьекту Engine производится посредством метода: $this->getEngine() \ No newline at end of file +б) Получение доступа к базовому обьекту Engine производится посредством метода: $this->getEngine() + +Прим: public function getEngine() { + return $this->getSubcontext('base')->getEngine(); + } \ No newline at end of file diff --git a/tests/behat/features/bootstrap/BaseFeatureContext.php b/tests/behat/features/bootstrap/BaseFeatureContext.php index 321e6914..2c3b1cee 100644 --- a/tests/behat/features/bootstrap/BaseFeatureContext.php +++ b/tests/behat/features/bootstrap/BaseFeatureContext.php @@ -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()); } /** diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php index e6f56e49..2ef84b29 100644 --- a/tests/behat/features/bootstrap/FeatureContext.php +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -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(); } }