示例#1
0
 /**
  * Test that I can load the ATOM page and that it returns valid XML.
  * The XMLLoader will take care of the validation, since it should be a valid document anyway.
  */
 public function testATOMPage()
 {
     // Get the RSS feed and download it to a local file.
     $rewriteurl = $this->blog->get('rewriteurl');
     $this->assertNotEmpty($rewriteurl);
     // Go to the page and make sure that it loads up!
     $request = new PageRequest($rewriteurl . '.atom');
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error);
     $markup = $view->fetch();
     $this->assertNotEmpty($markup);
     // DEVELOPMENT DEBUG
     //echo $markup; // DEBUG //
     $xml = new XMLLoader();
     $xml->setRootName('feed');
     // If it's invalid markup, this load will throw an error, causing phpunit to return an error :)
     // If the bug is fixed, this will not throw any errors.
     $xml->loadFromString($markup);
     $parsedmarkup = $xml->asMinifiedXML();
     $this->assertNotEmpty($parsedmarkup);
 }
示例#2
0
 /**
  * Test the creation of a blog article based off the newly created blog
  *
  * @depends testCreateBlog
  */
 public function testCreateBlogArticle()
 {
     // Update the current user so it has admin access.
     \Core\user()->set('admin', true);
     // Setup some variables that will be used throughout this method.
     $title = 'New Test Blog Article';
     $randomsnippet = 'Random-Snippet-' . Core::RandomHex(10);
     $lorem = new BaconIpsumGenerator();
     $body = $lorem->getParagraph(1);
     // Tack on the random snipped I'll be looking for.
     $body .= $lorem->getParagraphsAsMarkup(8, $randomsnippet);
     $blog = new BlogModel(self::$TestBlogID);
     $request = new PageRequest('/blog/article/create/' . self::$TestBlogID);
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error, 'Checking that article creation returns a valid page');
     // The returned data should have a "form" available.  This is the actual creation form.
     /** @var $form Form */
     $form = $view->getVariable('form');
     $this->assertInstanceOf('Form', $form, 'Checking that the form is set from the blog article create controller');
     // Set some variables on the form
     $form->getElement('page[title]')->set('value', $title);
     $form->getElement('page[rewriteurl]')->set('value', $blog->get('rewriteurl') . '/' . \Core\str_to_url($title));
     $form->getElement('model[image]')->set('value', 'public/blog/blog-test-image.png');
     $form->getElement('model[body]')->set('value', $body);
     // Copy in the image
     $src = \Core\Filestore\Factory::File(ROOT_PDIR . 'components/blog/tests/blog-test-image.png');
     /** @var $dest \Core\Filestore\File */
     $dest = \Core\Filestore\Factory::File('public/blog/blog-test-image.png');
     $src->copyTo($dest, true);
     // make sure that it exists
     $this->assertTrue($dest->exists(), 'Checking that files can be copied into the public filestore');
     // And submit this form to the handler.
     // On a successful submission, it should be simply the URL of the blog.
     $formsubmission = call_user_func_array($form->get('callsmethod'), array($form));
     if ($formsubmission === false) {
         throw new Exception(implode("\n", $form->getErrors()));
     }
     // Go to the parent listing page and find this entry.
     $request = new PageRequest($blog->get('rewriteurl'));
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error);
     $html = $view->fetch();
     $this->assertContains($title, $html);
     $this->assertContains('itemtype="http://schema.org/BlogPosting"', $html);
     preg_match_all('#<div[^>]*itemtype="http://schema.org/BlogPosting"[^>]*>.*<a[^>]*href="(.*)"[^>]*>(.*)</a>#msU', $html, $matches);
     // Title should now have three keys, with at least one value each.
     $this->assertNotEmpty($matches[1]);
     $this->assertNotEmpty($matches[2]);
     // This node contains the URL.
     $foundurl = $matches[1][0];
     $foundtitle = trim($matches[2][0]);
     // Make sure the url contains the site url.
     $this->assertStringStartsWith(ROOT_URL, $foundurl);
     // And trim it off.  This is because PageRequest expects that the url is already trimmed.
     $foundurl = '/' . substr($foundurl, strlen(ROOT_URL));
     $this->assertEquals($title, $foundtitle);
     //$this->assertStringStartsWith('/blog/article/view/', $formsubmission, 'Checking that blog article creation was successful');
     // Go to the page and make sure that it loads up!
     $request = new PageRequest($foundurl);
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error, 'Checking that public blog article exists');
     $html = $view->fetch();
     $this->assertContains($title, $html, 'Checking that the public blog article page contains the correct title');
     $this->assertContains($randomsnippet, $html, 'Checking that the public blog article page contains the correct body');
     $this->assertContains('blog-test-image', $html, 'Checking that the public blog article page contains the correct image');
 }
示例#3
0
 private function _viewBlogArticle(BlogModel $blog, BlogArticleModel $article)
 {
     $view = $this->getView();
     /** @var $page PageModel */
     $page = $article->getLink('Page');
     //$articles = $blog->getLink('BlogArticle');
     $manager = \Core\user()->checkAccess('p:/blog/manage_all');
     $editor = \Core\user()->checkAccess($blog->get('manage_articles_permission ')) || $manager;
     $author = UserModel::Construct($article->get('authorid'));
     //$authorid = $author->get('id');
     //var_dump($page->getMeta('keywords')); die();
     if (!$article->isPublished()) {
         // Is it actually not published, or just marked for a future publish date?
         if ($article->get('status') == 'published') {
             $publishdate = new CoreDateTime($article->get('published'));
             Core::SetMessage('Article is set to be published on ' . $publishdate->getFormatted('F jS, Y \\a\\t h:ia'), 'info');
         } else {
             Core::SetMessage('Article not published yet!', 'info');
         }
     }
     //$view->templatename = $page->get('page_template') ? $page->get('page_template') : 'pages/blog/article_view.tpl';
     $view->templatename = 'pages/blog/article_view.tpl';
     //$view->addBreadcrumb($blog->get('title'), $blog->get('rewriteurl'));
     $view->title = $article->get('title');
     $view->meta['title'] = $article->get('title');
     $view->updated = $article->get('updated');
     $view->canonicalurl = \Core\resolve_link($article->get('rewriteurl'));
     $view->meta['og:type'] = 'article';
     if ($article->get('image')) {
         $image = \Core\Filestore\Factory::File($article->get('image'));
         $view->meta['og:image'] = $image->getPreviewURL('200x200');
     }
     //if($author){
     //	/** @var $author User */
     //	//$view->meta['author'] = $author->getDisplayName();
     //	$view->meta['author'] = $author;
     //}
     $view->meta['description'] = $article->getTeaser();
     $view->assign('author', $author->exists() ? $author : null);
     $view->assign('article', $article);
     $view->assign('body', \Core\parse_html($article->get('body')));
     if ($editor) {
         $view->addControl('Edit Article', '/blog/article/update/' . $article->get('id'), 'edit');
         if ($article->get('status') == 'draft') {
             $view->addControl(['title' => 'Publish Article', 'link' => '/blog/article/publish/' . $blog->get('id') . '/' . $article->get('id'), 'icon' => 'arrow-up', 'confirm' => 'Publish article?']);
         }
         $view->addControl(array('title' => 'Delete Article', 'link' => '/blog/article/delete/' . $article->get('id'), 'icon' => 'remove', 'confirm' => 'Remove blog article?'));
     }
     // Add the extra view types for this page
     $view->addHead('<link rel="alternate" type="application/atom+xml" title="' . $page->get('title') . ' Atom Feed" href="' . \Core\resolve_link($blog->get('baseurl')) . '.atom"/>');
     $view->addHead('<link rel="alternate" type="application/rss+xml" title="' . $page->get('title') . ' RSS Feed" href="' . \Core\resolve_link($blog->get('baseurl')) . '.rss"/>');
     $view->addControl('RSS Feed', \Core\resolve_link($blog->get('baseurl')) . '.rss', 'rss');
 }