You are here

public function PageContextTest::setUp in Acquia Lift Connector 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/Service/Context/PageContextTest.php \Drupal\Tests\acquia_lift\Unit\Service\Context\PageContextTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/Service/Context/PageContextTest.php, line 100

Class

PageContextTest
PageContextTest Test.

Namespace

Drupal\Tests\acquia_lift\Unit\Service\Context

Code

public function setUp() {
  parent::setUp();

  // Get config factory mock
  $this->configFactory = $this
    ->createMock('Drupal\\Core\\Config\\ConfigFactoryInterface');

  // Get settings mock
  $this->settings = $this
    ->getMockBuilder('Drupal\\Core\\Config\\ImmutableConfig')
    ->disableOriginalConstructor()
    ->getMock();

  // Get entity manager mock
  $this->entityTypeManager = $this
    ->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');

  // Get taxonomy term mock
  $this->taxonomyTermStorage = $this
    ->createMock('Drupal\\taxonomy\\TermStorageInterface');

  // Get request class mocks
  $this->requestStack = $this
    ->createMock('Symfony\\Component\\HttpFoundation\\RequestStack');
  $this->request = $this
    ->createMock('Symfony\\Component\\HttpFoundation\\Request');
  $this->requestParameterBag = $this
    ->createMock('Symfony\\Component\\HttpFoundation\\ParameterBag');

  // Get route mocks
  $this->routeMatch = $this
    ->createMock('Drupal\\Core\\Routing\\RouteMatchInterface');
  $this->route = $this
    ->getMockBuilder('Symfony\\Component\\Routing\\Route')
    ->disableOriginalConstructor()
    ->getMock();

  // Get title resolver mock
  $this->titleResolver = $this
    ->createMock('Drupal\\Core\\Controller\\TitleResolverInterface');

  // Get language mock
  $this->language = $this
    ->createMock('Drupal\\Core\\Language\\LanguageManagerInterface');

  // Get language object mock
  $this->languageInterface = $this
    ->createMock('Drupal\\Core\\Language\\LanguageInterface');

  // Mock method and return val
  $this->languageInterface
    ->expects($this
    ->any())
    ->method('getId')
    ->willReturn('fr');

  // Mock config factory
  $this->configFactory
    ->expects($this
    ->once())
    ->method('get')
    ->with('acquia_lift.settings')
    ->willReturn($this->settings);

  // Mock settings credential method and return val
  $this->settings
    ->expects($this
    ->at(0))
    ->method('get')
    ->with('credential')
    ->willReturn($this
    ->getValidCredentialSettings());

  // Mock settings field_mapping method and return val
  $this->settings
    ->expects($this
    ->at(1))
    ->method('get')
    ->with('field_mappings')
    ->willReturn($this
    ->getValidFieldMappingsSettings());

  // Mock settings udf_person_mappings method and return val
  $this->settings
    ->expects($this
    ->at(2))
    ->method('get')
    ->with('udf_person_mappings')
    ->willReturn($this
    ->getValidUdfPersonMappingsSettings());

  // Mock settings udf_touch_mappings method and return val
  $this->settings
    ->expects($this
    ->at(3))
    ->method('get')
    ->with('udf_touch_mappings')
    ->willReturn($this
    ->getValidUdfTouchMappingsSettings());

  // Mock settings udf_event_mappings method and return val
  $this->settings
    ->expects($this
    ->at(4))
    ->method('get')
    ->with('udf_event_mappings')
    ->willReturn($this
    ->getValidUdfEventMappingsSettings());

  // Mock settings advanced method and return val
  $this->settings
    ->expects($this
    ->at(5))
    ->method('get')
    ->with('advanced')
    ->willReturn($this
    ->getValidAdvancedSettings());

  // Mock entity type manager getStorage method and return val
  $this->entityTypeManager
    ->expects($this
    ->once())
    ->method('getStorage')
    ->with('taxonomy_term')
    ->willReturn($this->taxonomyTermStorage);

  // Mock request stack's getCurrentRequest method and return val
  $this->requestStack
    ->expects($this
    ->once())
    ->method('getCurrentRequest')
    ->willReturn($this->request);

  // Set param bag
  $this->request->attributes = $this->requestParameterBag;

  // Mock routeMatch getRouteObject method and return val
  $this->routeMatch
    ->expects($this
    ->once())
    ->method('getRouteObject')
    ->willReturn($this->route);
}