diff --git a/app/TeenQuotes/Newsletters/NewslettersManager.php b/app/TeenQuotes/Newsletters/NewslettersManager.php index 553a4ac5..7a32040b 100644 --- a/app/TeenQuotes/Newsletters/NewslettersManager.php +++ b/app/TeenQuotes/Newsletters/NewslettersManager.php @@ -1,10 +1,11 @@ whereNotNull('country') ->groupBy('country') ->orderBy('total', 'DESC') ->first(); diff --git a/ressources/views/quotes/partials/moderationButtons.blade.php b/ressources/views/quotes/partials/moderationButtons.blade.php index 69c49d21..2ad62bf2 100644 --- a/ressources/views/quotes/partials/moderationButtons.blade.php +++ b/ressources/views/quotes/partials/moderationButtons.blade.php @@ -1,19 +1,27 @@
- + + +
- + + +
- + + +
- + + +
\ No newline at end of file diff --git a/tests/_support/AdminPanelHelper.php b/tests/_support/AdminPanelHelper.php index a0be411d..6805773b 100644 --- a/tests/_support/AdminPanelHelper.php +++ b/tests/_support/AdminPanelHelper.php @@ -38,7 +38,55 @@ public function seeModerationButtonsForQuote(Quote $q) } // I can see the edit button - $I->seeNumberOfElements($parentClass.' .fa-pencil-square-o', 1); + $I->seeNumberOfElements($this->getCssEditLink($q), 1); + } + + /** + * Click the edit button for a quote and assert that we've been redirected + * @param \TeenQuotes\Quotes\Models\Quote $q + */ + public function clickEditButtonFor(Quote $q) + { + $I = $this->getModule('Laravel4'); + + $I->click($this->getCssEditLink($q)); + $I->seeCurrentRouteIs('admin.quotes.edit', $q->id); + } + + /** + * Check that the author of a quote got an email telling him that one of its + * quote was approved + * @param \TeenQuotes\Quotes\Models\Quote $quote + */ + public function seeAuthorOfQuoteHasBeenWarnedOfApproval(Quote $quote) + { + $I = $this->getModule('MailCatcher'); + + $I->seeInLastEmailTo($quote->user->email, 'Your quote has been approved!'); + } + + /** + * Check that a quote is pending. Grab the quote from the DB + * @param \TeenQuotes\Quotes\Models\Quote $q + */ + public function seeQuoteIsPending(Quote $q) + { + $I = $this->getModule('Laravel4'); + + $quote = $I->grabRecord('quotes', ['id' => $q->id]); + + $I->assertEquals($quote->approved, Quote::PENDING); + } + + /** + * Get the CSS class for the link to the edit form for a quote + * @param \TeenQuotes\Quotes\ModelsQuote $q + */ + private function getCssEditLink(Quote $q) + { + $parentClass = $this->getCssParentClass($q); + + return $parentClass.' .admin__quote__edit-button'; } /** diff --git a/tests/_support/FormFillerHelper.php b/tests/_support/FormFillerHelper.php index 341c2b8a..a2a579d1 100644 --- a/tests/_support/FormFillerHelper.php +++ b/tests/_support/FormFillerHelper.php @@ -19,7 +19,7 @@ public function fillSigninForm($login, $password) public function fillEditCommentForm($text) { $I = $this->getModule('Laravel4'); - + $I->fillField('#content-comment', $text); $I->click('Edit my comment!'); } @@ -134,6 +134,18 @@ public function fillChangePasswordForm($password, $passwordRepeat) $I->click('Change my password!'); } + /** + * Fill and submit the form to set the new content of a quote waiting to be moderated + * @param string $content The new content + */ + public function fillNewContentWaitingQuoteForm($content) + { + $I = $this->getModule('Laravel4'); + + $I->fillField('Content of the quote', $content); + $I->click('Edit this quote!'); + } + public function fillUserSettingsForm(array $params) { $I = $this->getModule('Laravel4'); diff --git a/tests/functional.suite.yml b/tests/functional.suite.yml index ffbad0c8..15790751 100644 --- a/tests/functional.suite.yml +++ b/tests/functional.suite.yml @@ -6,7 +6,8 @@ class_name: FunctionalTester modules: - enabled: + enabled: + - AdminPanelHelper - Asserts - AuthHelper - Db diff --git a/tests/functional/AdminPanel/EditWaitingQuoteCest.php b/tests/functional/AdminPanel/EditWaitingQuoteCest.php new file mode 100644 index 00000000..277f3b1a --- /dev/null +++ b/tests/functional/AdminPanel/EditWaitingQuoteCest.php @@ -0,0 +1,71 @@ +tester = $I; + + $this->nbQuotes = [ + 'pending' => 7, + 'waiting' => 26, + ]; + + $I->createSomePublishedQuotes(); + $this->waitingQuotes = $I->createSomeWaitingQuotes(['nb_quotes' => $this->nbQuotes['waiting']]); + $I->createSomePendingQuotes(['nb_quotes' => $this->nbQuotes['pending']]); + + $this->admin = $I->logANewUser(['security_level' => 1]); + } + + public function editQuoteWaitingForModeration(FunctionalTester $I) + { + $I->am("a Teen Quotes' administrator"); + $I->wantTo('edit and publish a quote waiting to be moderated'); + + // Go to the admin panel + $I->navigateToTheAdminPanel(); + + $quote = $this->waitingQuotes[0]; + $I->seeModerationButtonsForQuote($quote); + + // Click the edit button and fill the form + $newContent = str_repeat('abc', 20); + $this->editContentOfQuote($quote, $newContent); + } + + private function editContentOfQuote(Quote $quote, $newContent) + { + $this->tester->clickEditButtonFor($quote); + $this->tester->fillNewContentWaitingQuoteForm($newContent); + $this->tester->seeSuccessFlashMessage('The quote has been edited and approved!'); + $this->tester->seeQuoteIsPending($quote); + $this->tester->seeAuthorOfQuoteHasBeenWarnedOfApproval($quote); + } +} \ No newline at end of file diff --git a/tests/functional/AdminPanel/ListWaitingQuotesCest.php b/tests/functional/AdminPanel/ListWaitingQuotesCest.php index 55e764b5..e6f5a740 100644 --- a/tests/functional/AdminPanel/ListWaitingQuotesCest.php +++ b/tests/functional/AdminPanel/ListWaitingQuotesCest.php @@ -1,6 +1,5 @@ waitingQuotes as $quote) { - $this->seeModerationButtonsForQuote($quote); - $this->seeContentForQuote($quote); + $this->tester->seeModerationButtonsForQuote($quote); + $this->tester->seeContentForQuoteWaitingForModeration($quote); } } - /** - * I can see that the content of a quote is displayed - * @param \TeenQuotes\Quotes\Models\Quote $q - */ - private function seeContentForQuote(Quote $q) - { - $parentClass = $this->getCssParentClass($q); - - $this->tester->see($q->content, $parentClass); - } - - /** - * I can see moderation buttons for each quote - * @param \TeenQuotes\Quotes\Models\Quote $q - */ - private function seeModerationButtonsForQuote(Quote $q) - { - $parentClass = $this->getCssParentClass($q); - - // I can see moderation decisions - $moderationDecisions = Moderation::getAvailableTypes(); - foreach ($moderationDecisions as $decision) - { - $cssClass = $parentClass.' .quote-moderation[data-decision="'.$decision.'"]'; - $this->tester->seeNumberOfElements($cssClass, 1); - } - - // I can see the edit button - $this->tester->seeNumberOfElements($parentClass.' .fa-pencil-square-o', 1); - } - - /** - * Get the CSS class for a quote - * @param \TeenQuotes\Quotes\ModelsQuote $q - */ - private function getCssParentClass(Quote $q) - { - return '.quote[data-id='.$q->id.']'; - } - /** * Compute the number of days to publish the given number of quotes * @param int $nbQuotes The number of quotes to publish