-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add custom property convenience methods
- Loading branch information
1 parent
455d554
commit 3e889ef
Showing
5 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Spatie\MediaLibrary\Test\Media; | ||
|
||
use Spatie\MediaLibrary\Test\TestCase; | ||
|
||
class CustomPropertyTest extends TestCase | ||
{ | ||
protected $mediaWithCustomProperty; | ||
protected $mediaWithoutCustomProperty; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->mediaWithCustomProperty = $this->testModel | ||
->addMedia($this->getTestJpg()) | ||
->preservingOriginal() | ||
->withCustomProperties(['customName' => 'customValue']) | ||
->toMediaLibrary('images'); | ||
|
||
$this->mediaWithoutCustomProperty = $this->testModel | ||
->addMedia($this->getTestJpg()) | ||
->preservingOriginal() | ||
->toMediaLibrary('images'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_can_determine_if_a_media_item_has_custom_property() | ||
{ | ||
$this->assertTrue($this->mediaWithCustomProperty->hasCustomProperty('customName')); | ||
$this->assertFalse($this->mediaWithCustomProperty->hasCustomProperty('nonExisting')); | ||
|
||
$this->assertFalse($this->mediaWithoutCustomProperty->hasCustomProperty('customName')); | ||
$this->assertFalse($this->mediaWithoutCustomProperty->hasCustomProperty('nonExisting')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_can_get_a_custom_property_of_a_media_item() | ||
{ | ||
$this->assertEquals('customValue', $this->mediaWithCustomProperty->getCustomProperty('customName')); | ||
$this->assertNull($this->mediaWithCustomProperty->getCustomProperty('nonExisting')); | ||
|
||
$this->assertNull($this->mediaWithoutCustomProperty->getCustomProperty('customName')); | ||
$this->assertNull($this->mediaWithoutCustomProperty->getCustomProperty('nonExisting')); | ||
} | ||
} |