Exemplo n.º 1
0
 public function testSaveContent()
 {
     $app = $this->getApp();
     $app['request'] = Request::create('/');
     $storage = new Storage($app);
     // Test missing contenttype handled
     $content = new Content($app);
     $this->setExpectedException('Bolt\\Exception\\StorageException', 'Contenttype is required for saveContent');
     $this->assertFalse($storage->saveContent($content));
     // Test dispatcher is called pre-save and post-save
     $content = $storage->getContent('showcases/1');
     $presave = 0;
     $postsave = 0;
     $listener = function () use(&$presave) {
         $presave++;
     };
     $listener2 = function () use(&$postsave) {
         $postsave++;
     };
     $app['dispatcher']->addListener(StorageEvents::PRE_SAVE, $listener);
     $app['dispatcher']->addListener(StorageEvents::POST_SAVE, $listener2);
     $storage->saveContent($content);
     $this->assertEquals(1, $presave);
     $this->assertEquals(1, $postsave);
 }
Exemplo n.º 2
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.º 3
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.º 4
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.º 5
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);
 }