Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Add method isUserLoggedIn to the TPresenter (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
radekhubner authored and mrtnzlml committed Apr 26, 2017
1 parent b96b8c8 commit dc755b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Traits/TPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ protected function logOut()
return $user;
}

/**
* @return bool
*/
protected function isUserLoggedIn()
{
/** @var \Nette\Security\User $user */
$user = \Testbench\ContainerFactory::create(FALSE)->getByType('Nette\Security\User');
return $user->isLoggedIn();
}

/**
* @return \Nette\Application\UI\Presenter
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Traits/TPresenterTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ class TPresenterTest extends \Testbench\CustomPresenterTestCase
}, 'Tester\AssertException', "field 'test' should be defined as required, but it's not");
}

public function testUserLoggedIn()
{
Assert::false($this->isUserLoggedIn());
$this->logIn();
Assert::true($this->isUserLoggedIn());
$this->logOut();
Assert::false($this->isUserLoggedIn());
}
}

(new TPresenterTest)->run();

0 comments on commit dc755b0

Please sign in to comment.