/** @test **/ public function it_fetches_the_cover_associated_with_the_post() { $this->createComponent('posts'); $this->createComponent('cover_photos'); $this->insertOn('posts', ['title' => 'Random Blog Post']); $this->insertOn('cover_photos', ['image' => '/path/to/image.jpg']); Post::usesOne(CoverPhoto::class); CoverPhoto::first()->registerTo(Post::first()); $cover = Post::first()->cover_photo; $this->assertEquals('/path/to/image.jpg', $cover->image); }
function requireDefaultRecords() { parent::requireDefaultRecords(); $ebook = DataObject::get_one('Ebook', "\"Title\" = 'Silhouetted against the moon'"); if (!($ebook && $ebook->exists())) { $ebook = new Ebook(); $ebook->Title = 'Silhouetted against the moon'; $ebook->Summary = <<<HTML \t\t\t<p>A frightful product that will keep you on the edge of your seat!</p> \t\t\t<p>Cover <a href="http://www.sxc.hu/photo/991793">image</a> courtesy of <a href="http://www.sxc.hu/profile/nazreth" target="_blank">nazreth</a> on <a href="http://www.sxc.hu/" target="_blank">sxc.hu</a></p> HTML; $coverPhoto = DataObject::get_one('CoverPhoto', "\"Name\" = 'silhouetted-against-the-moon.png'"); if (!($coverPhoto && $coverPhoto->exists())) { $uploadfolder = Folder::findOrMake("Uploads"); $command = "cp ../payment-test/templates/Images/silhouetted-against-the-moon.png ../" . $uploadfolder->Filename; `{$command}`; $coverPhoto = new CoverPhoto(array('ClassName' => 'CoverPhoto')); $coverPhoto->Name = 'silhouetted-against-the-moon.png'; $coverPhoto->Title = 'silhouetted-against-the-moon'; $coverPhoto->Filename = 'assets/Uploads/silhouetted-against-the-moon.png'; $coverPhoto->ParentID = $uploadfolder->ID; $coverPhoto->OwnerID = Member::currentUserID(); $coverPhoto->write(); } $file = DataObject::get_one('EbookFile', "\"Name\" = 'silhouetted-against-th-moon.pdf'"); if (!($file && $file->exists())) { $uploadfolder = Folder::findOrMake("Uploads"); $command = "cp ../payment-test/templates/Images/silhouetted-against-th-moon.pdf ../" . $uploadfolder->Filename; `{$command}`; $file = new EbookFile(array('ClassName' => 'EbookFile')); $file->Name = 'silhouetted-against-th-moon.pdf'; $file->Title = 'silhouetted-against-th-moon'; $file->Filename = 'assets/Uploads/silhouetted-against-th-moon.pdf'; $file->ParentID = $uploadfolder->ID; $file->OwnerID = Member::currentUserID(); $file->write(); } $ebook->CoverPhotoID = $coverPhoto->ID; $ebook->FileID = $file->ID; $ebook->Amount->Amount = '5.99'; $ebook->Amount->Currency = 'USD'; $ebook->write(); $author = DataObject::get_one('Author', "\"Name\" = 'Michael Lorenzo'"); if (!($author && $author->exists())) { $author = new Author(array('ClassName' => 'Author')); $author->Name = 'Michael Lorenzo'; $author->Introduction = <<<HTML <p>Hi everyone! =) Thank you for viewing my gallery. My images are for free and I would love to see your projects or send me a link to your website so that I can see where you used nazreth's photos. It's a pleasure to see your artworks and it would inspire me to come up with more useful images. =)<br /><br />Thanks again and enjoy viewing my gallery! =)</p> HTML; $author->write(); } $ebook->Authors()->add($author); DB::alteration_message('payable Ebook example \'Silhouetted against the moon\'', 'created'); } }