Пример #1
0
 public function testNewsAdminCreateEditAndDeleteArticle()
 {
     /* Assertions:
      * New article appears in news index
      * Index has link to edit article
      * Index has link to delete article
      * New article has ID
      * Changes to article get saved
      * Article can be deleted
      */
     $title = 'Integration Test ' . time();
     $form = $this->first('form[action^="' . TYPEF_WEB_DIR . '/admin/news/add"]');
     $form->first('input[name="title"]')->setValue($title);
     $form->first('input[name="author"]')->setValue('the test case');
     $form->first('textarea[name="article"]')->setValue('<p>My article!</p>');
     $form->submit();
     $news = new Model_News_Article();
     $news->where('title = ?', $title);
     $article = $news->getFirst();
     $this->assertTrue($article->exists(), 'Posted article not found in database');
     if ($article->exists()) {
         $this->get(TYPEF_WEB_DIR . '/admin/news');
         $newsid = $article['newsid'];
         $links = $this->select('a[href*="newsid=' . $article['newsid'] . '"]');
         $editLink = false;
         $deleteLink = false;
         foreach ($links as $link) {
             if ($editLink && $deleteLink) {
                 break;
             }
             if (strpos($link['href'], TYPEF_WEB_DIR . '/admin/news/edit') !== false) {
                 $editLink = $link['href'];
             } else {
                 if (strpos($link['href'], '/admin/news/delete') !== false) {
                     $deleteLink = true;
                 }
             }
         }
         $this->assertTrue($editLink, 'No link to edit article.');
         $this->assertTrue($deleteLink, 'No link to delete article.');
         $this->get($editLink);
         $form = $this->first('form[action="' . TYPEF_WEB_DIR . '/admin/news/edit"]');
         $form->first('textarea[name="article"]')->setValue('<p>My modified article!</p>');
         $form->submit();
         $this->get($editLink);
         $this->assertText('My modified article!', "Edited article was not saved.");
         $this->post(TYPEF_WEB_DIR . '/admin/news/delete', array('newsid' => $newsid));
         $this->get(TYPEF_WEB_DIR . '/admin/news');
         $this->assertNoText($title, 'Article could not be deleted.');
     }
     /*$this->get(TYPEF_WEB_DIR . '/admin/news');
     		if ($this->assertText($title, 'New article missing from index')) {
     			//$links = $this->first('td.toolbar')->select('a');
     			//$links = $this->select('a[href')
     			$newsid = null;
     			$editLink = false;
     			$deleteLink = false;
     			foreach ($links as $link) {
     				if ($editLink && $deleteLink) break;
     				if (strpos($link['href'], TYPEF_WEB_DIR . '/admin/news/edit') !== false) {
     					$editLink = "{$link['href']}";
     					if (preg_match('/newsid=([0-9]*)/', "{$link['href']}", $matches)) {
     						$newsid = $matches[1];
     					}
     				} else if (strpos($link['href'], 'delete') !== false) {
     					$deleteLink = true;
     				}
     			}
     			$this->assertTrue($editLink, 'No link to edit article.');
     			$this->assertTrue($deleteLink, 'No link to delete article.');
     			$this->assertTrue($newsid, 'Article does not have an ID.');
     			if ($newsid) {
     				$this->get($editLink);
     				$form = $this->first('form[action="' . TYPEF_WEB_DIR . '/admin/news/edit"]');
     				$form->first('textarea[name="article"]')->setValue('<p>My modified article!</p>');
     				$form->submit();
     				$this->get($editLink);
     				$this->assertText('My modified article!', "Edited article was not saved.");
     				$this->post(TYPEF_WEB_DIR . '/admin/news/delete', array('newsid' => $newsid));
     				$this->get(TYPEF_WEB_DIR . '/admin/news');
     				$this->assertNoText($title, 'Article could not be deleted.');
     			}
     		}*/
 }
Пример #2
0
if ($path) {
    // Get the article by encoded title
    $articles->where('encodedtitle = ?', $path);
} else {
    // Get the article by news ID if possible
    if (isset($_REQUEST['newsid'])) {
        $articles->where('newsid = ?', $_REQUEST['newsid']);
        $redirect = true;
    } else {
        Typeframe::Redirect('No news article was specified.', $typef_app_dir, 1, false);
        return;
    }
}
if (isset($settings['categoryid']) && is_array($settings['categoryid']) && !in_array(0, $settings['categoryid'])) {
    $articles->where('categoryid IN ?', $settings['categoryid']);
}
$articles->where('pubdate <= ?', Typeframe::Now());
$articles->where('expdate = ? OR expdate > ? OR expdate IS NULL', '0000-00-00 00:00:00', Typeframe::Now());
$articles->where('status = ?', 'published');
$article = $articles->getFirst();
if (!$article->exists()) {
    http_response_code(404);
    Typeframe::Redirect('Invalid article specified.', $typef_app_dir, 1, false);
    return;
}
if ($redirect) {
    Typeframe::Redirect('Redirecting to article...', $typef_app_dir . '/' . $article['encodedtitle']);
    return;
}
Plugin_Breadcrumbs::Add($article['title']);
$pm->setVariable('news', $article);