1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8namespace Tiki\Tests\Yaml; 9 10use PHPUnit_Framework_TestCase; 11use Symfony\Component\Yaml\Yaml; 12use Tiki\Yaml\Directives as Directives; 13 14class DirectivesTest extends PHPUnit_Framework_TestCase 15{ 16 /** 17 * @var Directives 18 */ 19 protected $directives; 20 protected $fixtures; 21 22 public function setUp() 23 { 24 $this->fixtures = __DIR__ . '/Fixtures/'; 25 $this->directives = new Directives(null, $this->fixtures); 26 } 27 28 public function testNoChangeIfNoDirective() 29 { 30 $yamlString = file_get_contents($this->fixtures . 'no_directives.yml'); 31 $yaml = Yaml::parse($yamlString); 32 33 $yamlJson = json_encode($yaml); 34 $this->directives->process($yaml); 35 $this->assertEquals($yamlJson, json_encode($yaml)); 36 } 37 38 /** 39 * @dataProvider includeDataProvider 40 */ 41 public function testInclude($yamlFile, $yamlResultFile) 42 { 43 $yamlString = file_get_contents($this->fixtures . $yamlFile); 44 $yaml = Yaml::parse($yamlString); 45 46 $yamlResultString = file_get_contents($this->fixtures . $yamlResultFile); 47 $yamlResult = Yaml::parse($yamlResultString); 48 49 50 $this->directives->process($yaml); 51 $this->assertEquals(json_encode($yamlResult), json_encode($yaml)); 52 } 53 54 public function includeDataProvider() 55 { 56 return [ 57 ['include_replace_key.yml', 'include_replace_key_result.yml'], 58 ['include_replace_key_2.yml', 'include_replace_key_result.yml'], 59 ['include_replace_deep_key.yml', 'include_replace_deep_key_result.yml'], 60 ['include_appending.yml', 'include_appending_result.yml'], 61 ]; 62 } 63} 64