From 596e0705ec7c792cce1c5a8f758f7c3ae567ea64 Mon Sep 17 00:00:00 2001 From: Antoine Augusti Date: Sat, 28 Mar 2015 11:26:22 +0100 Subject: [PATCH 1/4] refactor(adminPanel): clean how we do the FT to list waiting quotes Different CSS class to target the edit button Move methods to a dedicated class --- .../partials/moderationButtons.blade.php | 16 ++++-- tests/_support/AdminPanelHelper.php | 50 ++++++++++++++++++- tests/functional.suite.yml | 3 +- .../AdminPanel/ListWaitingQuotesCest.php | 45 +---------------- 4 files changed, 65 insertions(+), 49 deletions(-) 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/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/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 From 24e61265f66888836da3479d42128b371b474186 Mon Sep 17 00:00:00 2001 From: Antoine Augusti Date: Sat, 28 Mar 2015 11:33:52 +0100 Subject: [PATCH 2/4] feature: create a FT to edit a quote waiting for moderation Create a functional test that we can edit a quote waiting to be moderated. --- tests/_support/FormFillerHelper.php | 14 +++- .../AdminPanel/EditWaitingQuoteCest.php | 71 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 tests/functional/AdminPanel/EditWaitingQuoteCest.php 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/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 From dc9363a3fc3bc910d38444782e8e6696fbb97f3a Mon Sep 17 00:00:00 2001 From: Antoine Augusti Date: Sat, 28 Mar 2015 11:39:38 +0100 Subject: [PATCH 3/4] fix(newsletters): import the missing collection class The Collection class was not imported before, causing a bug --- app/TeenQuotes/Newsletters/NewslettersManager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 @@ Date: Sat, 28 Mar 2015 11:55:52 +0100 Subject: [PATCH 4/4] fix(countries): target only not null countries when finding the most common one Only target non null values for countries in the users' table when trying to find the most common country --- app/TeenQuotes/Users/Repositories/DbUserRepository.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/TeenQuotes/Users/Repositories/DbUserRepository.php b/app/TeenQuotes/Users/Repositories/DbUserRepository.php index 5b9895e8..1aa24efa 100644 --- a/app/TeenQuotes/Users/Repositories/DbUserRepository.php +++ b/app/TeenQuotes/Users/Repositories/DbUserRepository.php @@ -248,6 +248,7 @@ public function destroy($u) public function mostCommonCountryId() { $u = User::select('country', DB::raw('count(*) as total')) + ->whereNotNull('country') ->groupBy('country') ->orderBy('total', 'DESC') ->first();