public function testlogStoreEventFailedStorage()
 {
     $logger = $this->getMock('QuickTag\\Log\\LogInterface');
     $sub = new LogSubscriber($logger);
     $tag = new StoredTag();
     $tag->setTagId(1);
     $tag->setTitle('aaaa');
     $logger->expects($this->once())->method('info')->with('QuickTag:: Failed to stored Tag at ID 1 with title aaaa', array());
     # run the log handler
     $sub->logStoreEvent(new TagStoreEvent(false, $tag));
 }
示例#2
0
 /**
  *  Creates a Tag
  *
  *  @access public
  *  @return string a json response
  */
 public function postTagAction(Application $app, Request $req)
 {
     $response = array('msg' => null, 'result' => null);
     # Validate Params
     $errors = $this->getValidator()->validateValue(array('tagTitle' => $req->get('tagTitle'), 'tagWeight' => $req->get('tagWeight')), $this->getValidationRules());
     if (count($errors) > 0) {
         $this->getContainer()->abort(400, $this->serializeValidationErrors($errors));
     }
     $tag = new StoredTag();
     $tag->setTitle((string) $req->get('tagTitle'));
     $tag->setWeight((double) $req->get('tagWeight'));
     $tag->setTagCreated(new DateTime());
     $response['result'] = $this->getTagLibrary()->storeTag($tag);
     $response['msg'] = sprintf('Stored new tag with title %s tag at id %s', $tag->getTitle(), $tag->getTagId());
     return $this->response($response, 200);
 }
示例#3
0
 /**
  * Convert data array into entity
  *
  * @return QuickTag\Model\StoredTag
  * @param array $data
  * @access public
  */
 public function build($data)
 {
     $object = new StoredTag();
     if ($data['tag_user_context'] !== null) {
         $object->setUserContext($data['tag_user_context']);
     }
     if ($data['tag_weight'] !== null) {
         $object->setWeight($data['tag_weight']);
     }
     $object->setTagId($data['tag_id']);
     $object->setTagCreated($data['tag_date_created']);
     $object->setTitle($data['tag_title']);
     return $object;
 }
示例#4
0
 public function testEntityDemolish()
 {
     $tag_id = 1;
     $tag_user_context = 3;
     $tag_date_created = new DateTime();
     $tag_weight = 3.56;
     $tag_title = 'finance';
     $data = array('tag_id' => $tag_id, 'tag_user_context' => $tag_user_context, 'tag_date_created' => $tag_date_created, 'tag_weight' => $tag_weight, 'tag_title' => $tag_title);
     $builder = new TagBuilder();
     $entity = new StoredTag();
     $entity->setTagId($tag_id);
     $entity->setUserContext($tag_user_context);
     $entity->setTagCreated($tag_date_created);
     $entity->setWeight($tag_weight);
     $entity->setTitle($tag_title);
     $this->assertEquals($data, $builder->demolish($entity));
 }
示例#5
0
 /**
  *  @expectedException QuickTag\QuickTagException
  *  @expectedExceptionMessage SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tag_title' cannot be null
  */
 public function testSaveWithError()
 {
     $gateway = $this->getTableGateway();
     $event = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $mapper = new TagMapper($event, $gateway);
     $tag = new StoredTag();
     $tag->setUserContext(1);
     $tag->setWeight(1);
     $result = $mapper->save($tag);
 }
示例#6
0
 public function toArray(StoredTag $entity)
 {
     return array('tagId' => $entity->getTagId(), 'tagCreated' => $entity->getTagCreated(), 'tagTitle' => $entity->getTitle(), 'tagWeight' => $entity->getWeight(), 'tagUserContext' => $entity->getUserContext());
 }
示例#7
0
 /**
  *  Remove a tag
  *
  *  @access public
  *  @return boolean the result true if removed
  *  @param QuickTag\Model\StoredTag $tag
  *  @throws QuickTag\QuickTagException if database operation fails
  */
 public function delete(StoredTag $tag)
 {
     $result = null;
     if ($tag->getTagId() === null) {
         throw new QuickTagException('Given tag does not have a database id assigned can not delete');
     } else {
         $result = $this->gateway->deleteQuery()->start()->filterById($tag->getTagId())->end()->delete();
         # reset the tag id
         if ($result) {
             $tag->setTagId(0);
         }
     }
     return $result;
 }