diff --git a/tests/Pest.php b/tests/Pest.php index c5eaaa7f..3b9af18b 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -14,4 +14,6 @@ define('PATH', [ ! is_file($flextype_autoload = ROOT_DIR . '/vendor/autoload.php') and exit('Please run: composer install for flextype'); $flextype_loader = require_once $flextype_autoload; -include ROOT_DIR . '/src/flextype/flextype.php'; +filesystem()->directory(PATH['tmp'])->exists() and filesystem()->directory(PATH['tmp'])->delete(); + +include ROOT_DIR . '/src/flextype/bootstrap.php'; diff --git a/tests/fixtures/serializers/frontmatter.md b/tests/fixtures/serializers/frontmatter.md new file mode 100644 index 00000000..0a78a407 --- /dev/null +++ b/tests/fixtures/serializers/frontmatter.md @@ -0,0 +1,4 @@ +--- +title: Foo +--- +Content is here. \ No newline at end of file diff --git a/tests/fixtures/serializers/neon.neon b/tests/fixtures/serializers/neon.neon new file mode 100644 index 00000000..0d8e794f --- /dev/null +++ b/tests/fixtures/serializers/neon.neon @@ -0,0 +1 @@ +hello: world \ No newline at end of file diff --git a/tests/Foundation/Entries/EntriesTest.php b/tests/src/flextype/Entries/EntriesTest.php similarity index 100% rename from tests/Foundation/Entries/EntriesTest.php rename to tests/src/flextype/Entries/EntriesTest.php diff --git a/tests/Foundation/Entries/Fields/CreatedAtFieldTest.php b/tests/src/flextype/Entries/Fields/CreatedAtFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/CreatedAtFieldTest.php rename to tests/src/flextype/Entries/Fields/CreatedAtFieldTest.php diff --git a/tests/Foundation/Entries/Fields/CreatedByFieldTest.php b/tests/src/flextype/Entries/Fields/CreatedByFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/CreatedByFieldTest.php rename to tests/src/flextype/Entries/Fields/CreatedByFieldTest.php diff --git a/tests/Foundation/Entries/Fields/EntriesFieldTest.php b/tests/src/flextype/Entries/Fields/EntriesFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/EntriesFieldTest.php rename to tests/src/flextype/Entries/Fields/EntriesFieldTest.php diff --git a/tests/Foundation/Entries/Fields/IdFieldTest.php b/tests/src/flextype/Entries/Fields/IdFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/IdFieldTest.php rename to tests/src/flextype/Entries/Fields/IdFieldTest.php diff --git a/tests/Foundation/Entries/Fields/ModifiedAtFieldTest.php b/tests/src/flextype/Entries/Fields/ModifiedAtFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/ModifiedAtFieldTest.php rename to tests/src/flextype/Entries/Fields/ModifiedAtFieldTest.php diff --git a/tests/Foundation/Entries/Fields/ParsersFieldTest.php b/tests/src/flextype/Entries/Fields/ParsersFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/ParsersFieldTest.php rename to tests/src/flextype/Entries/Fields/ParsersFieldTest.php diff --git a/tests/Foundation/Entries/Fields/PublishedAtFieldTest.php b/tests/src/flextype/Entries/Fields/PublishedAtFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/PublishedAtFieldTest.php rename to tests/src/flextype/Entries/Fields/PublishedAtFieldTest.php diff --git a/tests/Foundation/Entries/Fields/PublishedByFieldTest.php b/tests/src/flextype/Entries/Fields/PublishedByFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/PublishedByFieldTest.php rename to tests/src/flextype/Entries/Fields/PublishedByFieldTest.php diff --git a/tests/Foundation/Entries/Fields/RegistryFieldTest.php b/tests/src/flextype/Entries/Fields/RegistryFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/RegistryFieldTest.php rename to tests/src/flextype/Entries/Fields/RegistryFieldTest.php diff --git a/tests/Foundation/Entries/Fields/RoutableFieldTest.php b/tests/src/flextype/Entries/Fields/RoutableFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/RoutableFieldTest.php rename to tests/src/flextype/Entries/Fields/RoutableFieldTest.php diff --git a/tests/Foundation/Entries/Fields/SlugFieldTest.php b/tests/src/flextype/Entries/Fields/SlugFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/SlugFieldTest.php rename to tests/src/flextype/Entries/Fields/SlugFieldTest.php diff --git a/tests/Foundation/Entries/Fields/UuidFieldTest.php b/tests/src/flextype/Entries/Fields/UuidFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/UuidFieldTest.php rename to tests/src/flextype/Entries/Fields/UuidFieldTest.php diff --git a/tests/Foundation/Entries/Fields/VisibilityFieldTest.php b/tests/src/flextype/Entries/Fields/VisibilityFieldTest.php similarity index 100% rename from tests/Foundation/Entries/Fields/VisibilityFieldTest.php rename to tests/src/flextype/Entries/Fields/VisibilityFieldTest.php diff --git a/tests/Support/Helpers/FilterHelperTest.php b/tests/src/flextype/FilterHelperTest.php similarity index 100% rename from tests/Support/Helpers/FilterHelperTest.php rename to tests/src/flextype/FilterHelperTest.php diff --git a/tests/Support/Helpers/FindHelperTest.php b/tests/src/flextype/FindHelperTest.php similarity index 100% rename from tests/Support/Helpers/FindHelperTest.php rename to tests/src/flextype/FindHelperTest.php diff --git a/tests/Foundation/Helpers/FlextypHelperTest.php b/tests/src/flextype/FlextypHelperTest.php similarity index 89% rename from tests/Foundation/Helpers/FlextypHelperTest.php rename to tests/src/flextype/FlextypHelperTest.php index 366dc5f2..afa5f979 100644 --- a/tests/Foundation/Helpers/FlextypHelperTest.php +++ b/tests/src/flextype/FlextypHelperTest.php @@ -7,7 +7,7 @@ use Flextype\Entries\Entries; use Atomastic\Strings\Strings; test('test getVersion() method', function () { - $this->assertTrue(!Strings::create(app()->getVersion())->isEmpty()); + $this->assertTrue(!Strings::create(flextype()->getVersion())->isEmpty()); }); test('test getInstance() method', function () { diff --git a/tests/Foundation/FlextypeTest.php b/tests/src/flextype/FlextypeTest.php similarity index 100% rename from tests/Foundation/FlextypeTest.php rename to tests/src/flextype/FlextypeTest.php diff --git a/tests/Support/Parsers/ShortcodeTest.php b/tests/src/flextype/Parsers/ShortcodeTest.php similarity index 100% rename from tests/Support/Parsers/ShortcodeTest.php rename to tests/src/flextype/Parsers/ShortcodeTest.php diff --git a/tests/Support/Parsers/Shortcodes/EntriesShortcodeTest.php b/tests/src/flextype/Parsers/Shortcodes/EntriesShortcodeTest.php similarity index 100% rename from tests/Support/Parsers/Shortcodes/EntriesShortcodeTest.php rename to tests/src/flextype/Parsers/Shortcodes/EntriesShortcodeTest.php diff --git a/tests/Support/Parsers/Shortcodes/RawShortcodeTest.php b/tests/src/flextype/Parsers/Shortcodes/RawShortcodeTest.php similarity index 100% rename from tests/Support/Parsers/Shortcodes/RawShortcodeTest.php rename to tests/src/flextype/Parsers/Shortcodes/RawShortcodeTest.php diff --git a/tests/Support/Parsers/Shortcodes/RegistryShortcodeTest.php b/tests/src/flextype/Parsers/Shortcodes/RegistryShortcodeTest.php similarity index 100% rename from tests/Support/Parsers/Shortcodes/RegistryShortcodeTest.php rename to tests/src/flextype/Parsers/Shortcodes/RegistryShortcodeTest.php diff --git a/tests/Support/Parsers/Shortcodes/UrlShortcodeTest.php b/tests/src/flextype/Parsers/Shortcodes/UrlShortcodeTest.php similarity index 100% rename from tests/Support/Parsers/Shortcodes/UrlShortcodeTest.php rename to tests/src/flextype/Parsers/Shortcodes/UrlShortcodeTest.php diff --git a/tests/Foundation/PluginsTest.php b/tests/src/flextype/PluginsTest.php similarity index 100% rename from tests/Foundation/PluginsTest.php rename to tests/src/flextype/PluginsTest.php diff --git a/tests/src/flextype/Serializers/FrontmatterTest.php b/tests/src/flextype/Serializers/FrontmatterTest.php new file mode 100644 index 00000000..ac426538 --- /dev/null +++ b/tests/src/flextype/Serializers/FrontmatterTest.php @@ -0,0 +1,26 @@ +file(ROOT_DIR . '/tests/fixtures/serializers/frontmatter.md')->get(); + $this->assertEquals($string, + serializers()->frontmatter() + ->encode(['title' => 'Foo', + 'content' => 'Content is here.'])); +}); + +test('test decode() method', function () { + $this->assertEquals(['title' => 'Foo', + 'content' => 'Content is here.'], + serializers()->frontmatter() + ->decode($string = filesystem()->file(ROOT_DIR . '/tests/fixtures/serializers/frontmatter.md')->get())); +}); + +test('test getCacheID() method', function () { + $string = filesystem()->file(ROOT_DIR . '/tests/fixtures/serializers/frontmatter.md')->get();; + $cache_id = serializers()->frontmatter() + ->getCacheID($string); + $this->assertEquals(32, strlen($cache_id)); + $this->assertNotEquals($string, $cache_id); +}); diff --git a/tests/Support/Serializers/JsonTest.php b/tests/src/flextype/Serializers/JsonTest.php similarity index 100% rename from tests/Support/Serializers/JsonTest.php rename to tests/src/flextype/Serializers/JsonTest.php diff --git a/tests/src/flextype/Serializers/NeonTest.php b/tests/src/flextype/Serializers/NeonTest.php new file mode 100644 index 00000000..90149cf6 --- /dev/null +++ b/tests/src/flextype/Serializers/NeonTest.php @@ -0,0 +1,23 @@ +file(ROOT_DIR . '/tests/fixtures/serializers/neon.neon')->get(); + $this->assertEquals(trim($string), + trim(serializers()->neon()->encode(['hello' => 'world']))); +}); + +test('test decode() method', function () { + $this->assertEquals(['hello' => 'world'], + serializers()->neon() + ->decode($string = filesystem()->file(ROOT_DIR . '/tests/fixtures/serializers/neon.neon')->get())); +}); + +test('test getCacheID() method', function () { + $string = filesystem()->file(ROOT_DIR . '/tests/fixtures/serializers/neon.neon')->get();; + $cache_id = serializers()->neon() + ->getCacheID($string); + $this->assertEquals(32, strlen($cache_id)); + $this->assertNotEquals($string, $cache_id); +}); diff --git a/tests/Support/Serializers/YamlTest.php b/tests/src/flextype/Serializers/YamlTest.php similarity index 100% rename from tests/Support/Serializers/YamlTest.php rename to tests/src/flextype/Serializers/YamlTest.php