Skip to content

Commit

Permalink
Merge branch 'release/3.4.1' into v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti committed Mar 28, 2015
2 parents de21028 + fc92f18 commit bd8be6b
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 51 deletions.
3 changes: 2 additions & 1 deletion app/TeenQuotes/Newsletters/NewslettersManager.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php namespace TeenQuotes\Newsletters;

use App;
use Illuminate\Support\Collection;
use TeenQuotes\Newsletters\Models\Newsletter;
use TeenQuotes\Newsletters\NewsletterList;
use TeenQuotes\Newsletters\Repositories\NewsletterRepository;
use TeenQuotes\Users\Models\User;
use TeenQuotes\Newsletters\Models\Newsletter;

class NewslettersManager {

Expand Down
1 change: 1 addition & 0 deletions app/TeenQuotes/Users/Repositories/DbUserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 12 additions & 4 deletions ressources/views/quotes/partials/moderationButtons.blade.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
<!-- Approve -->
<div class="col-xs-1">
<span class="badge quote-moderation" data-id="{{{ $quote->id }}}" data-url="{{{ URL::route('admin.quotes.moderate', [$quote->id, 'approve']) }}}" data-decision="approve"><i class="fa fa-thumbs-up"></i></span>
<span class="badge quote-moderation" data-id="{{{ $quote->id }}}" data-url="{{{ URL::route('admin.quotes.moderate', [$quote->id, 'approve']) }}}" data-decision="approve">
<i class="fa fa-thumbs-up"></i>
</span>
</div>

<!-- Unapprove -->
<div class="col-xs-1">
<span class="badge quote-moderation" data-id="{{{ $quote->id }}}" data-url="{{{ URL::route('admin.quotes.moderate', [$quote->id, 'unapprove']) }}}" data-decision="unapprove"><i class="fa fa-thumbs-down"></i></span>
<span class="badge quote-moderation" data-id="{{{ $quote->id }}}" data-url="{{{ URL::route('admin.quotes.moderate', [$quote->id, 'unapprove']) }}}" data-decision="unapprove">
<i class="fa fa-thumbs-down"></i>
</span>
</div>

<!-- Edit -->
<div class="col-xs-1">
<a href="{{ URL::route('admin.quotes.edit', array($quote->id)); }}" class="badge"><i class="fa fa-pencil-square-o"></i></a>
<a href="{{ URL::route('admin.quotes.edit', array($quote->id)); }}" class="badge admin__quote__edit-button">
<i class="fa fa-pencil-square-o"></i>
</a>
</div>

<!-- Alert sad content -->
<div class="col-xs-1">
<span class="badge quote-moderation" data-id="{{{ $quote->id }}}" data-url="{{{ URL::route('admin.quotes.moderate', [$quote->id, 'alert']) }}}" data-decision="alert"><i class="fa fa-warning"></i></span>
<span class="badge quote-moderation" data-id="{{{ $quote->id }}}" data-url="{{{ URL::route('admin.quotes.moderate', [$quote->id, 'alert']) }}}" data-decision="alert">
<i class="fa fa-warning"></i>
</span>
</div>
50 changes: 49 additions & 1 deletion tests/_support/AdminPanelHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
14 changes: 13 additions & 1 deletion tests/_support/FormFillerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
Expand Down Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion tests/functional.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

class_name: FunctionalTester
modules:
enabled:
enabled:
- AdminPanelHelper
- Asserts
- AuthHelper
- Db
Expand Down
71 changes: 71 additions & 0 deletions tests/functional/AdminPanel/EditWaitingQuoteCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

use TeenQuotes\AdminPanel\Helpers\Moderation;
use TeenQuotes\Quotes\Models\Quote;

class EditWaitingQuoteCest {

/**
* The admin user
* @var \TeenQuotes\Users\Models\User
*/
private $admin;

/**
* @var \FunctionalTester
*/
private $tester;

/**
* The number of quotes created, by approved type
* @var array
*/
private $nbQuotes;

/**
* Quotes that are waiting to be published
* @var array
*/
private $waitingQuotes;

public function _before(FunctionalTester $I)
{
$this->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);
}
}
45 changes: 2 additions & 43 deletions tests/functional/AdminPanel/ListWaitingQuotesCest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use TeenQuotes\AdminPanel\Helpers\Moderation;
use TeenQuotes\Quotes\Models\Quote;

class ListWaitingQuotesCest {
Expand Down Expand Up @@ -70,51 +69,11 @@ private function seeRequiredElementsForQuotes(array $quotes)
{
foreach ($this->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
Expand Down

0 comments on commit bd8be6b

Please sign in to comment.