예제 #1
0
 protected function setUp()
 {
     // Setup some variables that will be used throughout this method.
     $title = 'Blog Bug 409 [' . Core::RandomHex(6) . ']';
     $this->blog = new BlogModel();
     $this->blog->set('title', $title);
     // Make sure the page model has been loaded into this model too.
     $page = $this->blog->getLink('Page');
     $page->set('title', $title);
     $this->blog->save();
     $bacon = new BaconIpsumGenerator();
     // Create an article with an invalid title.
     $this->article = new BlogArticleModel();
     $this->article->setFromArray(['blogid' => $this->blog->get('id'), 'title' => 'Sömé "ḮnvÁlid" & \'Bad\' T¹tle!¡', 'body' => $bacon->getParagraphsAsMarkup(), 'status' => 'published']);
     $this->article->save();
 }
예제 #2
0
	/**
	 * Page to test the UI of various Core elements
	 */
	public function testui(){
		$view = $this->getView();
		$request = $this->getPageRequest();

		if(!\Core\user()->checkAccess('g:admin')){
			// This test page is an admin-only utility.
			return View::ERROR_ACCESSDENIED;
		}

		$lorem = new BaconIpsumGenerator();

		$skins = [];
		$admindefault = null;
		foreach(ThemeHandler::GetTheme()->getSkins() as $dat){
			$skins[ $dat['file'] ] = $dat['title'];
			if($dat['admindefault']) $admindefault = $dat['file'];
		}

		if($request->getParameter('skin')){
			$skin = $request->getParameter('skin');
		}
		else{
			$skin = $admindefault;
		}

		$view->mastertemplate = $skin;
		$view->title = 'Test General UI/UX';
		$view->assign('lorem_p', $lorem->getParagraphsAsMarkup(3));
		$view->assign(
			'lis', [
				$lorem->getWord(3),
				$lorem->getWord(3),
				$lorem->getWord(3),
				$lorem->getWord(3),
				$lorem->getWord(3),
			]
		);
		$view->assign('skins', $skins);
		$view->assign('skin', $skin);
	}
예제 #3
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');
 }