/**
  * @group EricssonCommercialGroupInt
  */
 public function testFindAll()
 {
     $this->commercialGroupMapper->insert($this->commercialGroup);
     $this->assertNotNull($this->commercialGroup->getId());
     $commercialGroups = $this->commercialGroupMapper->findAll();
     $this->assertNotNull($commercialGroups);
     $this->assertGreaterThanOrEqual(1, $commercialGroups->getCount());
     $items = $commercialGroups->getItems();
     foreach ($items as $item) {
         $this->assertInstanceOf('\\Application\\Model\\CommercialGroupModel', $item);
     }
 }
 public function testUpdateAuthorizedAndRestrictedNumbers()
 {
     $this->commercialGroupMapper->insert($this->commercialGroup);
     $this->assertNotNull($this->commercialGroup->getId());
     $commGroup = $this->commercialGroupMapper->findOneById($this->commercialGroup->getId());
     $whiteList = $commGroup->getWhiteList();
     $whiteList[] = "984847766";
     $commGroup->setWhiteList($whiteList);
     $blackList = $commGroup->getBlackList();
     $blackList[] = "888474632";
     $commGroup->setBlackList($whiteList);
     $result = $this->commercialGroupMapper->update($commGroup);
     $this->assertNotNull($result);
     $this->assertEquals($this->commercialGroup->getId(), $result);
 }
 /**
  * Validate element value
  *
  * If a translation adapter is registered, any error messages will be
  * translated according to the current locale, using the given error code;
  * if no matching translation is found, the original message will be
  * utilized.
  *
  * Note: The *filtered* value is validated.
  *
  * @param  $data \Application\Model\CommercialGroupModel
  * @param  $context \Application\Model\CommercialGroupModel The original commercialGroup
  * @return boolean
  */
 public function isValid($data, $context = null, $removeNotPresentFields = false)
 {
     if (!$data instanceof CommercialGroupModel) {
         $this->_messages = array();
         $this->_messages[self::NOT_COMMERCIAL_GROUP] = $this->_messageTemplatesCommercialGroup[self::NOT_COMMERCIAL_GROUP];
         return false;
     }
     //check if is an update
     if ($data->getId()) {
         //check if the user have modified the service pack
         $cgMapper = CommercialGroupMapper::getInstance();
         $original = $cgMapper->findOneById($data->getId());
         if (!$original instanceof CommercialGroupModel) {
             throw new \Application\Exceptions\UnexpectedException("Commercial group Id doesn't exist for update operation");
         }
         if (!is_null($data->getServicePackId()) && $data->getServicePackId() !== $original->getServicePackId()) {
             if ($original->getSubscriberCount() !== 0) {
                 $this->_messages = array();
                 $this->_messages[self::COMMERCIAL_GROUP_HAVE_SUBSCRIPTIONS] = $this->_messageTemplatesCommercialGroup[self::COMMERCIAL_GROUP_HAVE_SUBSCRIPTIONS];
                 return false;
             }
         }
     }
     return parent::isValid($data, $context, $removeNotPresentFields);
 }
 /**
  * @param  string    $userId
  * @return UserModel
  */
 public static function find($userId)
 {
     return CommercialGroupMapper::getInstance()->findOneById($userId);
 }