Exemplo n.º 1
0
 /**
  * Kernel request listener callback.
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $contenttypes = $this->config->get('contenttypes', array());
     foreach ($contenttypes as $contenttype) {
         $contenttype = $this->storage->getContentType($contenttype['slug']);
         // Check if we need to 'publish' any 'timed' records, or 'depublish' any expired records.
         $this->storage->publishTimedRecords($contenttype);
         $this->storage->depublishExpiredRecords($contenttype);
     }
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
 protected function addSomeContent()
 {
     $app = $this->getApp();
     $this->getService('config')->set('taxonomy/categories/options', ['news']);
     $prefillMock = new LoripsumMock();
     $this->setService('prefill', $prefillMock);
     $storage = new Storage($app);
     $storage->preFill(['showcases']);
 }
Exemplo n.º 8
0
 protected function addSomeContent()
 {
     $app = $this->getApp();
     $this->addDefaultUser($app);
     $app['config']->set('taxonomy/categories/options', ['news']);
     $prefillMock = new LoripsumMock();
     $app['prefill'] = $prefillMock;
     $storage = new Storage($app);
     $storage->prefill(['showcases', 'pages']);
 }
Exemplo n.º 9
0
 protected function executeGetContentQueries($decoded)
 {
     $this->queries[] = $decoded;
     return parent::executeGetContentQueries($decoded);
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
0
 protected function addSomeContent()
 {
     $app = $this->getApp();
     $app['config']->set('taxonomy/categories/options', array('news'));
     $prefillMock = new LoripsumMock();
     $app['prefill'] = $prefillMock;
     $storage = new Storage($app);
     $storage->prefill(array('showcases'));
 }
Exemplo n.º 12
0
 public function __construct(Bolt\Application $app)
 {
     parent::__construct($app);
     $this->app = $app;
 }