Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14404 from jeabakker/features
chore(seeding): prevent automatic seeding of object properties
- Loading branch information
Showing
2 changed files
with
93 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Elgg\Traits; | ||
|
||
use Elgg\UnitTestCase; | ||
|
||
class SeedingUnitTest extends UnitTestCase { | ||
|
||
use Seeding { | ||
createObject as createSeededObject; | ||
} | ||
|
||
/** | ||
* @dataProvider propertyProvider | ||
*/ | ||
public function testCreateObjectTitle($input) { | ||
$object = $this->createSeededObject([ | ||
'title' => $input, | ||
], ['save' => false]); | ||
$this->assertInstanceOf(\ElggObject::class, $object); | ||
|
||
if ($input === false) { | ||
$this->assertNull($object->title); | ||
} else { | ||
$this->assertIsString($object->title); | ||
} | ||
|
||
if (is_string($input)) { | ||
$this->assertEquals($input, $object->title); | ||
} | ||
} | ||
|
||
/** | ||
* @dataProvider propertyProvider | ||
*/ | ||
public function testCreateObjectDescription($input) { | ||
$object = $this->createSeededObject([ | ||
'description' => $input, | ||
], ['save' => false]); | ||
$this->assertInstanceOf(\ElggObject::class, $object); | ||
|
||
if ($input === false) { | ||
$this->assertNull($object->description); | ||
} else { | ||
$this->assertIsString($object->description); | ||
} | ||
|
||
if (is_string($input)) { | ||
$this->assertEquals($input, $object->description); | ||
} | ||
} | ||
|
||
/** | ||
* @dataProvider propertyProvider | ||
*/ | ||
public function testCreateObjectTags($input) { | ||
$object = $this->createSeededObject([ | ||
'tags' => $input, | ||
], ['save' => false]); | ||
$this->assertInstanceOf(\ElggObject::class, $object); | ||
|
||
if ($input === false) { | ||
$this->assertNull($object->tags); | ||
} elseif (is_string($input)) { | ||
$this->assertEquals($input, $object->tags); | ||
} else { | ||
$this->assertIsArray($object->tags); | ||
} | ||
} | ||
|
||
public function propertyProvider() { | ||
return [ | ||
[true], | ||
[false], | ||
['hello world'], | ||
]; | ||
} | ||
} |