Skip to content
Snippets Groups Projects
Commit 3619d82e authored by bircher's avatar bircher Committed by Karoly Negyesi
Browse files

Added unit tests for writeBackConfig #2300717 by bircher

parent 134c786f
Branches
Tags 8.x-1.0-alpha14
No related merge requests found
<?php
/**
* @file
* Contains \Drupal\config_devel\Tests\ConfigDevelAutoExportSubscriberTest.
*/
namespace Drupal\config_devel\Tests;
use org\bovigo\vfs\vfsStream;
use Drupal\Component\Serialization\Yaml;
use Drupal\config_devel\EventSubscriber\ConfigDevelAutoExportSubscriber;
/**
* @coversDefaultClass \Drupal\config_devel\EventSubscriber\ConfigDevelAutoExportSubscriber
* @group config_devel
*/
class ConfigDevelAutoExportSubscriberTest extends ConfigDevelTestBase {
/**
* Test ConfigDevelAutoExportSubscriber::writeBackConfig().
*/
public function testWriteBackConfig() {
$config_data = array(
'id' => $this->randomName(),
'langcode' => 'en',
'uuid' => '836769f4-6791-402d-9046-cc06e20be87f',
);
$config = $this->getMockBuilder('\Drupal\Core\Config\Config')
->disableOriginalConstructor()
->getMock();
$config->expects($this->any())
->method('getName')
->will($this->returnValue($this->randomName()));
$config->expects($this->any())
->method('get')
->will($this->returnValue($config_data));
$file_names = array(
vfsStream::url('public://' . $this->randomName() . '.yml'),
vfsStream::url('public://' . $this->randomName() . '.yml'),
);
$configDevelSubscriber = new ConfigDevelAutoExportSubscriber($this->configFactory, $this->configManager, $this->fileStorage);
$configDevelSubscriber->writeBackConfig($config, $file_names);
$data = $config_data;
unset($data['uuid']);
foreach ($file_names as $file_name) {
$this->assertEquals($data, Yaml::decode(file_get_contents($file_name)));
}
}
}
<?php
/**
* @file
* Contains \Drupal\config_devel\Tests\ConfigDevelTestBase.
*/
namespace Drupal\config_devel\Tests;
use org\bovigo\vfs\vfsStream;
use Drupal\Tests\UnitTestCase;
/**
* Helper class with mock objects.
*/
abstract class ConfigDevelTestBase extends UnitTestCase {
/**
* @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configFactory;
/**
* @var \Drupal\Core\Config\ConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configManager;
/**
* @var \Drupal\Core\Config\FileStorage|\PHPUnit_Framework_MockObject_MockObject
*/
protected $fileStorage;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->configFactory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
$this->configManager = $this->getMock('Drupal\Core\Config\ConfigManagerInterface');
$this->configManager->expects($this->any())
->method('getEntityTypeIdByName')
->will($this->returnArgument(0));
$this->fileStorage = $this->getMockBuilder('Drupal\Core\Config\FileStorage')
->disableOriginalConstructor()
->getMock();
$this->fileStorage->expects($this->any())
->method('encode')
->will($this->returnCallback('Drupal\Component\Serialization\Yaml::encode'));
vfsStream::setup('public://');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment