Commit 6614f6c4 authored by martin_t's avatar martin_t Committed by bojanz

Issue #2529958 by taleski: Add Resolver Tests

parent 66d6222f
<?php
/**
* @file
* Contains \Drupal\Tests\commerce_store\Unit\Resolver\ChainStoreResolverTest.
*/
namespace Drupal\Tests\commerce_store\Unit\Resolver;
use Drupal\commerce_store\Resolver\ChainStoreResolver;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\commerce_store\Resolver\ChainStoreResolver
* @group commerce_store
*/
class ChainStoreResolverTest extends UnitTestCase {
/**
* The resolver.
*
* @var \Drupal\commerce_store\Resolver\ChainStoreResolver
*/
protected $resolver;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->resolver = new ChainStoreResolver();
}
/**
* ::covers addResolver
* ::covers getResolvers
* ::covers resolve
*/
public function testResolver() {
$mockupBuilder = $this->getMockBuilder('Drupal\commerce_store\Resolver\StoreResolverInterface')
->disableOriginalConstructor();
$firstResolver = $mockupBuilder->getMock();
$firstResolver->expects($this->once())
->method('resolve');
$secondResolver = $mockupBuilder->getMock();
$secondResolver->expects($this->once())
->method('resolve')
->willReturn('testStore');
$thirdResolver = $mockupBuilder->getMock();
$thirdResolver->expects($this->never())
->method('resolve');
$this->resolver->addResolver($firstResolver);
$this->resolver->addResolver($secondResolver);
$this->resolver->addResolver($thirdResolver);
$resolvers = $this->resolver->getResolvers();
$this->assertEquals([$firstResolver, $secondResolver, $thirdResolver], $resolvers);
$result = $this->resolver->resolve();
$this->assertEquals('testStore', $result);
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\commerce\Unit\Resolver\ChainCountryResolverTest.
*/
namespace Drupal\Tests\commerce\Unit\Resolver;
use Drupal\commerce\Resolver\ChainCountryResolver;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass Drupal\commerce\Resolver\ChainCountryResolver
* @group commerce
*/
class ChainCountryResolverTest extends UnitTestCase {
/**
* @var \Drupal\commerce\Resolver\ChainCountryResolver
*/
protected $chainCountryResolver;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->chainCountryResolver = new ChainCountryResolver();
}
/**
* ::covers addResolver
* ::covers getResolvers
* ::covers resolve
*/
public function testResolver() {
$mockupBuilder = $this->getMockBuilder('Drupal\commerce\Resolver\CountryResolverInterface')
->disableOriginalConstructor();
$firstResolver = $mockupBuilder->getMock();
$firstResolver->expects($this->once())
->method('resolve');
$secondResolver = $mockupBuilder->getMock();
$secondResolver->expects($this->once())
->method('resolve')
->willReturn('RS');
$thirdResolver = $mockupBuilder->getMock();
$thirdResolver->expects($this->never())
->method('resolve');
$this->chainCountryResolver->addResolver($firstResolver);
$this->chainCountryResolver->addResolver($secondResolver);
$this->chainCountryResolver->addResolver($thirdResolver);
$resolvers = $this->chainCountryResolver->getResolvers();
$this->assertEquals([$firstResolver, $secondResolver, $thirdResolver], $resolvers);
$result = $this->chainCountryResolver->resolve();
$this->assertEquals('RS', $result);
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\commerce\Unit\Resolver\ChainLocaleResolverTest.
*/
namespace Drupal\Tests\commerce\Unit\Resolver;
use Drupal\commerce\Resolver\ChainLocaleResolver;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass Drupal\commerce\Resolver\ChainLocaleResolver
* @group commerce
*/
class ChainLocaleResolverTest extends UnitTestCase {
/**
* @var \Drupal\commerce\Resolver\ChainLocaleResolver
*/
protected $chainLocaleResolver;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->chainLocaleResolver = new ChainLocaleResolver();
}
/**
* ::covers addResolver
* ::covers getResolvers
* ::covers resolve
*/
public function testResolver() {
$mockBuilder = $this->getMockBuilder('Drupal\commerce\Resolver\LocaleResolverInterface')
->disableOriginalConstructor();
$firstResolver = $mockBuilder->getMock();
$firstResolver->expects($this->once())
->method('resolve');
$secondResolver = $mockBuilder->getMock();
$secondResolver->expects($this->once())
->method('resolve')
->willReturn('mk_MK');
$thirdResolver = $mockBuilder->getMock();
$thirdResolver->expects($this->never())
->method('resolve');
$this->chainLocaleResolver->addResolver($firstResolver);
$this->chainLocaleResolver->addResolver($secondResolver);
$this->chainLocaleResolver->addResolver($thirdResolver);
$resolvers = $this->chainLocaleResolver->getResolvers();
$this->assertEquals([$firstResolver, $secondResolver, $thirdResolver], $resolvers);
$result = $this->chainLocaleResolver->resolve();
$this->assertEquals('mk_MK', $result);
}
}
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