Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(annotations): save/update annotations return false on null values
fixes #14014
- Loading branch information
Showing
2 changed files
with
120 additions
and
0 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
112 changes: 112 additions & 0 deletions
112
engine/tests/phpunit/integration/Elgg/Database/AnnotationsTableIntegrationTest.php
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,112 @@ | ||
<?php | ||
|
||
namespace Elgg\Database; | ||
|
||
use Elgg\IntegrationTestCase; | ||
|
||
class AnnotationsTableIntegrationTest extends IntegrationTestCase { | ||
|
||
/** | ||
* @var AnnotationsTable | ||
*/ | ||
protected $service; | ||
|
||
/** | ||
* @var \ElggUser | ||
*/ | ||
protected $owner; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function up() { | ||
$this->service = _elgg_services()->annotationsTable; | ||
$this->owner = $this->createUser(); | ||
_elgg_services()->session->setLoggedInUser($this->owner); | ||
} | ||
|
||
public function testCreateAnnotation() { | ||
$entity = $this->createObject(); | ||
|
||
$annotation = new \ElggAnnotation(); | ||
$annotation->owner_guid = $this->owner->guid; | ||
$annotation->name = 'foo'; | ||
$annotation->value = 'bar'; | ||
|
||
$annotation_id = $this->service->create($annotation, $entity); | ||
$this->assertIsInt($annotation_id); | ||
|
||
$annotation = elgg_get_annotation_from_id($annotation_id); | ||
$this->assertInstanceOf(\ElggAnnotation::class, $annotation); | ||
$this->assertEquals($this->owner->guid, $annotation->owner_guid); | ||
$this->assertEquals('foo', $annotation->name); | ||
$this->assertEquals('bar', $annotation->value); | ||
} | ||
|
||
public function testCreateAnnotationWithEmptyContent() { | ||
$entity = $this->createObject(); | ||
|
||
$annotation = new \ElggAnnotation(); | ||
|
||
$this->assertFalse($this->service->create($annotation, $entity)); | ||
} | ||
|
||
public function testUpdateAnnotationUsingUpdate() { | ||
$entity = $this->createObject(); | ||
|
||
$annotation = new \ElggAnnotation(); | ||
$annotation->owner_guid = $this->owner->guid; | ||
$annotation->name = 'foo'; | ||
$annotation->value = 'bar'; | ||
|
||
$annotation_id = $this->service->create($annotation, $entity); | ||
$this->assertIsInt($annotation_id); | ||
|
||
$annotation = elgg_get_annotation_from_id($annotation_id); | ||
$this->assertInstanceOf(\ElggAnnotation::class, $annotation); | ||
$annotation->value = 'bar2'; | ||
$annotation_save_id = $this->service->update($annotation); | ||
$this->assertEquals($annotation_id, $annotation_save_id); | ||
|
||
$annotation = elgg_get_annotation_from_id($annotation_id); | ||
$this->assertEquals('bar2', $annotation->value); | ||
} | ||
|
||
public function testUpdateAnnotationUsingCreate() { | ||
$entity = $this->createObject(); | ||
|
||
$annotation = new \ElggAnnotation(); | ||
$annotation->owner_guid = $this->owner->guid; | ||
$annotation->name = 'foo'; | ||
$annotation->value = 'bar'; | ||
|
||
$annotation_id = $this->service->create($annotation, $entity); | ||
$this->assertIsInt($annotation_id); | ||
|
||
$annotation = elgg_get_annotation_from_id($annotation_id); | ||
$this->assertInstanceOf(\ElggAnnotation::class, $annotation); | ||
$annotation->value = 'bar2'; | ||
$annotation_save_id = $this->service->create($annotation, $entity); | ||
$this->assertEquals($annotation_id, $annotation_save_id); | ||
|
||
$annotation = elgg_get_annotation_from_id($annotation_id); | ||
$this->assertEquals('bar2', $annotation->value); | ||
} | ||
|
||
public function testUpdateAnnotationWithEmptyContent() { | ||
$entity = $this->createObject(); | ||
|
||
$annotation = new \ElggAnnotation(); | ||
$annotation->owner_guid = $this->owner->guid; | ||
$annotation->name = 'foo'; | ||
$annotation->value = 'bar'; | ||
|
||
$annotation_id = $this->service->create($annotation, $entity); | ||
$this->assertIsInt($annotation_id); | ||
|
||
$annotation = elgg_get_annotation_from_id($annotation_id); | ||
$this->assertInstanceOf(\ElggAnnotation::class, $annotation); | ||
unset($annotation->value); | ||
$this->assertFalse($this->service->update($annotation)); | ||
} | ||
} |