root/events/phpframework/piece_framework/trunk/specs/Phwittr/Self/StatusUpdateSpec.php @ 14802

Revision 14802, 6.0 kB (checked in by kumatch, 5 years ago)

Reviewed.

  • Property svn:keywords set to Id Rev
Line 
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
4/*
5 * PHP versions 5
6 *
7 * @package    Phwittr_PieceFramework
8 * @copyright  2008 KUMAKURA Yousuke All rights reserved.
9 * @version    SVN: $Id$
10 * @since      File available since Release 0.1.0
11 */
12
13require_once dirname(__FILE__). '/../SpecCommon.php';
14require_once 'Phwittr/Self.php';
15
16// {{{ Describeログインユーザのステータス更新・削除
17
18/**
19 * StatusUpdateSpec - ログインユーザのステータス更新・削除に関するSpec
20 *
21 * @package    Phwittr_PieceFramework
22 * @copyright  2008 KUMAKURA Yousuke All rights reserved.
23 * @version    Release: @package_version@
24 * @since      Class available since Release 0.1.0
25 */
26class Describeログインユーザのステータス更新・削除 extends SpecCommon
27{
28
29    // {{{ properties
30
31    /**#@+
32     * @access public
33     */
34
35    /**#@-*/
36
37    /**#@+
38     * @access protected
39     */
40
41    /**#@-*/
42
43    /**#@+
44     * @access private
45     */
46
47    /**#@-*/
48
49    /**#@+
50     * @access public
51     */
52
53    public function beforeAll()
54    {
55        parent::beforeAll();
56
57        $this->_createUserRecord($this->_foo);
58        $this->_createUserRecord($this->_bar);
59        $this->_createUserRecord($this->_baz);
60
61        $mapper = Piece_ORM::getMapper('Users');
62        $this->_foo = $mapper->findByUserName($this->_foo->userName);
63        $this->_bar = $mapper->findByUserName($this->_bar->userName);
64        $this->_baz = $mapper->findByUserName($this->_baz->userName);
65
66        $this->_self = new Phwittr_Self($this->_foo->id);
67    }
68
69    public function after()
70    {
71        $mapper = Piece_ORM::getMapper('Statuses');
72        $mapper->executeQuery("truncate statuses");
73    }
74
75    public function itいま何をしているか発言すると新しいステータスが作られる()
76    {
77        $comment = 'Hello, World!';
78        $this->_self->update($comment);
79
80        $mapper = Piece_ORM::getMapper('Statuses');
81        $status = $mapper->findByUserId($this->_foo->id);
82
83        $this->spec($status->id)->should->be(1);
84        $this->spec($status->userId)->should->be($this->_foo->id);
85        $this->spec($status->replyUserId)->should->beNull();
86        $this->spec($status->comment)->should->be($comment);
87    }
88
89    public function it発言の先頭に「@ユーザ名」とつけるとそのユーザへのReplyとなるステータスが作られる()
90    {
91        // ユーザ名は@[0-9a-zA-Z_]{1,20}
92
93        $comment = '@bar Hello, World!';
94        $this->_self->update($comment);
95
96        $mapper = Piece_ORM::getMapper('Statuses');
97        $status = $mapper->findByUserId($this->_foo->id);
98
99        $this->spec($status->id)->should->be(1);
100        $this->spec($status->userId)->should->be($this->_foo->id);
101        $this->spec($status->replyUserId)->should->be($this->_bar->id);
102        $this->spec($status->comment)->should->be($comment);
103    }
104
105    public function it発言の文中の「@ユーザ名」はreplyとならないでステータスが作られる()
106    {
107        $comment = 'Hello, @bar World!';
108        $this->_self->update($comment);
109
110        $mapper = Piece_ORM::getMapper('Statuses');
111        $status = $mapper->findByUserId($this->_foo->id);
112
113        $this->spec($status->id)->should->be(1);
114        $this->spec($status->userId)->should->be($this->_foo->id);
115        $this->spec($status->replyUserId)->should->beNull();
116        $this->spec($status->comment)->should->be($comment);
117    }
118
119    public function it発言の文内に複数の「@ユーザ」があっても発言先頭の@だけがreplyとなるステータスが作られる()
120    {
121        $comment = '@bar @baz Hello, World!';
122        $this->_self->update($comment);
123
124        $mapper = Piece_ORM::getMapper('Statuses');
125        $status = $mapper->findByUserId($this->_foo->id);
126
127        $this->spec($status->id)->should->be(1);
128        $this->spec($status->userId)->should->be($this->_foo->id);
129        $this->spec($status->replyUserId)->should->be($this->_bar->id);
130        $this->spec($status->comment)->should->be($comment);
131    }
132
133    public function it自分の発言idを指定して削除をすると、そのステータスは消去される()
134    {
135        $this->_createStatusRecord($this->_foo->id, null, 'foo1');
136
137        $mapper = Piece_ORM::getMapper('Statuses');
138        $status = $mapper->findByUserId($this->_foo->id);
139
140        $this->spec($status->id)->should->be(1);
141
142        $this->_self->delete(1);
143        $status = $mapper->findByUserId($this->_foo->id);
144
145        $this->spec($status)->should->beNull();
146    }
147
148    public function it自分の発言ではないidを指定して削除しようとすると、ステータスは消去されず例外が発生する()
149    {
150        $this->_createStatusRecord($this->_bar->id, null, 'bar1');
151
152        $mapper = Piece_ORM::getMapper('Statuses');
153        $status = $mapper->findByUserId($this->_bar->id);
154
155        $this->spec($status->id)->should->be(1);
156
157        try {
158            $this->_self->delete(1);
159        } catch (Phwittr_Self_Exception $e) {
160            $status = $mapper->findByUserId($this->_bar->id);
161
162            $this->spec($status->id)->should->be(1);
163            return;
164        }
165
166        $this->fail();
167    }
168
169    public function it存在しない発言idを指定して削除しようとすると例外が発生する()
170    {
171        $mapper = Piece_ORM::getMapper('Statuses');
172        $statusList = $mapper->findAll();
173
174        $this->spec(count($statusList))->should->be(0);
175
176        try {
177            $this->_self->delete(1);
178        } catch (Phwittr_Self_Exception $e) {
179            $statusList = $mapper->findAll();
180
181            $this->spec(count($statusList))->should->be(0);
182            return;
183        }
184
185        $this->fail();
186    }
187
188    /**#@-*/
189
190    /**#@+
191     * @access protected
192     */
193
194    /**#@-*/
195
196    /**#@+
197     * @access private
198     */
199
200    /**#@-*/
201
202    // }}}
203}
204
205// }}}
206
207/*
208 * Local Variables:
209 * mode: php
210 * coding: utf-8
211 * tab-width: 4
212 * c-basic-offset: 4
213 * c-hanging-comment-ender-p: nil
214 * indent-tabs-mode: nil
215 * End:
216 */
217?>
Note: See TracBrowser for help on using the browser.