Skip to content

Commit

Permalink
Add unit test and refactor fixtures #39
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Jan 27, 2017
1 parent fcd40c3 commit 0cf8bb1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Element/PatternPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static function processFields(array $element) {
* @return array|\Drupal\Component\Render\MarkupInterface|string
* Preview safe markup.
*/
protected static function getPreviewMarkup($preview) {
public static function getPreviewMarkup($preview) {
if (is_array($preview)) {
$rendered = [];
// If preview is a render array add hashes to keys.
Expand Down
30 changes: 30 additions & 0 deletions tests/src/PhpUnit/PatternPreviewTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Drupal\ui_patterns\Tests\Unit;

use function bovigo\assert\assert;
use function bovigo\assert\predicate\equals;
use Drupal\Component\Serialization\Yaml;
use Drupal\ui_patterns\Element\PatternPreview;

/**
* @coversDefaultClass \Drupal\ui_patterns\Element\PatternPreview
*
* @group ui_patterns
*/
class PatternPreviewTest extends AbstractUiPatternsTest {

/**
* Test getPreviewMarkup.
*
* @covers ::getPreviewMarkup
*/
public function testPreviewMarkup() {
$assertions = Yaml::decode(file_get_contents(dirname(__FILE__) . '/fixtures/preview_markup.yml'));
foreach ($assertions as $assertion) {
$result = PatternPreview::getPreviewMarkup($assertion['actual']);
assert($assertion['expected'], equals($result));
}
}

}
2 changes: 1 addition & 1 deletion tests/src/PhpUnit/UiPatternsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testProcessDefinition($id, array $expected) {
*/
public function testValidation() {
$validation = new UiPatternsValidation();
$definitions = Yaml::decode(file_get_contents(dirname(__FILE__) . '/bad_definitions.ui_patterns.yml'));
$definitions = Yaml::decode(file_get_contents(dirname(__FILE__) . '/fixtures/validation.yml'));
foreach ($definitions as $definition) {
try {
$validation->validate($definition);
Expand Down
15 changes: 15 additions & 0 deletions tests/src/PhpUnit/fixtures/preview_markup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-
actual:
type: pattern
id: image
fields:
image:
theme: image
uri: http://lorempixel.com/400/200/nature/2
expected:
'#type': pattern
'#id': image
'#fields':
image:
'#theme': image
'#uri': http://lorempixel.com/400/200/nature/2
File renamed without changes.

0 comments on commit 0cf8bb1

Please sign in to comment.