/** * test add new message */ public function testAdd() { $feedModel = new application_models_feeds(); $currentDatetime = date('Y-m-d H:i:s'); $this->model->add($feedModel->find(1)->current(), 'testmessage no 1'); // error in feed set $this->assertEquals('1', $feedModel->find(1)->current()->error); // correct error message added $this->assertGreaterThan(0, $this->model->fetchAll()->count()); $result = $this->model->fetchAll($this->model->select()->order('id DESC'))->current(); $this->assertEquals($currentDatetime, $result->datetime); $this->assertEquals('testmessage no 1', $result->message); $this->assertEquals('1', $result->feed); }
/** * test handling of icons */ public function testIconhandling() { // load icon by favicon value $this->model->saveIcon($this->model->find(1)->current()); $this->assertEquals($this->model->find(1)->current()->icon, md5('http://rsslounge.aditu.de/favicon.ico') . '.ico'); // load icon by htmlurl page $this->model->saveIcon($this->model->find(2)->current()); $this->assertEquals($this->model->find(2)->current()->icon, md5('http://blog.aditu.de/wp-content/themes/blog.aditu.de/favicon.ico') . '.ico'); // use plugin icon (invalid url, no htmlurl) $this->model->saveIcon($this->model->find(3)->current()); $this->assertEquals($this->model->find(3)->current()->icon, 'plugins/rss/icon.ico'); // delete icon $this->model->deleteIcon($this->model->find(1)->current()); $this->assertFalse(file_exists(Zend_Registry::get('config')->favicons->path . md5('http://rsslounge.aditu.de/favicon.ico') . '.ico')); }
/** * updates a given feed (for executing via ajax call) * * @return void */ public function feedAction() { // timeout bigger than 0 = no feed refresh needed $updater = Zend_Controller_Action_HelperBroker::getStaticHelper('updater'); if ($updater->timeout() != 0) { $this->finishAction(); return; } // get and check feed $feedModel = new application_models_feeds(); $feeds = $feedModel->find($this->getRequest()->getParam('id')); if ($feeds->count() == 0) { $this->_helper->json(array('error' => $this->view->translate('No feed with given ID found'))); } // update feed (fetch new data from source) $feed = $feeds->current(); $result = $updater->feed($feed); // if necessary update icon $updateIcon = $feed->dirtyicon == 1; if ($updateIcon) { $feedModel->saveIcon($feed); } // create answer if (!is_numeric($result)) { $this->_helper->json(array('error' => $result)); } else { // return category and feed unread items $this->_helper->json(array('success' => true, 'icon' => $updateIcon, 'lastrefresh' => $result)); } }
/** * save feed * * @return void */ public function saveAction() { // get data $data = $this->getRequest()->getPost(); // get feed model for db access $feedModel = new application_models_feeds(); if (strlen(trim($data['id'])) == 0) { $new = true; } else { $new = false; } // validate and write/add feed if ($new) { $result = $feedModel->add($data); } else { $result = $feedModel->edit($data); } // error if (is_array($result)) { $this->_helper->json(array('success' => false, 'errors' => $result)); // success } else { // get new feed $newFeed = $feedModel->find($result)->current(); // update items of new feed if ($new) { $updater = Zend_Controller_Action_HelperBroker::getStaticHelper('updater'); $updater->feed($newFeed); // delete old icon (on edit feed) } else { $feedModel->deleteIcon($newFeed); } // save new icon $feedModel->saveIcon($newFeed); // set new priorities $newSettings = $this->resetPriorities(); // disable icon caching if user added a feed Zend_Registry::get('config')->cache->iconcaching = 0; // renew iconcache Zend_Controller_Action_HelperBroker::getStaticHelper('icon')->resetIconImage(); // build result $result = array('success' => true, 'feed' => array('id' => $newFeed->id, 'category' => $newFeed->category, 'position' => $newFeed->position, 'html' => $this->view->partial('feed/feed.' . Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->getViewSuffix(), $newFeed->toArray())), 'categories' => Zend_Controller_Action_HelperBroker::getStaticHelper('itemcounter')->unreadItemsCategories(), 'all' => Zend_Controller_Action_HelperBroker::getStaticHelper('itemcounter')->allItems(), 'settings' => $newSettings, 'feeds' => $feedModel->count(Zend_Registry::get('session')->currentPriorityStart, Zend_Registry::get('session')->currentPriorityEnd, Zend_Registry::get('session')->view)); $this->_helper->json($result); } }