diff --git a/src/Plugin.php b/src/Plugin.php index 959b7a8..3b6035c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -100,6 +100,12 @@ public function handleNotice(UserEvent $event, Queue $queue) if (preg_match($pattern, $message)) { return $queue->ircNick($nick); } + + // Emit event when user's identity has been confirmed + $pattern = '/You are now identified/'; + if (preg_match($pattern, $message)) { + $this->getEventEmitter()->emit('nickserv.confirmed', [$event->getConnection()]); + } } /** @@ -129,7 +135,6 @@ public function handleNick(UserEvent $event, Queue $queue) if (strcasecmp($event->getNick(), $connection->getNickname()) === 0) { $params = $event->getParams(); $connection->setNickname($params['nickname']); - $this->getEventEmitter()->emit('nickserv.nick', [$connection]); } } diff --git a/tests/PluginTest.php b/tests/PluginTest.php index 47c5f49..f66e422 100644 --- a/tests/PluginTest.php +++ b/tests/PluginTest.php @@ -88,11 +88,21 @@ public function testHandleNoticeFromNonNickServUser() */ public function testHandleNoticeWithIrrelevantNoticeFromNickServ() { - Phake::when($this->event)->getParams()->thenReturn(array('text' => 'You are now identified for Phergie')); + Phake::when($this->event)->getParams()->thenReturn(['text' => 'You are already logged in as Phergie']); Phake::verifyNoFurtherInteraction($this->queue); $this->plugin->handleNotice($this->event, $this->queue); } + /** + * Tests that identity confirmation notices from the NickServ emit an event. + */ + public function testHandleNoticeWithIdentityConfirmation() + { + Phake::when($this->event)->getParams()->thenReturn(['text' => 'You are now identified for Phergie']); + $this->plugin->handleNotice($this->event, $this->queue); + Phake::verify($this->emitter)->emit('nickserv.confirmed', [$this->connection]); + } + /** * Tests that authentication requests are handled. */ @@ -140,7 +150,6 @@ public function testHandleQuitWithRelevantEvent() public function testHandleNickWithIrrelevantEvent() { Phake::verifyNoFurtherInteraction($this->queue); - Phake::verifyNoFurtherInteraction($this->emitter); $this->plugin->handleNick($this->event, $this->queue); } @@ -154,7 +163,6 @@ public function testHandleNickWithRelevantEvent() Phake::when($this->event)->getParams()->thenReturn(array('nickname' => 'Phergie')); $this->plugin->handleNick($this->event, $this->queue); Phake::verify($this->connection)->setNickname('Phergie'); - Phake::verify($this->emitter)->emit('nickserv.nick', [$this->connection]); } /**