Skip to content

Commit

Permalink
finishing up with the test
Browse files Browse the repository at this point in the history
  • Loading branch information
summerblue committed Aug 25, 2014
1 parent 1f27398 commit 88022ac
Show file tree
Hide file tree
Showing 27 changed files with 455 additions and 71 deletions.
11 changes: 10 additions & 1 deletion app/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

class UsersController extends \BaseController {


public function __construct(Topic $topic)
{
parent::__construct();

$this->beforeFilter('auth', ['only' => ['edit', 'update', 'destroy']]);
$this->topic = $topic;
}

public function index()
{
$users = User::recent()->take(48)->get();
Expand All @@ -27,7 +36,7 @@ public function update($id)
{
$user = User::findOrFail($id);
$this->authorOrAdminPermissioinRequire($user->id);
$data = Input::only('city', 'company', 'twitter_account', 'personal_website', 'signature', 'description');
$data = Input::only('city', 'company', 'twitter_account', 'personal_website', 'signature', 'introduction');
App::make('Phphub\Forms\UserUpdateForm')->validate($data);

$user->update($data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function up()
$table->string('twitter_account')->nullable();
$table->string('personal_website')->nullable();
$table->string('signature')->nullable();
$table->string('description')->nullable();
$table->string('introduction')->nullable();
$table->softDeletes();
$table->timestamps();
});
Expand Down
4 changes: 2 additions & 2 deletions app/database/seeds/UserTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public function run()
'company' => $faker->userName(),
'personal_website' => $faker->url(),
'signature' => $faker->sentence(),
'description' => $faker->sentence(),
'introduction' => $faker->sentence(),
'email' => $faker->email(),
]);
}
}

}
}
2 changes: 1 addition & 1 deletion app/views/topics/partials/replies.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<span> • </span>

@if ($currentUser && ($currentUser->can("manage_topics") || $currentUser->id == $reply->user_id) )
<a id="topic-delete-button" href="{{ route('replies.delete', [$reply->id]) }}" onclick=" return confirm('确定要删除此话题吗?')">
<a id="reply-delete-{{ $reply->id }}" href="{{ route('replies.delete', [$reply->id]) }}" onclick=" return confirm('确定要删除此话题吗?')">
<i class="fa fa-trash-o"></i>
</a>
<span> • </span>
Expand Down
14 changes: 7 additions & 7 deletions app/views/users/edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@extends('layouts.default')

@section('title')
编辑个人资料_@parent
编辑个人资料_@parent
@stop

@section('content')
Expand All @@ -15,15 +15,15 @@
<div class="main-col col-md-9 left-col">

<div class="panel panel-default">

<div class="panel-body ">

<div class="alert alert-warning">
如需修改头像, 请到 <a href="https://github.com/settings/profile" target="_blank">Github 的个人设置</a> 页面修改, 注意头像会有缓存, 估计一个小时内会见效.
</div>

@include('layouts.partials.errors')

{{ Form::model($user, ['route' => ['users.update', $user->id], 'method' => 'patch']) }}

<div class="form-group">
Expand All @@ -43,14 +43,14 @@
</div>

<div class="form-group">
{{ Form::textarea('signature', null, ['class' => 'form-control',
'rows' => 3,
{{ Form::textarea('signature', null, ['class' => 'form-control',
'rows' => 3,
'placeholder' => "签名/座右铭"]) }}
</div>

<div class="form-group">
{{ Form::textarea('description', null, ['class' => 'form-control',
'rows' => 3,
{{ Form::textarea('introduction', null, ['class' => 'form-control',
'rows' => 3,
'placeholder' => "个人简介"]) }}
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/users/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@foreach ($users as $user)
<div class="col-md-1 remove-padding-right">
<div class="avatar">
<a href="{{ route('users.show', $user->id) }}">
<a href="{{ route('users.show', $user->id) }}" class="users-index-{{ $user->id }}">
<img src="{{ $user->present()->gravatar }}" class="img-thumbnail avatar" style="width:48px;height:48px;margin-bottom: 20px;"/>
</a>
</div>
Expand Down
20 changes: 10 additions & 10 deletions app/views/users/partials/basicinfo.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
</div>

<dl class="dl-horizontal">

<dt><lable>&nbsp; </lable></dt><dd>第 {{ $user->id }} 位会员</dd>

<dt><label>Name:</label></dt><dd><strong>{{{ $user->name }}}</strong></dd>

<dt><label>Github:</label></dt>
<dd>
<a href="https://github.com/{{ $user->name }}" target="_blank">
<i class="fa fa-github-alt"></i> {{ $user->name }}
</a>
</dd>

@if ($user->company)
<dt class="adr"><label>公司:</label></dt><dd><span class="org">{{{ $user->company }}}</span></dd>
<dt class="adr"><label>公司:</label></dt><dd><span class="org">{{{ $user->company }}}</span></dd>
@endif

@if ($user->city)
<dt class="adr"><label>城市:</label></dt><dd><span class="org"><i class="fa fa-map-marker"></i> {{{ $user->city }}}</span></dd>
<dt class="adr"><label>城市:</label></dt><dd><span class="org"><i class="fa fa-map-marker"></i> {{{ $user->city }}}</span></dd>
@endif

@if ($user->twitter_account)
<dt><label><span>Twitter</span>:</label></dt>
<dd>
<a href="https://twitter.com/{{ $user->twitter_account }}" rel="nofollow" class="twitter" target="_blank"><i class="fa fa-twitter"></i> {{{ '@' . $user->twitter_account }}}
</a>
</dd>
@endif

@if ($user->personal_website)
<dt><label>博客:</label></dt>
<dd>
Expand All @@ -41,7 +41,7 @@
</a>
</dd>
@endif

@if ($user->signature)
<dt><label>签名:</label></dt><dd><span>{{{ $user->signature }}}</span></dd>
@endif
Expand All @@ -54,7 +54,7 @@
<div class="clearfix"></div>

@if ($currentUser && $currentUser->id == $user->id)
<a class="btn btn-primary btn-block" href="{{ route('users.edit', $user->id) }}">
<a class="btn btn-primary btn-block" href="{{ route('users.edit', $user->id) }}" id="user-edit-button">
<i class="icon-edit"></i> 编辑个人资料
</a>
@endif
@endif
8 changes: 6 additions & 2 deletions tests/_support/FunctionalHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

class FunctionalHelper extends \Codeception\Module
{
public function signIn()
public function signIn($user = null)
{
$user = $this->haveAnAccount();
$user = $user ? $user : $this->haveAnAccount();
$I = $this->getModule('Laravel4');

$I->logout();

// login user
$I->amLoggedAs($user);
return $user;
Expand All @@ -24,6 +26,8 @@ public function signInAsAdmin()
$user = $this->haveAnAccount();
$I = $this->getModule('Laravel4');

$I->logout();

$founder = Role::where('name', 'Founder')->get()->first();
$user->attachRole($founder);

Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ Reply:
body: $text
created_at: $date
updated_at: $date

Favorite:
user_id:
type: User
topic_id:
type: Topic
44 changes: 44 additions & 0 deletions tests/functional/Notifications/NotificationAttentionCept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* ------------------------------------
* Notify attented user
* ------------------------------------
*/

$I = new FunctionalTester($scenario);

Route::enableFilters();

$I->wantTo('Notify A User when he/she attented a Topic');
$topic = $I->postATopic(['title' => 'My Awsome Topic.']);

// attented a topic
$user = $I->signIn();
$I->amOnRoute('topics.show', $topic->id );
$I->click('#topic-attent-button');

// another user leave a reply
$randomUser = $I->signIn();
$I->amOnRoute('topics.show', $topic->id );
$I->fillField(['name' => 'body'], 'The Awsome Reply.');
$I->click('#reply-create-submit');
$I->see('The Awsome Reply.');

// the first user sign in again
$user = $I->signIn($user);

$I->seeRecord('users', [
'id' => $user->id,
'notification_count' => 1
]);

$I->amOnRoute('notifications.index');
$I->see('My Awsome Topic.');
$I->see('The Awsome Reply.');
$I->see($randomUser->name);

$I->seeRecord('users', [
'id' => $user->id,
'notification_count' => 0
]);
43 changes: 43 additions & 0 deletions tests/functional/Notifications/NotificationReplyAtUserCept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* ------------------------------------
* Notify user being "@"
* ------------------------------------
*/

$I = new FunctionalTester($scenario);

Route::enableFilters();

$I->wantTo('Notify a User when he/she is being AT on a newly Reply');

$SuperMan = $I->have('User', ['name' => 'SuperMan']);

$user = $I->signIn();
$topic = $I->postATopic(['title' => 'My Awsome Topic.', 'user_id' => $user->id]);

// another user leave a reply
$randomUser = $I->signIn();
$I->amOnRoute('topics.show', $topic->id );
$I->fillField(['name' => 'body'], 'The Awsome Reply. @SuperMan');
$I->click('#reply-create-submit');
$I->see('The Awsome Reply. [@SuperMan](' .route('users.show', $SuperMan->id).')');

// sign in the author
$user = $I->signIn($SuperMan);

$I->seeRecord('users', [
'id' => $user->id,
'notification_count' => 1
]);

$I->amOnRoute('notifications.index');
$I->see('My Awsome Topic.');
$I->see('The Awsome Reply. [@SuperMan](' .route('users.show', $SuperMan->id).')');
$I->see($randomUser->name);

$I->seeRecord('users', [
'id' => $user->id,
'notification_count' => 0
]);
41 changes: 41 additions & 0 deletions tests/functional/Notifications/NotificationReplyCept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* ------------------------------------
* Notify newly reply
* ------------------------------------
*/

$I = new FunctionalTester($scenario);

Route::enableFilters();

$I->wantTo('Notify The Author when his/her Topic has a new Reply');

$user = $I->have('User', ['name' => 'SuperMan']);
$topic = $I->postATopic(['title' => 'My Awsome Topic.', 'user_id' => $user->id]);

// another user leave a reply
$randomUser = $I->signIn();
$I->amOnRoute('topics.show', $topic->id );
$I->fillField(['name' => 'body'], 'The Awsome Reply.');
$I->click('#reply-create-submit');
$I->see('The Awsome Reply.');

// sign in the author
$user = $I->signIn($user);

$I->seeRecord('users', [
'id' => $user->id,
'notification_count' => 1
]);

$I->amOnRoute('notifications.index');
$I->see('My Awsome Topic.');
$I->see('The Awsome Reply.');
$I->see($randomUser->name);

$I->seeRecord('users', [
'id' => $user->id,
'notification_count' => 0
]);
4 changes: 2 additions & 2 deletions tests/functional/Pages/PagesControllerCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public function home(FunctionalTester $I)
{
$I->am('a guest');
$I->wantTo('Visit home page.');
$I->amOnPage('/');
$I->amOnRoute('home');
$I->seeElement('body');
}

public function about(FunctionalTester $I)
{
$I->am('a guest');
$I->wantTo('Visit about page.');
$I->amOnPage('/about');
$I->amOnRoute('about');
$I->seeElement('body');
}

Expand Down
9 changes: 4 additions & 5 deletions tests/functional/Replies/ReplyCreationCept.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@

// Test Login Redirect
$I->am('a Phphub visitor');
$I->amOnPage('topics/' . $topic->id );
$I->amOnRoute('topics.show', $topic->id);

$I->fillField(['name' => 'body'], 'My first reply body.');
$I->click('#reply-create-submit');

$I->seeCurrentUrlEquals('/login-required');
$I->seeCurrentRouteIs('login-required');


// Test as a member
$I->signIn();
$I->am('as a Phphub member');

// Test Login Redirect
$I->amOnPage('topics/' . $topic->id );

$I->amOnRoute('topics.show', $topic->id);
$I->fillField(['name' => 'body'], 'My first reply body.');
$I->click('#reply-create-submit');

Expand Down
Loading

0 comments on commit 88022ac

Please sign in to comment.