Open Data Catalog v2.0.0
SchemaRetrieverTest.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use Drupal\Core\Extension\ExtensionList;
7 use PHPUnit\Framework\TestCase;
8 
15 class SchemaRetrieverTest extends TestCase {
16 
20  public function testSchemaDirectory() {
21  $module = $this->getMockBuilder(ExtensionList::class)
22  ->setMethods(['getPathname'])
23  ->disableOriginalConstructor()
24  ->getMockForAbstractClass();
25 
26  $module->method("getPathname")->willReturn("./tmp");
27 
28  $retriever = new SchemaRetriever("/tmp", $module);
29  $dir = $retriever->getSchemaDirectory();
30  $this->assertEquals($dir, './schema');
31  }
32 
36  public function testGetAllIds() {
37  $module = $this->getMockBuilder(ExtensionList::class)
38  ->setMethods(['getPathname'])
39  ->disableOriginalConstructor()
40  ->getMockForAbstractClass();
41 
42  $module->method("getPathname")->willReturn("./tmp");
43 
44  $retriever = new SchemaRetriever("/tmp", $module);
45  $ids = $retriever->getAllIds();
46  $this->assertEquals(['catalog', 'dataset', 'dataset.ui'], $ids);
47  }
48 
52  public function testGet() {
53  $module = $this->getMockBuilder(ExtensionList::class)
54  ->setMethods(['getPathname'])
55  ->disableOriginalConstructor()
56  ->getMockForAbstractClass();
57 
58  $module->method("getPathname")->willReturn("./tmp");
59 
60  $retriever = new SchemaRetriever("/tmp", $module);
61  $schema = $retriever->retrieve('dataset');
62  $json = json_decode($schema);
63  $this->assertNotFalse($json);
64  }
65 
69  public function testError() {
70  $this->expectExceptionMessage("Schema blah not found.");
71  $module = $this->getMockBuilder(ExtensionList::class)
72  ->setMethods(['getPathname'])
73  ->disableOriginalConstructor()
74  ->getMockForAbstractClass();
75 
76  $module->method("getPathname")->willReturn("./tmp");
77 
78  $retriever = new SchemaRetriever("/tmp", $module);
79  $retriever->retrieve('blah');
80  }
81 
85  public function testNoDirectory() {
86  $this->expectExceptionMessage("No schema directory found.");
87  $module = $this->getMockBuilder(ExtensionList::class)
88  ->setMethods(['getPathname'])
89  ->disableOriginalConstructor()
90  ->getMockForAbstractClass();
91 
92  $module->method("getPathname")->willReturn("/abcd");
93 
94  $retriever = new SchemaRetriever("/abcd", $module);
95  $retriever->retrieve('dataset');
96  }
97 
98 }
Drupal\Tests\dkan_schema\Unit\SchemaRetrieverTest\testSchemaDirectory
testSchemaDirectory()
Definition: SchemaRetrieverTest.php:20
Drupal\Tests\dkan_schema\Unit
Definition: SchemaRetrieverTest.php:3
Drupal\Tests\dkan_schema\Unit\SchemaRetrieverTest\testError
testError()
Definition: SchemaRetrieverTest.php:69
Drupal\Tests\dkan_schema\Unit\SchemaRetrieverTest\testGetAllIds
testGetAllIds()
Definition: SchemaRetrieverTest.php:36
Drupal\dkan_schema\SchemaRetriever
Definition: SchemaRetriever.php:11
Drupal\Tests\dkan_schema\Unit\SchemaRetrieverTest\testNoDirectory
testNoDirectory()
Definition: SchemaRetrieverTest.php:85
Drupal\Tests\dkan_schema\Unit\SchemaRetrieverTest\testGet
testGet()
Definition: SchemaRetrieverTest.php:52
Drupal\Tests\dkan_schema\Unit\SchemaRetrieverTest
Definition: SchemaRetrieverTest.php:15