Exemple #1
0
 /**
  * Create a new blog
  */
 public function testCreateBlog()
 {
     // Setup some variables that will be used throughout this method.
     $random = Core::RandomHex(6);
     $title = 'New Test Blog ' . Core::RandomHex(6);
     // Update the current user so it has admin access.
     \Core\user()->set('admin', true);
     $request = new PageRequest('/blog/create');
     // Run the method, it should give me a 200 since the user is now an admin.
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error, 'Checking that admin users can create blogs');
     // 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 create controller');
     // Set some variables on the form
     $form->getElement('page[title]')->set('value', $title);
     $form->getElement('page[rewriteurl]')->set('value', '/blogtest-' . $random);
     // 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));
     $this->assertStringStartsWith('/blog/view/', $formsubmission, 'Checking that form creation was successful');
     self::$TestBlogID = substr($formsubmission, 11);
     // This will be just the number at the end of the baseurl, ie: the id.
     // Make sure that this blog exists!
     $blog = new BlogModel(self::$TestBlogID);
     $this->assertTrue($blog->exists(), 'Checking that blog model creation was successful');
     // And make sure that the page was created.
     $page = new PageModel('/blog/view/' . self::$TestBlogID);
     $this->assertTrue($page->exists(), 'Checking that blog page creation was successful');
     // Go to the page and make sure that it loads up!
     $request = new PageRequest('/blog/view/' . self::$TestBlogID);
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error, 'Checking that public blog page exists');
     $html = $view->fetch();
     $this->assertContains($title, $html, 'Checking that the public blog page contains the correct title');
 }
 /**
  * Shortcut for unpublishing an article.
  */
 public function article_unpublish()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     $blog = new BlogModel($request->getParameter(0));
     if (!$blog->exists()) {
         return View::ERROR_NOTFOUND;
     }
     $manager = \Core\user()->checkAccess('p:/blog/manage_all');
     $editor = \Core\user()->checkAccess($blog->get('manage_articles_permission ')) || $manager;
     if (!$editor) {
         return View::ERROR_ACCESSDENIED;
     }
     $article = new BlogArticleModel($request->getParameter(1));
     if (!$article->exists()) {
         return View::ERROR_NOTFOUND;
     }
     if ($article->get('blogid') != $blog->get('id')) {
         return View::ERROR_NOTFOUND;
     }
     if (!$request->isPost()) {
         return View::ERROR_BADREQUEST;
     }
     // Is this article already published?
     if ($article->get('status') == 'draft') {
         Core::SetMessage('Article is already in draft mode!', 'error');
         \Core\go_back();
     }
     $article->set('status', 'draft');
     $article->save();
     Core::SetMessage('Unpublished article successfully!', 'success');
     \Core\go_back();
 }