Skip to content
Snippets Groups Projects
Commit 4e5a96f8 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2082735 by damiankloip: Unit test Drupal\serialization\Normalizer\TypedDataNormalizer class.

parent 034d9569
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?php
/**
* @file
* Contains \Drupal\serialization\Tests\Normalizer\TypedDataNormalizerTest
*/
namespace Drupal\serialization\Tests\Normalizer;
use Drupal\Tests\UnitTestCase;
use Drupal\serialization\Normalizer\TypedDataNormalizer;
/**
* Tests the TypedDataNormalizer class.
*
* @see \Drupal\serialization\Normalizer\TypedDataNormalizer
*
* @group Drupal
*/
class TypedDataNormalizerTest extends UnitTestCase {
/**
* The TypedDataNormalizer instance.
*
* @var \Drupal\serialization\Normalizer\TypedDataNormalizer
*/
protected $normalizer;
/**
* The mock typed data instance.
*
* @var \Drupal\Core\TypedData\TypedDataInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $typedData;
public static function getInfo() {
return array(
'name' => 'TypedDataNormalizer',
'description' => 'Tests the TypedDataNormalizer class.',
'group' => 'Serialization',
);
}
public function setUp() {
$this->normalizer = new TypedDataNormalizer();
$this->typedData = $this->getMock('Drupal\Core\TypedData\TypedDataInterface');
}
/**
* Tests the supportsNormalization() method.
*/
public function testSupportsNormalization() {
$this->assertTrue($this->normalizer->supportsNormalization($this->typedData));
// Also test that an object not implementing TypedDataInterface fails.
$this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
}
/**
* Tests the normalize() method.
*/
public function testNormalize() {
$this->typedData->expects($this->once())
->method('getValue')
->will($this->returnValue('test'));
$this->assertEquals('test', $this->normalizer->normalize($this->typedData));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment