public function testgetValues() { $app = $this->getApp(); $content = new Content($app, 'pages'); $content->setValue('title', 'Test Page'); $content->setValue('image', ['file' => 'image1.jpg', 'title' => 'Test image']); $values = $content->getValues(true); $this->assertEquals('Test Page', $values['title']); $this->assertEquals('{"file":"image1.jpg","title":"Test image"}', $values['image']); }
public function testSetupWithRecord() { $app = $this->getApp(); $content = new Content($app, 'pages'); $content->setValue('id', 5); $event = new StorageEvent($content); $this->assertEquals(5, $event->getId()); $this->assertEquals('pages', $event->getContentType()); }
public function testIsCreate() { $app = $this->getApp(); $content = new Content($app, 'pages'); $content->setValue('id', 5); $event = new StorageEvent($content); $event->setArgument('create', true); $this->assertTrue($event->isCreate()); $event->setArgument('create', false); $this->assertFalse($event->isCreate()); }
public function testHomepageContent() { $app = $this->getApp(); $this->setRequest(Request::create('/')); $storage = $this->getMock('Bolt\\Storage', ['getContent'], [$app]); $content1 = new Content($app); $content1->setValue('id', 42); $storage->expects($this->once())->method('getContent')->will($this->returnValue($content1)); $this->setService('storage', $storage); $response = $this->controller()->homepage($this->getRequest()); $globals = $response->getGlobalContext(); $this->assertTrue($response instanceof BoltResponse); $this->assertSame([42 => $content1], $globals['records']); }
/** * Determine which templates will result in templatefields. * * @param array $contenttype * @param Content $content * * @return array */ private function getTempateFieldTemplates(array $contenttype, Content $content) { $templateFieldTemplates = []; $templateFieldsConfig = $this->app['config']->get('theme/templatefields'); if ($templateFieldsConfig) { $templateFieldTemplates = array_keys($templateFieldsConfig); // Special case for default template $toRepair = []; foreach ($contenttype['fields'] as $name => $field) { if ($field['type'] === 'templateselect' && !empty($content->values[$name])) { $toRepair[$name] = $content->values[$name]; $content->setValue($name, ''); } } if ($content->hasTemplateFields()) { $templateFieldTemplates[] = ''; } foreach ($toRepair as $name => $value) { $content->setValue($name, $value); } } return $templateFieldTemplates; }
/** * Update a Bolt contenttype record. * * @param \Bolt\Legacy\Content $content The content object to be updated * @param string $comment Add a comment to save with change. * * @throws \Bolt\Exception\StorageException * * @return bool */ private function updateContent(Content $content, $comment = null) { $tablename = $this->getContenttypeTablename($content->contenttype); // Set the date the record was changed $content->setValue('datechanged', date('Y-m-d H:i:s')); // Test that the record exists in the database $oldContent = $this->findContent($tablename, $content['id']); if (empty($oldContent)) { throw new StorageException('Attempted to update a non-existent record'); } // Get the JSON database prepared values and make sure it's valid $fieldvalues = $this->getValidSaveData($content->getValues(true), $content->contenttype); // Do the actual update, and log it. $res = $this->app['db']->update($tablename, $fieldvalues, ['id' => $content['id']]); if ($res > 0) { $this->logUpdate($content->contenttype['slug'], $content['id'], $fieldvalues, $oldContent, $comment); return true; } }
/** * Insert a new contenttype record in the database. * * @param \Bolt\Legacy\Content $content Record content to insert * @param string $comment Editor's comment * * @return boolean */ protected function insertContent(Content &$content, $comment = null, $extra = []) { $collection = $this->getContentTypeCollection($content->contenttype); // Get the JSON database prepared values and make sure it's valid $fieldvalues = $this->getValidSaveData($content->getValues(false), $content->contenttype); $fieldvalues = array_merge($fieldvalues, $extra); $res = $this->app['blimp_client.request']('POST', $collection, null, $fieldvalues); $synced = $content->contenttype['blimp_mode'] === 'sync'; // Do the actual insert, and log it. if ($res['status'] == 201) { $id = $res['data']['id']; if ($synced) { $content->setValue('blimp_id', $id); } else { $content->setValue('id', $id); $this->logInsert($content->contenttype['slug'], $id, $fieldvalues, $comment); } return true; } }