diff --git a/app/module/autotest/app/discussion/DiscussionDetailUiTest.php b/app/module/autotest/app/discussion/DiscussionDetailUiTest.php index 1d04775a..51d6182a 100644 --- a/app/module/autotest/app/discussion/DiscussionDetailUiTest.php +++ b/app/module/autotest/app/discussion/DiscussionDetailUiTest.php @@ -1,130 +1,121 @@ -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(); +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(); diff --git a/app/module/autotest/app/discussion/DiscussionsUiTest.php b/app/module/autotest/app/discussion/DiscussionsUiTest.php index b2dc0a82..129ea546 100644 --- a/app/module/autotest/app/discussion/DiscussionsUiTest.php +++ b/app/module/autotest/app/discussion/DiscussionsUiTest.php @@ -1,46 +1,47 @@ -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(); +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(); diff --git a/app/module/autotest/app/event/EventDetailUiTest.php b/app/module/autotest/app/event/EventDetailUiTest.php index e29c2ea4..7db4e53d 100644 --- a/app/module/autotest/app/event/EventDetailUiTest.php +++ b/app/module/autotest/app/event/EventDetailUiTest.php @@ -1,67 +1,61 @@ -authorizeAdmin(); - $event = $this->recordManager->createEvent(); - - $this->authorizeUser(); - $dom = parent::getDomForAction($this->presenter, 'event', ["udalost" => $event["id"]]); - - //has navbar - Assert::true($dom->has('div#snippet-navbar-nav')); - //has breadcrumbs - Assert::true($dom->has('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 - //test body - Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3 div.card-header div.row div.col h4.card-title')); - - - Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body h6.card-subtitle.mb-2.text-muted span a')); - Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body p.card-text')); - Assert::equal(count($dom->find('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body div.row div.col-lg-4 table.table.mb-0 tr th')), 3); - Assert::equal(count($dom->find('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body div.row div.col-lg-4 table.table.mb-0 tr td')), 3); - - Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body div.row div.col-lg-8.d-flex.flex-column-reverse.align-items-center input.form-control.form-control-sm.custom-btn-sm')); - Assert::count(3, $dom->find('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body div.row div.col-lg-8.d-flex.flex-column-reverse.align-items-center button.btn.custom-btn-sm')); - Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body div.row div.col-lg-8.d-flex.flex-column-reverse.align-items-center div#snippet--attendanceWarning')); - - Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3#snippet--attendanceTabs div.card-header ul.nav.nav-tabs.flex-column.flex-sm-row.card-header-tabs li.nav-item')); - Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3#snippet--attendanceTabs div.card-body div.tab-content div.tab-pane.fade.player-list div.row.my-2')); - - //admin sees also pencil button - $this->authorizeAdmin(); - $dom = parent::getDomForAction($this->presenter, 'event', ["udalost" => $event["id"]]); - - $pencilBtn = 'div.container.event div.row div.col div.card.sh-box.my-3 div.card-header div.row div.col.col-md-auto a.btn.btn-sm.btn-light.btn-light-bordered i.fa.fa-edit'; - Assert::true($dom->has($pencilBtn)); - - $this->recordManager->deleteEvent($event["id"]); - } - - protected function getPresenter(): string - { - return "Event"; - } - - public function getModule(): string - { - return "Event"; - } -} - -$test = new EventDetailUiTest($container); -$test->run(); +authorizeAdmin(); + $event = $this->recordManager->createEvent(); + $this->authorizeUser(); + $dom = parent::getDomForAction($this->presenter, 'event', ["udalost" => $event["id"]]); +//has navbar + Assert::true($dom->has('div#snippet-navbar-nav')); +//has breadcrumbs + Assert::true($dom->has('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 + //test body + Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3 div.card-header div.row div.col h4.card-title')); + Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body h6.card-subtitle.mb-2.text-muted span a')); + Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body p.card-text')); + Assert::equal(count($dom->find('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body div.row div.col-lg-4 table.table.mb-0 tr th')), 3); + Assert::equal(count($dom->find('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body div.row div.col-lg-4 table.table.mb-0 tr td')), 3); + Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body div.row div.col-lg-8.d-flex.flex-column-reverse.align-items-center input.form-control.form-control-sm.custom-btn-sm')); + Assert::count(3, $dom->find('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body div.row div.col-lg-8.d-flex.flex-column-reverse.align-items-center button.btn.custom-btn-sm')); + Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3 div.card-body div.row div.col-lg-8.d-flex.flex-column-reverse.align-items-center div#snippet--attendanceWarning')); + Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3#snippet--attendanceTabs div.card-header ul.nav.nav-tabs.flex-column.flex-sm-row.card-header-tabs li.nav-item')); + Assert::true($dom->has('div.container.event div.row div.col div.card.sh-box.my-3#snippet--attendanceTabs div.card-body div.tab-content div.tab-pane.fade.player-list div.row.my-2')); +//admin sees also pencil button + $this->authorizeAdmin(); + $dom = parent::getDomForAction($this->presenter, 'event', ["udalost" => $event["id"]]); + $pencilBtn = 'div.container.event div.row div.col div.card.sh-box.my-3 div.card-header div.row div.col.col-md-auto a.btn.btn-sm.btn-light.btn-light-bordered i.fa.fa-edit'; + Assert::true($dom->has($pencilBtn)); + $this->recordManager->deleteEvent($event["id"]); + } + + protected function getPresenter(): string + { + return "Event"; + } + + public function getModule(): string + { + return "Event"; + } +} + +$test = new EventDetailUiTest($container); +$test->run(); diff --git a/app/module/autotest/app/event/EventsUiTest.php b/app/module/autotest/app/event/EventsUiTest.php index 3f8013ab..8858abd8 100644 --- a/app/module/autotest/app/event/EventsUiTest.php +++ b/app/module/autotest/app/event/EventsUiTest.php @@ -1,49 +1,49 @@ -presenter); - - //has navbar - Assert::true($dom->has('div#snippet-navbar-nav')); - //has breadcrumbs - Assert::true($dom->has('div.container div.row div.col 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 - - Assert::true($dom->has('div.container.events')); - Assert::true(count($dom->find('div.container.events div.row')) >= 1); - Assert::true($dom->has('div.container.events div.row div.col-md-7.my-3 div.card.sh-box#calendar')); - - Assert::true($dom->has('div.container.events div.row div.col-md-5.my-3.agenda-wrapper#snippet--events-agenda')); - Assert::equal(count($dom->find('div.container.events div.row div.col-md-5.my-3.agenda-wrapper#snippet--events-agenda div.card.sh-box.agenda[data-month]')), 13); - } - - protected function getPresenter(): string - { - return "Event"; - } - - public function getModule(): string - { - return "Event"; - } -} - -$test = new EventsUiTest($container); -$test->run(); +presenter); +//has navbar + Assert::true($dom->has('div#snippet-navbar-nav')); +//has breadcrumbs + Assert::true($dom->has('div.container div.row div.col 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 + + Assert::true($dom->has('div.container.events')); + Assert::true(count($dom->find('div.container.events div.row')) >= 1); + Assert::true($dom->has('div.container.events div.row div.col-md-7.my-3 div.card.sh-box#calendar')); + Assert::true($dom->has('div.container.events div.row div.col-md-5.my-3.agenda-wrapper#snippet--events-agenda')); + Assert::equal(count($dom->find('div.container.events div.row div.col-md-5.my-3.agenda-wrapper#snippet--events-agenda div.card.sh-box.agenda[data-month]')), 13); + } + + protected function getPresenter(): string + { + return "Event"; + } + + public function getModule(): string + { + return "Event"; + } +} + +$test = new EventsUiTest($container); +$test->run(); diff --git a/app/module/autotest/entity/UITest.php b/app/module/autotest/entity/UITest.php index 647cc59b..1e756895 100644 --- a/app/module/autotest/entity/UITest.php +++ b/app/module/autotest/entity/UITest.php @@ -25,7 +25,7 @@ protected function setUp() parent::setUp(); } - + /** * Load DOM response on presenter/action query *