Example #1
0
 public function testDeleteContent()
 {
     $app = $this->getApp();
     $app['request'] = Request::create('/');
     $storage = new Storage($app);
     // Test delete fails on missing params
     $this->setExpectedException('Bolt\\Exception\\StorageException', 'Contenttype is required for deleteContent');
     $this->assertFalse($storage->deleteContent('', 999));
     $content = $storage->getContent('showcases/1');
     // Test the delete events are triggered
     $delete = 0;
     $listener = function () use(&$delete) {
         $delete++;
     };
     $app['dispatcher']->addListener(StorageEvents::PRE_DELETE, $listener);
     $app['dispatcher']->addListener(StorageEvents::POST_DELETE, $listener);
     $storage->deleteContent(['slug' => 'showcases'], 1);
     $this->assertFalse($storage->getContent('showcases/1'));
     $this->assertEquals(2, $delete);
 }
Example #2
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);
 }
Example #3
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);
 }