/**
  * @covers ::validateCurrencyNumber
  * @dataProvider providerTestValidateCurrencyNumber
  */
 public function testValidateCurrencyNumber($valid, $currency_number, $currency_is_new, $currency_number_exists = FALSE)
 {
     $element = array('#value' => $currency_number);
     $form = array();
     $form_state = $this->getMock(FormStateInterface::class);
     $this->currency->expects($this->any())->method('isNew')->willReturn($currency_is_new);
     if (!$valid) {
         $form_state->expects($this->once())->method('setError')->with($element, 'The currency number must be three digits.');
     } elseif ($currency_number_exists) {
         $loaded_currency_code = $this->randomMachineName();
         $loaded_currency_label = $this->randomMachineName();
         $loaded_currency_url = new Url($this->randomMachineName());
         $loaded_currency = $this->getMock(CurrencyInterface::class);
         $loaded_currency->expects($this->any())->method('id')->willReturn($loaded_currency_code);
         $loaded_currency->expects($this->any())->method('label')->willReturn($loaded_currency_label);
         $loaded_currency->expects($this->atLeastOnce())->method('urlInfo')->willReturn($loaded_currency_url);
         $this->currencyStorage->expects($this->once())->method('loadByProperties')->with(array('currencyNumber' => $currency_number))->willReturn(array($loaded_currency));
         $form_state->expects($this->once())->method('setError');
         $this->linkGenerator->expects($this->once())->method('generate')->with($loaded_currency_label, $loaded_currency_url);
     } else {
         $this->currencyStorage->expects($this->once())->method('loadByProperties')->with(array('currencyNumber' => $currency_number))->willReturn(FALSE);
         $form_state->expects($this->never())->method('setError');
         $form_state->expects($this->never())->method('setErrorByName');
     }
     $this->sut->validateCurrencyNumber($element, $form_state, $form);
 }
 /**
  * @covers ::link
  *
  * @dataProvider providerTestLink
  */
 public function testLink($entity_label, $link_text, $expected_text, $link_rel = 'canonical', array $link_options = [])
 {
     $route_name_map = ['canonical' => 'entity.test_entity_type.canonical', 'edit-form' => 'entity.test_entity_type.edit_form'];
     $route_name = $route_name_map[$link_rel];
     $entity_id = 'test_entity_id';
     $entity_type_id = 'test_entity_type';
     $expected = '<a href="/test_entity_type/test_entity_id">' . $expected_text . '</a>';
     $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $entity_type->expects($this->once())->method('getLinkTemplates')->willReturn($route_name_map);
     $entity_type->expects($this->any())->method('getKey')->with('label')->willReturn('label');
     $this->entityManager->expects($this->any())->method('getDefinition')->with($entity_type_id)->will($this->returnValue($entity_type));
     /** @var \Drupal\Core\Entity\Entity $entity */
     $entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', [['id' => $entity_id, 'label' => $entity_label], $entity_type_id]);
     $expected_link = Link::createFromRoute($expected_text, $route_name, [$entity_type_id => $entity_id], ['entity_type' => $entity_type_id, 'entity' => $entity] + $link_options)->setLinkGenerator($this->linkGenerator);
     $this->linkGenerator->expects($this->once())->method('generateFromLink')->with($this->equalTo($expected_link))->willReturn($expected);
     $this->assertSame($expected, $entity->link($link_text, $link_rel, $link_options));
 }
 /**
  * Setup the link generator with a frontpage route.
  */
 public function setupLinkGeneratorWithFrontpage()
 {
     $this->linkGenerator->expects($this->once())->method('generate')->with($this->anything(), '<front>', array())->will($this->returnCallback(function ($title) {
         return '<a href="/">' . $title . '</a>';
     }));
 }