ViewpointDescription now ignores empty lines

This commit is contained in:
Vassyli
2017-09-27 13:17:26 +02:00
parent 829d63d7f6
commit 4b82ee4b89
3 changed files with 29 additions and 1 deletions
+8
View File
@@ -71,6 +71,14 @@ class Viewpoint implements CreateableInterface
$this->_description = new SceneDescription($description);
}
/**
* Clears the description
*/
public function clearDescription(): void
{
$this->description = "";
}
/**
* Returns the current description as a string
* @return string
+8 -1
View File
@@ -61,6 +61,13 @@ class SceneDescription
$input = str_replace("\r\n", "\n", $input);
$input = str_replace("\r", "\n", $input);
return explode("\n\n", $input);
$parts = explode("\n\n", $input);
foreach ($parts as $key => $part) {
if (strlen($part) === 0) {
unset($parts[$key]);
}
}
return $parts;
}
}
+13
View File
@@ -197,4 +197,17 @@ class ViewpointTest extends CoreModelTestCase
$characterScene->addDescriptionParagraph("You enjoy being here.");
$this->assertSame("This is the village.\n\nYou enjoy being here.", $characterScene->getDescription());
}
public function testClearingSceneDescription()
{
$em = $this->getEntityManager();
$testCharacter = $em->getRepository(Character::class)->find(2);
$characterScene = $testCharacter->getViewpoint();
$characterScene->clearDescription();
$this->assertSame("", $characterScene->getDescription());
$characterScene->addDescriptionParagraph("You enjoy being here.");
$this->assertSame("You enjoy being here.", $characterScene->getDescription());
}
}