Beispiel #1
0
 /**
  * Render the not found page if on frontend and http exception
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
         return;
     }
     $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
     if (!$content instanceof Content || empty($content->id)) {
         return;
     }
     $template = $this->templateChooser->record($content);
     $response = $this->render->render($template, $content->getTemplateContext());
     $event->setResponse($response);
 }
Beispiel #2
0
 protected function addSomeContent()
 {
     $app = $this->getApp();
     $app['request'] = Request::create('/');
     $app['config']->set('taxonomy/categories/options', ['news']);
     $prefillMock = new LoripsumMock();
     $app['prefill'] = $prefillMock;
     $storage = new Storage($app);
     $storage->prefill(['showcases', 'entries', 'pages']);
     // We also set some relations between showcases and entries
     $showcases = $storage->getContent('showcases');
     $randEntries = $storage->getContent('entries/random/2');
     foreach ($showcases as $show) {
         foreach ($randEntries as $key => $entry) {
             $show->setRelation('entries', $key);
             $storage->saveContent($show);
         }
     }
 }
 /**
  * Get choice values from Contenttype records
  *
  * @return array
  */
 private function getChoicesFromContenttypeRecords()
 {
     $key = $this->options['choices'];
     $params = explode('::', $key);
     if ($params === false || count($params) !== 4) {
         throw new \UnexpectedValueException("The configured Contenttype choice field '{$this->name}' has an invalid key string: '{$key}'");
     }
     /** @var $records Bolt\Content[] */
     $records = $this->storage->getContent($params[1], $this->getQueryParameters());
     $choices = array();
     foreach ($records as $record) {
         $choices[$record->get($params[3])] = $record->get($params[2]);
     }
     return $choices;
 }
Beispiel #4
0
 public function testGetNextChangeLogEntry()
 {
     $app = $this->getApp();
     $app['config']->set('general/changelog/enabled', true);
     $storage = new Storage($app);
     // To generate an extra changelog we fetch and save a content item
     // For now we need to mock the request object.
     $app['request'] = Request::create('/');
     $content = $storage->getContent('pages/1');
     $this->assertInstanceOf('\\Bolt\\Content', $content);
     $content->setValues(['status' => 'draft', 'ownerid' => 99]);
     $storage->saveContent($content, 'Test Suite Update');
     $content->setValues(['status' => 'published', 'ownerid' => 1]);
     $storage->saveContent($content, 'Test Suite Update');
     $log = $this->getLogChangeRepository()->getChangeLogEntry('pages', 1, 1, '>');
     $this->assertAttributeEquals(1, 'contentid', $log);
 }
Beispiel #5
0
 public function testCurrent()
 {
     // Setup the db so we have a predictable content url to test
     $app = $this->getApp();
     $this->addDefaultUser($app);
     $storage = new Storage($app);
     $content = $storage->getEmptyContent('showcases');
     $content->setValues(['title' => 'New Showcase', 'slug' => 'new-showcase', 'status' => 'published']);
     $storage->saveContent($content);
     $phpunit = $this;
     $handlers = $this->getTwigHandlers($app);
     $twig = new TwigExtension($app, $handlers, false);
     $storage = new Storage($app);
     // Get the content object and create a routed request
     $request = Request::create('/showcase/new-showcase');
     $app->before(function ($request, $app) use($phpunit, $twig, $storage) {
         $fetched = $storage->getContent('showcases/1');
         $phpunit->assertTrue($twig->current($fetched));
     });
     $app->handle($request);
     // Test works on custom homepage
     $app['config']->set('general/homepage', 'showcase/new-showcase');
     $request = Request::create('/');
     $app->before(function ($request, $app) use($phpunit, $twig, $storage) {
         $fetched = $storage->getContent('showcases/1');
         $phpunit->assertTrue($twig->current($fetched));
     });
     $app->handle($request);
     // Delete the content so we're back to a clean database
     $storage->deleteContent('showcases', 1);
 }
Beispiel #6
0
 public function testUpdateSingleValue()
 {
     $app = $this->getApp();
     $app['request'] = Request::create('/');
     $storage = new Storage($app);
     $fetch1 = $storage->getContent('showcases/2');
     $this->assertEquals(1, $fetch1->get('ownerid'));
     $result = $storage->updateSingleValue('showcases', 2, 'ownerid', '10');
     $this->assertEquals(2, $result);
     $fetch2 = $storage->getContent('showcases/2');
     $this->assertEquals('10', $fetch2->get('ownerid'));
     // Test invalid column fails
     $shouldError = $storage->updateSingleValue('showcases', 2, 'nonexistent', '10');
     $this->assertFalse($shouldError);
 }
Beispiel #7
0
 public function testListContent()
 {
     $app = $this->getApp();
     $phpunit = $this;
     $handlers = $this->getTwigHandlers($app);
     $twig = new TwigExtension($app, $handlers, false);
     $storage = new Storage($app);
     // First up we seed the database with a showcase and some related entries.
     $content = $storage->getEmptyContent('entries');
     $content->setValues(['title' => 'New Entry 1', 'slug' => 'new-entry-1', 'status' => 'published']);
     $storage->saveContent($content);
     $content = $storage->getEmptyContent('entries');
     $content->setValues(['title' => 'New Entry 2', 'slug' => 'new-entry-2', 'status' => 'published']);
     $storage->saveContent($content);
     $content = $storage->getEmptyContent('entries');
     $content->setValues(['title' => 'New Entry 3', 'slug' => 'new-entry-3', 'status' => 'published']);
     $storage->saveContent($content);
     $content = $storage->getEmptyContent('showcases');
     $content->setValues(['title' => 'New Showcase', 'slug' => 'new-showcase', 'status' => 'published']);
     $content->setRelation('entries', 1);
     $content->setRelation('entries', 2);
     $storage->saveContent($content);
     $request = Request::create('/');
     $app->before(function ($request, $app) use($phpunit, $twig, $storage) {
         $fetched = $storage->getContent('showcases/latest/1', ['returnsingle' => true]);
         $content = $twig->listContent('entries', ['order' => 'title'], $fetched);
         $phpunit->assertEquals(2, count($content));
         $phpunit->assertFalse($content[2]['selected']);
     });
     $app->handle($request);
     // Clean up test database
     $storage->deleteContent('entries', 1);
     $storage->deleteContent('entries', 2);
     $storage->deleteContent('entries', 3);
     $storage->deleteContent('showcases', 1);
 }