2015-11-11 00:09:47 +01:00
|
|
|
<?php namespace Todaymade\Daux\Tree;
|
|
|
|
|
|
|
|
use Todaymade\Daux\Config;
|
|
|
|
|
|
|
|
class ContentTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-07-27 21:32:51 +02:00
|
|
|
protected function createContent($content)
|
|
|
|
{
|
2015-11-11 00:09:47 +01:00
|
|
|
$dir = new Directory(new Root(new Config, ''), '');
|
|
|
|
$obj = new Content($dir, '');
|
|
|
|
$obj->setContent($content);
|
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerTestAttributes()
|
|
|
|
{
|
2016-07-27 21:32:51 +02:00
|
|
|
return [
|
|
|
|
['This is content', [], 'This is content'],
|
|
|
|
["title: This is a simple title\n---\nThis is content\n", ['title' => 'This is a simple title'], 'This is content'],
|
|
|
|
["title: This is a simple title\ntitle :This is another title\n---\nThis is content\n", ['title' => 'This is another title'], 'This is content'],
|
|
|
|
["title: This is a simple title\nthis is not metadata\n---\nThis is content\n", ['title' => 'This is a simple title'], 'This is content'],
|
|
|
|
['title: This is only metatada, no content', [], 'title: This is only metatada, no content'],
|
|
|
|
["title: This is almost only metadata\n---\n", ['title' => 'This is almost only metadata'], ''],
|
2016-04-28 23:33:26 +02:00
|
|
|
["# Some content\n\nhi\n```yml\nvalue: true\n```\n----\n Follow up", [], "# Some content\n\nhi\n```yml\nvalue: true\n```\n----\n Follow up"],
|
2016-07-27 21:32:51 +02:00
|
|
|
];
|
2015-11-11 00:09:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestAttributes
|
|
|
|
*/
|
2016-04-28 23:33:26 +02:00
|
|
|
public function testAttributes($content, $attributes, $finalContent)
|
2015-11-11 00:09:47 +01:00
|
|
|
{
|
|
|
|
$obj = $this->createContent($content);
|
|
|
|
|
|
|
|
$this->assertEquals($attributes, $obj->getAttribute());
|
2016-04-28 23:33:26 +02:00
|
|
|
$this->assertEquals($finalContent, trim($obj->getContent()));
|
2015-11-11 00:09:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoAttributes()
|
|
|
|
{
|
|
|
|
$content = "This is a content with a separator\n----\n this wasn't an attribute";
|
|
|
|
|
|
|
|
$obj = $this->createContent($content);
|
|
|
|
|
|
|
|
$this->assertEquals($content, $obj->getContent());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testContentPreserved()
|
|
|
|
{
|
|
|
|
$content = "this was an attribute, but also a separator\n----\nand it works";
|
|
|
|
$with_attribute = "title: a title\n----\n$content";
|
|
|
|
|
|
|
|
$obj = $this->createContent($with_attribute);
|
|
|
|
|
|
|
|
$this->assertEquals($content, $obj->getContent());
|
|
|
|
$this->assertEquals('a title', $obj->getAttribute('title'));
|
|
|
|
}
|
|
|
|
}
|