getContentObject() 공개 메소드

Get an object for the content of a specific contenttype. This will be \Bolt\Legacy\Content, unless the contenttype defined another class to be used.
public getContentObject ( array | string $contenttype, array $values = [] ) : Content
$contenttype array | string
$values array
리턴 Content
예제 #1
0
 public function testGetContentObject()
 {
     $app = $this->getApp();
     $storage = new Storage($app);
     $content = $storage->getContentObject('pages');
     $this->assertInstanceOf('Bolt\\Legacy\\Content', $content);
     $fields = $app['config']->get('contenttypes/pages/fields');
     $mock = $this->getMock('Bolt\\Legacy\\Content', null, [$app], 'Pages');
     $content = $storage->getContentObject(['class' => 'Pages', 'fields' => $fields]);
     $this->assertInstanceOf('Pages', $content);
     $this->assertInstanceOf('Bolt\\Legacy\\Content', $content);
     // Test that a class not instanceof Bolt\Legacy\Content fails
     $mock = $this->getMock('stdClass', null, [], 'Failing');
     $this->setExpectedException('Exception', 'Failing does not extend \\Bolt\\Legacy\\Content.');
     $content = $storage->getContentObject(['class' => 'Failing', 'fields' => $fields]);
 }
예제 #2
0
파일: ChangeLogTest.php 프로젝트: bolt/bolt
 public function setUp()
 {
     $this->resetDb();
     $app = $this->getApp();
     $app['config']->set('general/changelog/enabled', true);
     $this->addSomeContent();
     $storage = new Storage($app);
     $content = $storage->getContentObject('pages');
     $content['contentid'] = 1;
     $storage->saveContent($content, 'pages');
 }
예제 #3
0
 /**
  * We copy the 'Pages' ContentType into a 'Fakes' configuration and test
  * against this, as PHPUnit keeps the mock in the $this->mockObjects private
  * property array and any further calls to the 'Pages' repo will (currently)
  * fail as the Application object is torn down at the end of the test/class.
  */
 public function testGetContentObject()
 {
     $app = $this->getApp();
     $storage = new Storage($app);
     $content = $storage->getContentObject('pages');
     $this->assertInstanceOf('Bolt\\Legacy\\Content', $content);
     // Fake it until we make it… to the end of the test suite.
     $contentType = $app['config']->get('contenttypes/pages');
     $contentType['name'] = 'Fakes';
     $contentType['singular_name'] = 'Fake';
     $contentType['slug'] = 'fakes';
     $contentType['singular_slug'] = 'fake';
     $contentType['tablename'] = 'fakes';
     $app['config']->set('contenttypes/fakes', $contentType);
     $fields = $app['config']->get('contenttypes/fakes/fields');
     $mock = $this->getMock('Bolt\\Legacy\\Content', [], [$app], 'Fakes');
     $content = $storage->getContentObject(['class' => 'Fakes', 'fields' => $fields]);
     $this->assertInstanceOf('Fakes', $content);
     $this->assertInstanceOf('Bolt\\Legacy\\Content', $content);
     // Test that a class not instanceof Bolt\Legacy\Content fails
     $mock = $this->getMock('stdClass', null, [], 'Failing');
     $this->setExpectedException('Exception', 'Failing does not extend \\Bolt\\Legacy\\Content.');
     $content = $storage->getContentObject(['class' => 'Failing', 'fields' => $fields]);
 }