-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01cac6e
commit 2c215e5
Showing
5 changed files
with
279 additions
and
293 deletions.
There are no files selected for viewing
251 changes: 121 additions & 130 deletions
251
app/module/autotest/app/discussion/DiscussionDetailUiTest.php
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 |
---|---|---|
@@ -1,130 +1,121 @@ | ||
<?php | ||
|
||
namespace Tymy\Module\Autotest\Discussion; | ||
|
||
use Nette; | ||
use Nette\Application\Responses\TextResponse; | ||
use Nette\Utils\Strings; | ||
use Tester\Assert; | ||
use Tester\DomQuery; | ||
use Tymy\Bootstrap; | ||
use Tymy\Module\Autotest\UITest; | ||
|
||
use function count; | ||
|
||
require getenv("ROOT_DIR") . '/app/Bootstrap.php'; | ||
$container = Bootstrap::boot(); | ||
|
||
class DiscussionDetailUiTest extends UITest | ||
{ | ||
|
||
public function testActionDiscussionReadableWritable() | ||
{ | ||
$this->authorizeAdmin(); | ||
$discussion = $this->recordManager->createDiscussion(); | ||
$discussionWebName = Strings::webalize($discussion["id"] . "-" . $discussion["caption"]); | ||
|
||
$this->authorizeUser(); //this user can read & write into th | ||
$request = new Nette\Application\Request($this->presenterName, 'GET', ['action' => 'default', 'discussion' => $discussionWebName]); | ||
$response = $this->presenter->run($request); | ||
|
||
assert($response instanceof TextResponse); | ||
Assert::type(TextResponse::class, $response); | ||
|
||
$re = '/&(?!(?:apos|quot|[gl]t|amp);|#)/'; | ||
|
||
$dom = NULL; | ||
$html = (string) $response->getSource(); | ||
//replace unescaped ampersands in html to prevent tests from failing | ||
$html = preg_replace($re, "&", $html); | ||
|
||
$dom = DomQuery::fromHtml($html); | ||
//has navbar | ||
parent::assertDomHas($dom,'div#snippet-navbar-nav'); | ||
|
||
//has breadcrumbs | ||
|
||
parent::assertDomHas($dom,'div.container div.row div.col ol.breadcrumb'); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item a[href]')), 2); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item')), 3); //last item aint link | ||
|
||
$discussionDom = parent::assertDomHas($dom, 'div.container-fluid.my-2'); | ||
Assert::equal(count($discussionDom->find('div.row.justify-content-md-center')), 2); //search container and wysiwyg container | ||
|
||
$wysiwygDom = parent::assertDomHas($discussionDom, 'div.row.justify-content-md-center', 0); | ||
$searchBarDom = parent::assertDomHas($discussionDom, 'div.row.justify-content-md-center', 1); | ||
|
||
//user can write, assert there is addPost textarea wysiwyg shown | ||
parent::assertDomHas($wysiwygDom, 'div.col-md-10 textarea#addPost'); | ||
|
||
$searchFormDom = parent::assertDomHas($searchBarDom, 'div.col-md-10 div.addPost form.form-inline'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group input.form-control[name=search]'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group select.form-control.custom-select[name=suser]'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group button.form-control.btn.btn-outline-success.mr-sm-2.rounded-right'); | ||
|
||
parent::assertDomHas($searchFormDom, 'div.col-3 button#editPost.btn.btn-warning'); | ||
|
||
$discussionPostsDom = parent::assertDomHas($discussionDom, 'div.container-fluid.discussion#snippet--discussion'); | ||
Assert::count(0, $discussionPostsDom->find('div.row')); | ||
|
||
$this->recordManager->deleteDiscussion($discussion["id"]); | ||
} | ||
|
||
public function testActionDiscussionReadableOnly() | ||
{ | ||
$this->authorizeAdmin(); | ||
$discussion = $this->recordManager->createDiscussion(null, ["writeRightName" => "ADMINONLY"]); | ||
$discussionWebName = Strings::webalize($discussion["id"] . "-" . $discussion["caption"]); | ||
|
||
$this->authorizeUser(); //this user can read only in this discussion | ||
$request = new Nette\Application\Request($this->presenterName, 'GET', ['action' => 'default', 'discussion' => $discussionWebName]); | ||
$response = $this->presenter->run($request); | ||
|
||
Assert::type('Nette\Application\Responses\TextResponse', $response); | ||
|
||
$re = '/&(?!(?:apos|quot|[gl]t|amp);|#)/'; | ||
|
||
$dom = NULL; | ||
$html = (string)$response->getSource(); | ||
//replace unescaped ampersands in html to prevent tests from failing | ||
$html = preg_replace($re, "&", $html); | ||
|
||
$dom = DomQuery::fromHtml($html); | ||
//has navbar | ||
parent::assertDomHas($dom,'div#snippet-navbar-nav'); | ||
|
||
//has breadcrumbs | ||
|
||
parent::assertDomHas($dom,'div.container div.row div.col ol.breadcrumb'); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item a[href]')), 2); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item')), 3); //last item aint link | ||
|
||
$discussionDom = parent::assertDomHas($dom, 'div.container-fluid.my-2'); | ||
Assert::falsey(count($dom->find('div.container.my-2 div.row.justify-content-md-center div.col-md-10 textarea#addPost'))); //user cannot write, assert there is not addPost textarea wysiwyg shown | ||
Assert::equal(count($discussionDom->find('div.row.justify-content-md-center')), 1); //only search container | ||
$searchBarDom = parent::assertDomHas($discussionDom, 'div.row.justify-content-md-center', 0); | ||
$searchFormDom = parent::assertDomHas($searchBarDom, 'div.col-md-10 div.addPost form.form-inline'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group input.form-control[name=search]'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group select.form-control.custom-select[name=suser]'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group button.form-control.btn.btn-outline-success.mr-sm-2.rounded-right'); | ||
|
||
Assert::falsey(count($searchFormDom->find('div.col-3 button#editPost.btn.btn-warning'))); //no editPost button is shown in search bar | ||
|
||
$discussionPostsDom = parent::assertDomHas($discussionDom, 'div.container-fluid.discussion#snippet--discussion'); | ||
Assert::count(0, $discussionPostsDom->find('div.row')); | ||
|
||
$this->recordManager->deleteDiscussion($discussion["id"]); | ||
} | ||
|
||
protected function getPresenter(): string | ||
{ | ||
return "Discussion"; | ||
} | ||
|
||
public function getModule(): string | ||
{ | ||
return "Discussion"; | ||
} | ||
} | ||
|
||
(new DiscussionDetailUiTest($container))->run(); | ||
<?php | ||
|
||
// phpcs:disable PSR1.Files.SideEffects | ||
|
||
namespace Tymy\Module\Autotest\Discussion; | ||
|
||
use Nette; | ||
use Nette\Application\Request; | ||
use Nette\Application\Responses\TextResponse; | ||
use Nette\Utils\Strings; | ||
use Tester\Assert; | ||
use Tester\DomQuery; | ||
use Tymy\Bootstrap; | ||
use Tymy\Module\Autotest\UITest; | ||
|
||
use function count; | ||
|
||
require getenv("ROOT_DIR") . '/app/Bootstrap.php'; | ||
$container = Bootstrap::boot(); | ||
|
||
class DiscussionDetailUiTest extends UITest | ||
{ | ||
protected function getDomForAction(Nette\Application\UI\Presenter $presenter, string $action = "default", array $params = []) | ||
{ | ||
$this->authorizeUser(); | ||
$request = new Request($presenter, 'GET', ['action' => $action] + $params); | ||
$response = $presenter->run($request); | ||
|
||
Assert::type(TextResponse::class, $response); | ||
assert($response instanceof TextResponse); | ||
|
||
//replace unescaped ampersands in html to prevent tests from failing | ||
$html = preg_replace('/&(?!(?:apos|quot|[gl]t|amp);|#)/', "&", (string) $response->getSource()); | ||
|
||
return DomQuery::fromHtml($html); | ||
} | ||
|
||
public function testActionDiscussionReadableWritable() | ||
{ | ||
$this->authorizeAdmin(); | ||
$discussion = $this->recordManager->createDiscussion(); | ||
$discussionWebName = Strings::webalize($discussion["id"] . "-" . $discussion["caption"]); | ||
$dom = $this->getDomForAction($this->presenter, 'default', ['discussion' => $discussionWebName]); | ||
|
||
//has navbar | ||
parent::assertDomHas($dom, 'div#snippet-navbar-nav'); | ||
|
||
//has breadcrumbs | ||
parent::assertDomHas($dom, 'div.container div.row div.col ol.breadcrumb'); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item a[href]')), 2); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item')), 3); //last item aint link | ||
|
||
$discussionDom = parent::assertDomHas($dom, 'div.container-fluid.my-2'); | ||
Assert::equal(count($discussionDom->find('div.row.justify-content-md-center')), 2); //search container and wysiwyg container | ||
|
||
$wysiwygDom = parent::assertDomHas($discussionDom, 'div.row.justify-content-md-center', 0); | ||
$searchBarDom = parent::assertDomHas($discussionDom, 'div.row.justify-content-md-center', 1); | ||
|
||
//user can write, assert there is addPost textarea wysiwyg shown | ||
parent::assertDomHas($wysiwygDom, 'div.col-md-10 textarea#addPost'); | ||
|
||
$searchFormDom = parent::assertDomHas($searchBarDom, 'div.col-md-10 div.addPost form.form-inline'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group input.form-control[name=search]'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group select.form-control.custom-select[name=suser]'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group button.form-control.btn.btn-outline-success.mr-sm-2.rounded-right'); | ||
|
||
parent::assertDomHas($searchFormDom, 'div.col-3 button#editPost.btn.btn-warning'); | ||
|
||
$discussionPostsDom = parent::assertDomHas($discussionDom, 'div.container-fluid.discussion#snippet--discussion'); | ||
Assert::count(0, $discussionPostsDom->find('div.row')); | ||
|
||
$this->recordManager->deleteDiscussion($discussion["id"]); | ||
} | ||
|
||
public function testActionDiscussionReadableOnly() | ||
{ | ||
$this->authorizeAdmin(); | ||
$discussion = $this->recordManager->createDiscussion(null, ["writeRightName" => "ADMINONLY"]); | ||
$discussionWebName = Strings::webalize($discussion["id"] . "-" . $discussion["caption"]); | ||
|
||
$this->authorizeUser(); //this user can read only in this discussion | ||
$dom = $this->getDomForAction($this->presenter, 'default', ['discussion' => $discussionWebName]); | ||
|
||
//has navbar | ||
parent::assertDomHas($dom, 'div#snippet-navbar-nav'); | ||
|
||
//has breadcrumbs | ||
|
||
parent::assertDomHas($dom, 'div.container div.row div.col ol.breadcrumb'); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item a[href]')), 2); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item')), 3); //last item aint link | ||
|
||
$discussionDom = parent::assertDomHas($dom, 'div.container-fluid.my-2'); | ||
Assert::falsey(count($dom->find('div.container.my-2 div.row.justify-content-md-center div.col-md-10 textarea#addPost'))); //user cannot write, assert there is not addPost textarea wysiwyg shown | ||
Assert::equal(count($discussionDom->find('div.row.justify-content-md-center')), 1); //only search container | ||
$searchBarDom = parent::assertDomHas($discussionDom, 'div.row.justify-content-md-center', 0); | ||
$searchFormDom = parent::assertDomHas($searchBarDom, 'div.col-md-10 div.addPost form.form-inline'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group input.form-control[name=search]'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group select.form-control.custom-select[name=suser]'); | ||
parent::assertDomHas($searchFormDom, 'div.col-9 div.input-group button.form-control.btn.btn-outline-success.mr-sm-2.rounded-right'); | ||
|
||
Assert::falsey(count($searchFormDom->find('div.col-3 button#editPost.btn.btn-warning'))); //no editPost button is shown in search bar | ||
|
||
$discussionPostsDom = parent::assertDomHas($discussionDom, 'div.container-fluid.discussion#snippet--discussion'); | ||
Assert::count(0, $discussionPostsDom->find('div.row')); | ||
|
||
$this->recordManager->deleteDiscussion($discussion["id"]); | ||
} | ||
|
||
protected function getPresenter(): string | ||
{ | ||
return "Discussion"; | ||
} | ||
|
||
public function getModule(): string | ||
{ | ||
return "Discussion"; | ||
} | ||
} | ||
|
||
(new DiscussionDetailUiTest($container))->run(); |
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 |
---|---|---|
@@ -1,46 +1,47 @@ | ||
<?php | ||
|
||
namespace Tymy\Module\Autotest\Discussion; | ||
|
||
use Tester\Assert; | ||
use Tymy\Bootstrap; | ||
use Tymy\Module\Autotest\UITest; | ||
|
||
use function count; | ||
|
||
require getenv("ROOT_DIR") . '/app/Bootstrap.php'; | ||
$container = Bootstrap::boot(); | ||
|
||
class DiscussionsUiTest extends UITest | ||
{ | ||
|
||
public function testActionDefault() | ||
{ | ||
$dom = parent::getDomForAction($this->presenter); | ||
|
||
//has navbar | ||
parent::assertDomHas($dom, 'div#snippet-navbar-nav'); | ||
|
||
//has breadcrumbs | ||
$containerDom = parent::assertDomHas($dom, 'div.container'); | ||
parent::assertDomHas($containerDom, 'ol.breadcrumb'); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item a[href]')), 1); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item')), 2); //last item aint link | ||
|
||
$discussionsDom = parent::assertDomHas($dom, 'div.container-fluid.discussions'); | ||
$discussionsListDom = parent::assertDomHas($discussionsDom, 'div.card.sh-box.discussion-box'); | ||
Assert::true(count($discussionsListDom->find('div.card-body div.row')) >= 1); | ||
} | ||
|
||
protected function getPresenter(): string | ||
{ | ||
return "Default"; | ||
} | ||
|
||
public function getModule(): string | ||
{ | ||
return "Discussion"; | ||
} | ||
} | ||
|
||
(new DiscussionsUiTest($container))->run(); | ||
<?php | ||
|
||
// phpcs:disable PSR1.Files.SideEffects | ||
|
||
namespace Tymy\Module\Autotest\Discussion; | ||
|
||
use Tester\Assert; | ||
use Tymy\Bootstrap; | ||
use Tymy\Module\Autotest\UITest; | ||
|
||
use function count; | ||
|
||
require getenv("ROOT_DIR") . '/app/Bootstrap.php'; | ||
$container = Bootstrap::boot(); | ||
|
||
class DiscussionsUiTest extends UITest | ||
{ | ||
public function testActionDefault() | ||
{ | ||
$dom = parent::getDomForAction($this->presenter); | ||
|
||
//has navbar | ||
parent::assertDomHas($dom, 'div#snippet-navbar-nav'); | ||
|
||
//has breadcrumbs | ||
$containerDom = parent::assertDomHas($dom, 'div.container'); | ||
parent::assertDomHas($containerDom, 'ol.breadcrumb'); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item a[href]')), 1); | ||
Assert::equal(count($dom->find('ol.breadcrumb li.breadcrumb-item')), 2); //last item aint link | ||
|
||
$discussionsDom = parent::assertDomHas($dom, 'div.container-fluid.discussions'); | ||
$discussionsListDom = parent::assertDomHas($discussionsDom, 'div.card.sh-box.discussion-box'); | ||
Assert::true(count($discussionsListDom->find('div.card-body div.row')) >= 1); | ||
} | ||
|
||
protected function getPresenter(): string | ||
{ | ||
return "Default"; | ||
} | ||
|
||
public function getModule(): string | ||
{ | ||
return "Discussion"; | ||
} | ||
} | ||
|
||
(new DiscussionsUiTest($container))->run(); |
Oops, something went wrong.