| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | require_once dirname(__FILE__). '/../SpecCommon.php'; |
|---|
| 14 | require_once 'Phwittr/Self.php'; |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | class Describeログインユーザのステータス更新・削除 extends SpecCommon |
|---|
| 27 | { |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | ?> |
|---|