public function testSave()
 {
     //  test save subscriber
     $subscriber = new Subscriber();
     $subscriber->user_id = 1;
     $this->assertEquals(true, $subscriber->save(), 'Can not save subscriber');
     $channel = new Channel();
     $channel->name = 'test';
     $this->assertEquals(true, $channel->save(), 'Can not save channel');
 }
Пример #2
0
 /**
  * @return Channel
  */
 public function getChannel()
 {
     if (isset($this->_channel)) {
         return $this->_channel;
     }
     $this->_channel = Channel::model()->findByAttributes(array('name' => $this->getChannelName()));
     return $this->_channel;
 }
Пример #3
0
 public function testDelete()
 {
     $channel = new Channel();
     $channel->attributes = array('name' => 'test6' . time(), 'subscriber_source' => Channel::SOURCE_PHP, 'event_source' => Channel::SOURCE_PHP);
     $this->assertEquals(true, $channel->getIsNewRecord());
     $this->assertEquals(true, $channel->save());
     //  try find channel
     $channel = Channel::model()->findByPk($channel->id);
     $this->assertInstanceOf('YiiNodeSocket\\Models\\Channel', $channel);
     //  try delete
     $this->assertEquals(true, $channel->delete());
     //  try find again
     $channel = Channel::model()->findByPk($channel->id);
     //  should be null
     $this->assertNull($channel);
 }
 /**
  * @param Subscriber $subscriber
  * @param bool       $refresh
  *
  * @return AModel[]
  */
 public function getChannels(Subscriber $subscriber, $refresh = false)
 {
     if ($subscriber->getIsNewRecord()) {
         return array();
     }
     if (array_key_exists($subscriber->id, self::$_subscriberChannels) && !$refresh) {
         return self::$_subscriberChannels[$subscriber->id];
     }
     $links = $this->findAllByAttributes(array('subscriber_id' => $subscriber->id));
     $channelId = array();
     foreach ($links as $link) {
         $channelId[] = $link->id;
     }
     $channels = Channel::model()->findAllByPk($channelId);
     foreach ($channels as $channel) {
         self::_addToCache($channel, $subscriber);
     }
     return $channels;
 }