Commit 67a58a03 authored by petar.gnjidic's avatar petar.gnjidic Committed by bojanz

Issue #2507003 by petar.gnjidic: Add initial tests for resolvers

parent 4bfdcd6e
<?php
/**
* @file
* Contains \Drupal\Tests\commerce_store\Unit\Resolver\DefaultStoreResolver.
*/
namespace Drupal\Tests\commerce_store\Unit\Resolver;
use Drupal\commerce_store\Resolver\DefaultStoreResolver;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\commerce_store\Resolver\DefaultStoreResolver
* @group commerce_store
*/
class DefaultStoreResolverTest extends UnitTestCase {
/**
* The resolver.
*
* @var \Drupal\commerce_store\Resolver\DefaultStoreResolver
*/
protected $resolver;
/**
* {@inheritdoc}
*/
public function setUp() {
$config = $this->getMockBuilder('Drupal\Core\Config\Config')
->disableOriginalConstructor()
->getMock();
$config->expects($this->once())
->method('get')
->with('default_store')
->will($this->returnValue('fakeuuid'));
$configFactory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
$configFactory->expects($this->once())
->method('get')
->with('commerce_store.settings')
->will($this->returnValue($config));
$entityManager = $this->getMockBuilder('\Drupal\Core\Entity\EntityManager')
->disableOriginalConstructor()
->getMock();
$entityManager->expects($this->once())
->method('loadEntityByUuid')
->with('commerce_store', 'fakeuuid')
->will($this->returnValue('testStore'));
$this->resolver = new DefaultStoreResolver($configFactory, $entityManager);
}
/**
* @covers ::resolve
*/
public function testResolve() {
$defaultStore = $this->resolver->resolve();
$this->assertEquals('testStore', $defaultStore);
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\commerce\Unit\Resolver\DefaultCountryResolverTest.
*/
namespace Drupal\Tests\commerce\Unit\Resolver;
use Drupal\commerce\Resolver\DefaultCountryResolver;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\commerce\Resolver\DefaultCountryResolver
* @group commerce
*/
class DefaultCountryResolverTest extends UnitTestCase {
/**
* The resolver.
*
* @var \Drupal\commerce\Resolver\DefaultCountryResolver
*/
protected $resolver;
/**
* {@inheritdoc}
*/
public function setUp() {
$config = $this->getMockBuilder('Drupal\Core\Config\Config')
->disableOriginalConstructor()
->getMock();
$config->expects($this->once())
->method('get')
->with('country.default')
->will($this->returnValue('RS'));
$configFactory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
$configFactory->expects($this->once())
->method('get')
->with('system.date')
->will($this->returnValue($config));
$this->resolver = new DefaultCountryResolver($configFactory);
}
/**
* @covers ::resolve
*/
public function testResolve() {
$countryCode = $this->resolver->resolve();
$this->assertEquals('RS', $countryCode);
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\commerce\Unit\Resolver\DefaultLocaleResolverTest.
*/
namespace Drupal\Tests\commerce\Unit\Resolver;
use Drupal\commerce\Resolver\DefaultLocaleResolver;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\commerce\Resolver\DefaultLocaleResolver
* @group commerce
*/
class DefaultLocaleResolverTest extends UnitTestCase {
/**
* @covers ::resolve
*/
public function testLanguageCountry() {
$language = $this->getMockBuilder('\Drupal\Core\Language\Language')
->disableOriginalConstructor()
->getMock();
$language->expects($this->once())
->method('getId')
->will($this->returnValue('sr'));
$languageManager = $this->getMockBuilder('\Drupal\Core\Language\LanguageManagerInterface')
->disableOriginalConstructor()
->getMock();
$languageManager->expects($this->once())
->method('getConfigOverrideLanguage')
->will($this->returnValue($language));
$countryContext = $this->getMockBuilder('\Drupal\commerce\CountryContext')
->disableOriginalConstructor()
->getMock();
$countryContext->expects($this->once())
->method('getCountry')
->will($this->returnValue('RS'));
$resolver = new DefaultLocaleResolver($languageManager, $countryContext);
$this->assertEquals('sr-RS', $resolver->resolve());
}
/**
* @covers ::resolve
*/
public function testLanguageWithCountryComponent() {
$language = $this->getMockBuilder('\Drupal\Core\Language\Language')
->disableOriginalConstructor()
->getMock();
$language->expects($this->once())
->method('getId')
->will($this->returnValue('pt-br'));
$languageManager = $this->getMockBuilder('\Drupal\Core\Language\LanguageManagerInterface')
->disableOriginalConstructor()
->getMock();
$languageManager->expects($this->once())
->method('getConfigOverrideLanguage')
->will($this->returnValue($language));
$countryContext = $this->getMockBuilder('\Drupal\commerce\CountryContext')
->disableOriginalConstructor()
->getMock();
$resolver = new DefaultLocaleResolver($languageManager, $countryContext);
$this->assertEquals('pt-br', $resolver->resolve());
}
/**
* @covers ::resolve
*/
public function testUnknownCountry() {
$language = $this->getMockBuilder('\Drupal\Core\Language\Language')
->disableOriginalConstructor()
->getMock();
$language->expects($this->once())
->method('getId')
->will($this->returnValue('sr'));
$languageManager = $this->getMockBuilder('\Drupal\Core\Language\LanguageManagerInterface')
->disableOriginalConstructor()
->getMock();
$languageManager->expects($this->once())
->method('getConfigOverrideLanguage')
->will($this->returnValue($language));
$countryContext = $this->getMockBuilder('\Drupal\commerce\CountryContext')
->disableOriginalConstructor()
->getMock();
$countryContext->expects($this->once())
->method('getCountry')
->will($this->returnValue(NULL));
$resolver = new DefaultLocaleResolver($languageManager, $countryContext);
$this->assertEquals('sr', $resolver->resolve());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment