当前位置: 首页>>代码示例>>PHP>>正文


PHP UrlGeneratorInterface::expects方法代码示例

本文整理汇总了PHP中Drupal\Core\Routing\UrlGeneratorInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlGeneratorInterface::expects方法的具体用法?PHP UrlGeneratorInterface::expects怎么用?PHP UrlGeneratorInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Routing\UrlGeneratorInterface的用法示例。


在下文中一共展示了UrlGeneratorInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setupUrlGenerator

 protected function setupUrlGenerator()
 {
     $this->urlGenerator->expects($this->any())->method('generateFromRoute')->willReturnCallback(function ($route, $parameters, $options) {
         $query_string = '';
         if (!empty($options['query'])) {
             $query_string = '?' . $options['query'];
         }
         return '/current-path' . $query_string;
     });
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:RedirectDestinationTest.php

示例2: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->eventDispatcher = $this->getMock(EventDispatcherInterface::class);
     $this->entityManager = $this->getMock(EntityManagerInterface::class);
     $this->urlGenerator = $this->getMock(UrlGeneratorInterface::class);
     $this->urlGenerator->expects($this->any())->method('generateFromRoute')->willReturn('http://example.com');
     $this->stringTranslation = $this->getStringTranslationStub();
     $this->payment = $this->getMock(PaymentInterface::class);
     $this->sut = new PaymentReference([], 'payment_reference', [], $this->eventDispatcher, $this->urlGenerator, $this->entityManager, $this->stringTranslation);
     $this->sut->setPayment($this->payment);
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:14,代码来源:PaymentReferenceTest.php

示例3: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
     $this->urlGenerator->expects($this->any())->method('generateFromPath')->will($this->returnArgument(0));
     $this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface');
     $container = new ContainerBuilder();
     $container->set('router', $this->router);
     $container->set('url_generator', $this->urlGenerator);
     \Drupal::setContainer($container);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:14,代码来源:ExternalUrlTest.php

示例4: testExecute

 /**
  * @covers ::execute
  */
 public function testExecute()
 {
     $url = $this->randomMachineName();
     $currency = $this->getMock(CurrencyInterface::class);
     $currency->expects($this->once())->method('enable');
     $currency->expects($this->once())->method('save');
     $this->urlGenerator->expects($this->once())->method('generateFromRoute')->with('entity.currency.collection')->willReturn($url);
     $response = $this->sut->execute($currency);
     $this->assertInstanceOf(RedirectResponse::class, $response);
     $this->assertSame($url, $response->getTargetUrl());
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:14,代码来源:EnableCurrencyTest.php

示例5: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $map = array();
     $map[] = array('view.frontpage.page_1', array(), array(), '/node');
     $map[] = array('node_view', array('node' => '1'), array(), '/node/1');
     $map[] = array('node_edit', array('node' => '2'), array(), '/node/2/edit');
     $this->map = $map;
     $this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
     $this->urlGenerator->expects($this->any())->method('generateFromRoute')->will($this->returnValueMap($this->map));
     $this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface');
     $container = new ContainerBuilder();
     $container->set('router', $this->router);
     $container->set('url_generator', $this->urlGenerator);
     \Drupal::setContainer($container);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:19,代码来源:UrlTest.php

示例6: assertRedirectedToFrontPageOnHandle

 /**
  * Assert user redirected to homepage when controller invoked.
  */
 private function assertRedirectedToFrontPageOnHandle()
 {
     // URL Generator will generate a path to the homepage.
     $this->urlGenerator->expects($this->once())->method('generate')->with('<front>')->will($this->returnValue('http://example.com/front'));
     $response = $this->serviceController->handle();
     $this->assertTrue($response->isRedirect('http://example.com/front'));
 }
开发者ID:pulibrary,项目名称:recap,代码行数:10,代码来源:ServiceControllerTest.php

示例7: testRedirectWithoutResult

 /**
  * Tests the redirectForm() method when no redirect is expected.
  *
  * @covers ::redirectForm
  *
  * @dataProvider providerTestRedirectWithoutResult
  */
 public function testRedirectWithoutResult($form_state)
 {
     $form_submitter = $this->getFormSubmitter();
     $this->urlGenerator->expects($this->never())->method('generateFromPath');
     $this->urlGenerator->expects($this->never())->method('generateFromRoute');
     $form_state += $this->getFormStateDefaults();
     $redirect = $form_submitter->redirectForm($form_state);
     $this->assertNull($redirect);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:16,代码来源:FormSubmitterTest.php

示例8: testGetServerLogoutUrlFrontPage

 /**
  * Test generating the logout url with front page specified.
  *
  * @covers ::getServerLogoutUrl
  */
 public function testGetServerLogoutUrlFrontPage()
 {
     $config_factory = $this->getConfigFactoryStub(array('cas.settings' => array('logout.logout_destination' => '<front>')));
     $cas_helper = $this->getMockBuilder('\\Drupal\\cas\\Service\\CasHelper')->setConstructorArgs(array($config_factory, $this->urlGenerator, $this->connection, $this->loggerFactory, $this->session))->setMethods(array('getServerBaseUrl'))->getMock();
     $cas_helper->expects($this->once())->method('getServerBaseUrl')->will($this->returnValue('https://example.com/'));
     $request = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $this->urlGenerator->expects($this->once())->method('generate')->will($this->returnValue('https://example.com/frontpage'));
     $this->assertEquals('https://example.com/logout?service=https%3A//example.com/frontpage', $cas_helper->getServerLogoutUrl($request));
 }
开发者ID:pulibrary,项目名称:recap,代码行数:14,代码来源:CasHelperTest.php

示例9: testInvalidEntityUriParameter

  /**
   * Tests the fromUri() method with an invalid entity: URI.
   *
   * @covers ::fromUri
   * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
   */
  public function testInvalidEntityUriParameter() {
    // Make the mocked URL generator behave like the actual one.
    $this->urlGenerator->expects($this->once())
      ->method('generateFromRoute')
      ->with('entity.test_entity.canonical', ['test_entity' => '1/blah'])
      ->willThrowException(new InvalidParameterException('Parameter "test_entity" for route "/test_entity/{test_entity}" must match "[^/]++" ("1/blah" given) to generate a corresponding URL..'));

    Url::fromUri('entity:test_entity/1/blah')->toString();
  }
开发者ID:jthoresen,项目名称:PladsenDrupal,代码行数:15,代码来源:UrlTest.php

示例10: testRedirectWithoutResult

 /**
  * Tests the redirectForm() method when no redirect is expected.
  *
  * @covers ::redirectForm
  */
 public function testRedirectWithoutResult()
 {
     $form_submitter = $this->getFormSubmitter();
     $this->urlGenerator->expects($this->never())->method('generateFromPath');
     $this->urlGenerator->expects($this->never())->method('generateFromRoute');
     $form_state = $this->getMock('Drupal\\Core\\Form\\FormStateInterface');
     $form_state->expects($this->once())->method('getRedirect')->willReturn(FALSE);
     $redirect = $form_submitter->redirectForm($form_state);
     $this->assertNull($redirect);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:15,代码来源:FormSubmitterTest.php

示例11: testGetSystemPath

 /**
  * Tests the getPathByAlias() method.
  *
  * @covers ::getSystemPath
  */
 public function testGetSystemPath()
 {
     $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $entity_type->expects($this->any())->method('getLinkTemplates')->will($this->returnValue(array('canonical' => 'entity.test_entity_type.canonical')));
     $this->entityManager->expects($this->any())->method('getDefinition')->with('test_entity_type')->will($this->returnValue($entity_type));
     $no_link_entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'));
     $this->assertSame('', $no_link_entity->getSystemPath('banana'));
     $this->urlGenerator->expects($this->once())->method('getPathFromRoute')->with('entity.test_entity_type.canonical', array('test_entity_type' => 'test_entity_id'))->will($this->returnValue('entity/test_entity_type/test_entity_id'));
     $valid_entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'));
     $this->assertSame('entity/test_entity_type/test_entity_id', $valid_entity->getSystemPath());
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:16,代码来源:EntityUrlTest.php

示例12: testRedirectWithoutResult

 /**
  * Tests the redirectForm() method when no redirect is expected.
  *
  * @covers ::redirectForm
  */
 public function testRedirectWithoutResult()
 {
     $form_submitter = $this->getFormSubmitter();
     $this->urlGenerator->expects($this->never())->method('generateFromRoute');
     $this->unroutedUrlAssembler->expects($this->never())->method('assemble');
     $container = new ContainerBuilder();
     $container->set('url_generator', $this->urlGenerator);
     $container->set('unrouted_url_assembler', $this->unroutedUrlAssembler);
     \Drupal::setContainer($container);
     $form_state = $this->getMock('Drupal\\Core\\Form\\FormStateInterface');
     $form_state->expects($this->once())->method('getRedirect')->willReturn(FALSE);
     $redirect = $form_submitter->redirectForm($form_state);
     $this->assertNull($redirect);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:19,代码来源:FormSubmitterTest.php

示例13: testRenderAsLinkWithUrlAndOptions

 /**
  * Tests link rendering with a URL and options.
  *
  * @dataProvider providerTestRenderAsLinkWithUrlAndOptions
  * @covers ::renderAsLink
  */
 public function testRenderAsLinkWithUrlAndOptions(Url $url, $alter, Url $expected_url, $url_path, Url $expected_link_url, $link_html, $final_html = NULL)
 {
     $alter += ['make_link' => TRUE, 'url' => $url];
     $final_html = isset($final_html) ? $final_html : $link_html;
     $this->setUpUrlIntegrationServices();
     $this->setupDisplayWithEmptyArgumentsAndFields();
     $field = $this->setupTestField(['alter' => $alter]);
     $field->field_alias = 'key';
     $row = new ResultRow(['key' => 'value']);
     $expected_url->setOptions($expected_url->getOptions() + $this->defaultUrlOptions);
     $expected_link_url->setUrlGenerator($this->urlGenerator);
     $expected_url_options = $expected_url->getOptions();
     unset($expected_url_options['attributes']);
     $this->urlGenerator->expects($this->once())->method('generateFromRoute')->with($expected_url->getRouteName(), $expected_url->getRouteParameters(), $expected_url_options)->willReturn($url_path);
     $result = $field->advancedRender($row);
     $this->assertEquals($final_html, $result);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:23,代码来源:FieldPluginBaseTest.php

示例14: testUrl

 /**
  * Tests the url() method.
  *
  * @covers ::url
  */
 public function testUrl()
 {
     $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $entity_type->expects($this->any())->method('getLinkTemplates')->will($this->returnValue(array('canonical' => 'test_entity_type.view')));
     $this->entityManager->expects($this->any())->method('getDefinition')->with('test_entity_type')->will($this->returnValue($entity_type));
     $invalid_entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(array(), 'test_entity_type'));
     $this->assertSame('', $invalid_entity->url());
     $no_link_entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'));
     $this->assertSame('', $no_link_entity->url('banana'));
     $valid_entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'));
     $language = new Language(array('id' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->urlGenerator->expects($this->any())->method('generateFromRoute')->willReturnCallback(function ($route_name, $route_parameters, $options) use($language) {
         if ($route_name === 'entity.test_entity_type.canonical' && $route_parameters === array('test_entity_type' => 'test_entity_id') && array_keys($options) === ['entity_type', 'entity', 'language'] && $options['language'] == $language) {
             return '/entity/test_entity_type/test_entity_id';
         }
         if ($route_name === 'entity.test_entity_type.canonical' && $route_parameters === array('test_entity_type' => 'test_entity_id') && array_keys($options) === ['absolute', 'entity_type', 'entity', 'language'] && $options['language'] == $language) {
             return 'http://drupal/entity/test_entity_type/test_entity_id';
         }
     });
     $this->assertSame('/entity/test_entity_type/test_entity_id', $valid_entity->url());
     $this->assertSame('http://drupal/entity/test_entity_type/test_entity_id', $valid_entity->url('canonical', array('absolute' => TRUE)));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:27,代码来源:EntityUrlTest.php

示例15: testOverview

 /**
  * @covers ::overview
  */
 public function testOverview()
 {
     $currency_code_from = 'EUR';
     $currency_code_to = 'NLG';
     $rate = '2.20371';
     $currency_from = $this->getMock(CurrencyInterface::class);
     $currency_from->expects($this->once())->method('label');
     $currency_to = $this->getMock(CurrencyInterface::class);
     $currency_to->expects($this->once())->method('label');
     $map = array(array($currency_code_from, $currency_from), array($currency_code_to, $currency_to));
     $this->currencyStorage->expects($this->any())->method('load')->willReturnMap($map);
     $rates_configuration = array($currency_code_from => array($currency_code_to => $rate));
     $fixed_rates = $this->getMockBuilder(FixedRates::class)->disableOriginalConstructor()->getMock();
     $fixed_rates->expects($this->once())->method('loadAll')->willReturn($rates_configuration);
     $this->currencyExchangeRateProviderManager->expects($this->once())->method('createInstance')->with('currency_fixed_rates')->willReturn($fixed_rates);
     $this->urlGenerator->expects($this->once())->method('generateFromRoute')->with('currency.exchange_rate_provider.fixed_rates.add');
     $amount_formatter = $this->getMock(AmountFormatterInterface::class);
     $amount_formatter->expects($this->once())->method('formatAmount')->with($currency_to, $rate);
     $this->currencyAmountFormatterManager->expects($this->once())->method('getDefaultPlugin')->willReturn($amount_formatter);
     $build = $this->sut->overview();
     $this->assertInternalType('array', $build);
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:25,代码来源:FixedRatesOverviewTest.php


注:本文中的Drupal\Core\Routing\UrlGeneratorInterface::expects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。