Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

#6 handleNotice emits 'nickserv.confirmed' when it receives a relevant n... #8

Merged
merged 1 commit into from
Apr 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}
}

/**
Expand Down Expand Up @@ -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]);
}
}

Expand Down
14 changes: 11 additions & 3 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
}

Expand All @@ -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]);
}

/**
Expand Down