/** * Filters events that are not user-specific or are from users with * specified modes. * * @param \Phergie\Irc\Event\EventInterface $event * @return boolean|null TRUE if the event originated from a user with a matching mode * associated with this filter, FALSE if the event originated from a user * without a matching mode, or NULL if the event did not originate from a user. */ public function filter(EventInterface $event) { if (!$event instanceof UserEventInterface) { return null; } $channels = $this->getChannels($event); $nick = $event->getNick(); if (empty($channels) || $nick === null) { return null; } $connection = $event->getConnection(); foreach ($channels as $channel) { $userModes = $this->userMode->getUserModes($connection, $channel, $nick); $commonModes = array_intersect($userModes, $this->modes); if ($commonModes) { return true; } } return false; }
/** * Tests loadUserModes() with an overridden prefix. */ public function testLoadUserModesWithOverriddenPrefix() { $channel = '#channel'; $params = array('=', $channel, '$unsupported', 'iterable' => array('$unsupported'), 'tail' => '$unsupported'); $event = $this->getMockEvent(); $connection = $this->getMockConnection(); Phake::when($event)->getParams()->thenReturn($params); Phake::when($event)->getConnection()->thenReturn($connection); $plugin = new Plugin(array('prefixes' => array('$' => 'd'))); $plugin->setLogger($this->logger); $plugin->loadUserModes($event, $this->queue); $this->assertSame(array('d'), $plugin->getUserModes($connection, $channel, 'unsupported')); }