1*8fed17f3SAndreas Gohr<?php 2*8fed17f3SAndreas Gohr 3*8fed17f3SAndreas Gohrnamespace dokuwiki\plugin\struct\test; 4*8fed17f3SAndreas Gohr 5*8fed17f3SAndreas Gohruse dokuwiki\plugin\struct\meta; 6*8fed17f3SAndreas Gohruse dokuwiki\plugin\struct\meta\Column; 7*8fed17f3SAndreas Gohr 8*8fed17f3SAndreas Gohr/** 9*8fed17f3SAndreas Gohr * @group plugin_struct 10*8fed17f3SAndreas Gohr * @group plugins 11*8fed17f3SAndreas Gohr * 12*8fed17f3SAndreas Gohr */ 13*8fed17f3SAndreas Gohrclass SchemaImporterTest extends StructTest 14*8fed17f3SAndreas Gohr{ 15*8fed17f3SAndreas Gohr 16*8fed17f3SAndreas Gohr public function test_export() 17*8fed17f3SAndreas Gohr { 18*8fed17f3SAndreas Gohr $sb = new meta\SchemaBuilder( 19*8fed17f3SAndreas Gohr 'schema1', 20*8fed17f3SAndreas Gohr [ 21*8fed17f3SAndreas Gohr 'new' => [ 22*8fed17f3SAndreas Gohr 'new1' => ['label' => 'first', 'class' => 'Text', 'sort' => 10, 'ismulti' => 0, 'isenabled' => 1], 23*8fed17f3SAndreas Gohr 'new2' => ['label' => 'second', 'class' => 'Text', 'sort' => 20, 'ismulti' => 1, 'isenabled' => 1], 24*8fed17f3SAndreas Gohr 'new3' => ['label' => 'third', 'class' => 'Text', 'sort' => 30, 'ismulti' => 0, 'isenabled' => 1], 25*8fed17f3SAndreas Gohr 'new4' => ['label' => 'fourth', 'class' => 'Text', 'sort' => 40, 'ismulti' => 0, 'isenabled' => 1], 26*8fed17f3SAndreas Gohr ] 27*8fed17f3SAndreas Gohr ] 28*8fed17f3SAndreas Gohr ); 29*8fed17f3SAndreas Gohr $sb->build(); 30*8fed17f3SAndreas Gohr 31*8fed17f3SAndreas Gohr $schema = new meta\Schema('schema1'); 32*8fed17f3SAndreas Gohr $expect = json_decode(file_get_contents(__DIR__ . '/json/schema1.struct.json'), true); 33*8fed17f3SAndreas Gohr $actual = json_decode($schema->toJSON(), true); 34*8fed17f3SAndreas Gohr // we don't expect this to match 35*8fed17f3SAndreas Gohr unset($expect['structversion']); 36*8fed17f3SAndreas Gohr unset($actual['structversion']); 37*8fed17f3SAndreas Gohr $this->assertEquals($expect, $actual); 38*8fed17f3SAndreas Gohr } 39*8fed17f3SAndreas Gohr 40*8fed17f3SAndreas Gohr public function test_import_one() 41*8fed17f3SAndreas Gohr { 42*8fed17f3SAndreas Gohr $sb = new meta\SchemaImporter('tag', file_get_contents(__DIR__ . '/json/tag.struct.json')); 43*8fed17f3SAndreas Gohr $this->assertTrue((bool)$sb->build()); 44*8fed17f3SAndreas Gohr 45*8fed17f3SAndreas Gohr $schema = new meta\Schema('tag'); 46*8fed17f3SAndreas Gohr $columns = $schema->getColumns(); 47*8fed17f3SAndreas Gohr 48*8fed17f3SAndreas Gohr $this->assertCount(2, $columns); 49*8fed17f3SAndreas Gohr $this->assertTrue(is_a($columns[0], Column::class)); 50*8fed17f3SAndreas Gohr $this->assertTrue(is_a($columns[1], Column::class)); 51*8fed17f3SAndreas Gohr $this->assertEquals('tag', $columns[0]->getLabel()); 52*8fed17f3SAndreas Gohr $this->assertEquals('tags', $columns[1]->getLabel()); 53*8fed17f3SAndreas Gohr } 54*8fed17f3SAndreas Gohr 55*8fed17f3SAndreas Gohr public function test_import_export() 56*8fed17f3SAndreas Gohr { 57*8fed17f3SAndreas Gohr $sb = new meta\SchemaImporter('foobar', file_get_contents(__DIR__ . '/json/schema1.struct.json')); 58*8fed17f3SAndreas Gohr $this->assertTrue((bool)$sb->build()); 59*8fed17f3SAndreas Gohr 60*8fed17f3SAndreas Gohr $schema = new meta\Schema('foobar'); 61*8fed17f3SAndreas Gohr $expect = json_decode(file_get_contents(__DIR__ . '/json/schema1.struct.json'), true); 62*8fed17f3SAndreas Gohr $actual = json_decode($schema->toJSON(), true); 63*8fed17f3SAndreas Gohr // we don't expect this to match 64*8fed17f3SAndreas Gohr unset($expect['structversion']); 65*8fed17f3SAndreas Gohr unset($actual['structversion']); 66*8fed17f3SAndreas Gohr $expect['schema'] = 'foobar'; // we exported the new schema 67*8fed17f3SAndreas Gohr $this->assertEquals($expect, $actual); 68*8fed17f3SAndreas Gohr } 69*8fed17f3SAndreas Gohr 70*8fed17f3SAndreas Gohr} 71