/** @test */
 function it_saves_and_gets_source_model()
 {
     $nodeSource = $this->getNodeSource();
     $this->populateNodeSource($nodeSource);
     $this->assertInstanceOf('gen\\Entities\\' . source_model_name($nodeSource->source_type), $nodeSource->getSource());
     $this->assertNull($nodeSource->source);
     // We check this because the source model should be saved to
     // the relation after the first save and the model retrieves
     // source from relation if the model exists in the database.
     $nodeSource->save();
     $this->assertInstanceOf('gen\\Entities\\' . source_model_name($nodeSource->source_type), $nodeSource->getSource());
     // We should now be able to access the source through the
     // relation magic property.
     $this->assertInstanceOf('gen\\Entities\\' . source_model_name($nodeSource->source_type), $nodeSource->source);
     // Now we are attempting to save an existing relation model
     $nodeSource->save();
     $this->assertInstanceOf('gen\\Entities\\' . source_model_name($nodeSource->source_type), $nodeSource->getSource());
     // We should now be able to access the source through the
     // relation magic property.
     $this->assertInstanceOf('gen\\Entities\\' . source_model_name($nodeSource->source_type), $nodeSource->source);
 }
Beispiel #2
0
 /**
  * Gets the cover image
  *
  * @return Image|null
  */
 public function getCoverImage()
 {
     if ($this->coverImage) {
         return $this->coverImage;
     }
     $modelName = source_model_name($this->getNodeTypeName(), true);
     $mutatables = call_user_func([$modelName, 'getMutatables']);
     foreach ($mutatables as $mutatable => $type) {
         if ($type === 'gallery' && ($images = $this->getTranslationAttribute($mutatable, null, true, true))) {
             if ($cover = get_nuclear_cover($images)) {
                 $this->coverImage = $cover;
                 return $cover;
             }
         }
         if ($type === 'document' && ($document = $this->getTranslationAttribute($mutatable, null, true, true))) {
             if ($document = get_nuclear_cover($document)) {
                 $this->coverImage = $document;
                 return $document;
             }
         }
     }
     return null;
 }
Beispiel #3
0
 /**
  * Creates a class name from table name
  *
  * @param string $name
  * @return string
  */
 public function getClassName($name)
 {
     return source_model_name($name);
 }
Beispiel #4
0
 /**
  * Returns the source model name
  *
  * @param string|null $type
  * @return string
  */
 public function getSourceModelName($type = null)
 {
     $type = $type ?: $this->source_type;
     return source_model_name($type, true);
 }
Beispiel #5
0
 /** @test */
 function it_registers_source_model_name_helper()
 {
     $this->assertEquals('NsProject', source_model_name('project'));
 }