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


PHP AccountInterface::expects方法代码示例

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


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

示例1: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $cache_contexts_manager = $this->prophesize(CacheContextsManager::class);
     $cache_contexts_manager->assertValidTokens()->willReturn(TRUE);
     $cache_contexts_manager->reveal();
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
     $this->viewer = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $this->viewer->expects($this->any())->method('hasPermission')->will($this->returnValue(FALSE));
     $this->viewer->expects($this->any())->method('id')->will($this->returnValue(1));
     $this->owner = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $this->owner->expects($this->any())->method('hasPermission')->will($this->returnValueMap(array(array('administer users', FALSE), array('change own username', TRUE))));
     $this->owner->expects($this->any())->method('id')->will($this->returnValue(2));
     $this->admin = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $this->admin->expects($this->any())->method('hasPermission')->will($this->returnValue(TRUE));
     $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->accessControlHandler = new UserAccessControlHandler($entity_type);
     $module_handler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $module_handler->expects($this->any())->method('getImplementations')->will($this->returnValue(array()));
     $this->accessControlHandler->setModuleHandler($module_handler);
     $this->items = $this->getMockBuilder('Drupal\\Core\\Field\\FieldItemList')->disableOriginalConstructor()->getMock();
     $this->items->expects($this->any())->method('defaultAccess')->will($this->returnValue(AccessResult::allowed()));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:28,代码来源:UserAccessControlHandlerTest.php

示例2: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->storage = $this->getMock('Drupal\\locale\\StringStorageInterface');
     $this->cache = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
     $this->lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
     $this->lock->expects($this->never())->method($this->anything());
     $this->user = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $this->user->expects($this->any())->method('getRoles')->will($this->returnValue(array('anonymous')));
     $this->configFactory = $this->getConfigFactoryStub(array('locale.settings' => array('cache_strings' => FALSE)));
     $this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
     $container = new ContainerBuilder();
     $container->set('current_user', $this->user);
     \Drupal::setContainer($container);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:17,代码来源:LocaleLookupTest.php

示例3: testSetCacheAuthUser

  /**
   * @covers ::setCache
   */
  public function testSetCacheAuthUser() {
    $form_build_id = 'the_form_build_id';
    $form = [];
    $form_state = new FormState();

    $cache_token = 'the_cache_token';
    $form_data = $form;
    $form_data['#cache_token'] = $cache_token;
    $this->formCacheStore->expects($this->once())
      ->method('setWithExpire')
      ->with($form_build_id, $form_data, $this->isType('int'));

    $form_state_data = $form_state->getCacheableArray();
    $form_state_data['build_info']['safe_strings'] = [];
    $this->formStateCacheStore->expects($this->once())
      ->method('setWithExpire')
      ->with($form_build_id, $form_state_data, $this->isType('int'));

    $this->csrfToken->expects($this->once())
      ->method('get')
      ->willReturn($cache_token);
    $this->account->expects($this->once())
      ->method('isAuthenticated')
      ->willReturn(TRUE);

    $this->formCache->setCache($form_build_id, $form, $form_state);
  }
开发者ID:komejo,项目名称:article-test,代码行数:30,代码来源:FormCacheTest.php

示例4: testGetUrlIfValidWithoutAccess

 /**
  * Tests the getUrlIfValid() method where there is no access.
  */
 public function testGetUrlIfValidWithoutAccess()
 {
     $this->account->expects($this->once())->method('hasPermission')->with('link to any page')->willReturn(FALSE);
     $this->accessAwareRouter->expects($this->once())->method('match')->with('/test-path')->willThrowException(new AccessDeniedHttpException());
     $this->pathProcessor->expects($this->once())->method('processInbound')->willReturnArgument(0);
     $url = $this->pathValidator->getUrlIfValid('test-path');
     $this->assertFalse($url);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:11,代码来源:PathValidatorTest.php

示例5: testGetUrlIfValidWithoutAccessCheck

 /**
  * Tests the getUrlIfValidWithoutAccessCheck() method.
  *
  * @covers ::getUrlIfValidWithoutAccessCheck
  */
 public function testGetUrlIfValidWithoutAccessCheck()
 {
     $this->account->expects($this->never())->method('hasPermission')->with('link to any page');
     $this->accessAwareRouter->expects($this->never())->method('match');
     $this->accessUnawareRouter->expects($this->once())->method('match')->with('/test-path')->willReturn([RouteObjectInterface::ROUTE_NAME => 'test_route', '_raw_variables' => new ParameterBag(['key' => 'value'])]);
     $this->pathProcessor->expects($this->once())->method('processInbound')->willReturnArgument(0);
     $url = $this->pathValidator->getUrlIfValidWithoutAccessCheck('test-path');
     $this->assertInstanceOf('Drupal\\Core\\Url', $url);
     $this->assertEquals('test_route', $url->getRouteName());
     $this->assertEquals(['key' => 'value'], $url->getRouteParameters());
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:16,代码来源:PathValidatorTest.php

示例6: testHandleIsAuthenticated

 /**
  * Test backing out when user is authenticated.
  *
  * @covers ::handle
  * @covers ::__construct
  */
 public function testHandleIsAuthenticated()
 {
     $config_factory = $this->getConfigFactoryStub();
     $cas_subscriber = $this->getMockBuilder('\\Drupal\\cas\\Subscriber\\CasSubscriber')->setConstructorArgs(array($this->requestStack, $this->routeMatcher, $config_factory, $this->currentUser, $this->conditionManager, $this->casHelper))->setMethods(NULL)->getMock();
     $this->event->expects($this->any())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
     $this->currentUser->expects($this->once())->method('isAuthenticated')->will($this->returnValue(TRUE));
     $cas_subscriber->expects($this->never())->method('isIgnoreableRoute');
     $cas_subscriber->expects($this->never())->method('IsCrawlerRequest');
     $cas_subscriber->expects($this->never())->method('handleForcedPath');
     $cas_subscriber->expects($this->never())->method('handleGateway');
     $cas_subscriber->handle($this->event);
 }
开发者ID:pulibrary,项目名称:recap,代码行数:18,代码来源:CasSubscriberTest.php

示例7: testValidateArgument

 /**
  * @covers ::validateArgument
  *
  * @dataProvider providerValidateArgument
  */
 public function testValidateArgument($expected_validity, $argument, $current_user_id, array $permissions)
 {
     $entity = $this->getMock(EntityInterface::class);
     $entity_storage = $this->getMock(EntityStorageInterface::class);
     $entity_storage->expects($this->atLeastOnce())->method('loadMultiple')->willReturn([7 => $entity, 9 => $entity]);
     $this->entityManager->expects($this->atLeastOnce())->method('getStorage')->with($this->pluginDefinition['entity_type'])->willReturn($entity_storage);
     $this->currentUser->expects($this->any())->method('id')->willReturn($current_user_id);
     $map = [];
     foreach ($permissions as $permission) {
         $map[] = [$permission, TRUE];
     }
     $this->currentUser->expects($this->any())->method('hasPermission')->willReturnMap($map);
     $this->assertSame($expected_validity, $this->sut->validateArgument($argument));
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:19,代码来源:ViewPaymentsByOwnerTest.php

示例8: testCheckAccessWithLinkToAnyPagePermission

 /**
  * Tests checkAccess() tree manipulator with 'link to any page' permission.
  *
  * @covers ::checkAccess
  * @covers ::menuLinkCheckAccess
  */
 public function testCheckAccessWithLinkToAnyPagePermission()
 {
     $this->mockTree();
     $this->currentUser->expects($this->exactly(8))->method('hasPermission')->with('link to any page')->willReturn(TRUE);
     $this->mockTree();
     $this->defaultMenuTreeManipulators->checkAccess($this->originalTree);
     $this->assertTrue($this->originalTree[1]->access);
     $this->assertTrue($this->originalTree[2]->access);
     $this->assertTrue($this->originalTree[2]->subtree[3]->access);
     $this->assertTrue($this->originalTree[2]->subtree[3]->subtree[4]->access);
     $this->assertTrue($this->originalTree[5]->subtree[7]->access);
     $this->assertTrue($this->originalTree[6]->access);
     $this->assertTrue($this->originalTree[8]->access);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:20,代码来源:DefaultMenuLinkTreeManipulatorsTest.php

示例9: testExecute

 /**
  * @covers ::execute
  */
 public function testExecute()
 {
     $definitions = ['foo' => ['label' => $this->randomMachineName(), 'description' => $this->randomMachineName()], 'bar' => ['label' => $this->randomMachineName()], 'payment_unavailable' => []];
     $operations_foo = ['baz' => ['title' => $this->randomMachineName()]];
     $operations_provider_foo = $this->getMock(PluginOperationsProviderInterface::class);
     $operations_provider_foo->expects($this->once())->method('getOperations')->with('foo')->willReturn($operations_foo);
     $this->paymentTypeManager->expects($this->once())->method('getDefinitions')->willReturn($definitions);
     $map = [['foo', $operations_provider_foo], ['bar', NULL]];
     $this->paymentTypeManager->expects($this->exactly(2))->method('getOperationsProvider')->willReturnMap($map);
     $this->moduleHandler->expects($this->any())->method('moduleExists')->with('field_ui')->willReturn(TRUE);
     $map = [['administer payment fields', TRUE], ['administer payment form display', TRUE], ['administer payment display', TRUE]];
     $this->currentUser->expects($this->atLeastOnce())->method('hasPermission')->willReturnMap($map);
     $build = $this->sut->execute();
     $expected_build = ['#empty' => 'There are no available payment types.', '#header' => ['Type', 'Description', 'Operations'], '#type' => 'table', 'foo' => ['label' => ['#markup' => $definitions['foo']['label']], 'description' => ['#markup' => $definitions['foo']['description']], 'operations' => ['#links' => $operations_foo + ['configure' => ['url' => new Url('payment.payment_type', ['bundle' => 'foo']), 'title' => 'Configure'], 'manage-fields' => ['title' => 'Manage fields', 'url' => new Url('entity.payment.field_ui_fields', ['bundle' => 'foo'])], 'manage-form-display' => ['title' => 'Manage form display', 'url' => new Url('entity.entity_form_display.payment.default', ['bundle' => 'foo'])], 'manage-display' => ['title' => 'Manage display', 'url' => new Url('entity.entity_view_display.payment.default', ['bundle' => 'foo'])]], '#type' => 'operations']], 'bar' => ['label' => ['#markup' => $definitions['bar']['label']], 'description' => ['#markup' => NULL], 'operations' => ['#links' => ['configure' => ['url' => new Url('payment.payment_type', ['bundle' => 'bar']), 'title' => 'Configure'], 'manage-fields' => ['title' => 'Manage fields', 'url' => new Url('entity.payment.field_ui_fields', ['bundle' => 'bar'])], 'manage-form-display' => ['title' => 'Manage form display', 'url' => new Url('entity.entity_form_display.payment.default', ['bundle' => 'bar'])], 'manage-display' => ['title' => 'Manage display', 'url' => new Url('entity.entity_view_display.payment.default', ['bundle' => 'bar'])]], '#type' => 'operations']]];
     $this->assertEquals($expected_build, $build);
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:19,代码来源:ListPaymentTypesTest.php

示例10: testCheckAccessWithLinkToAnyPagePermission

 /**
  * Tests checkAccess() tree manipulator with 'link to any page' permission.
  *
  * @covers ::checkAccess
  * @covers ::menuLinkCheckAccess
  */
 public function testCheckAccessWithLinkToAnyPagePermission()
 {
     $this->mockTree();
     $this->currentUser->expects($this->exactly(9))->method('hasPermission')->with('link to any page')->willReturn(TRUE);
     $this->mockTree();
     $this->defaultMenuTreeManipulators->checkAccess($this->originalTree);
     $expected_access_result = AccessResult::allowed()->cachePerPermissions();
     $this->assertEquals($expected_access_result, $this->originalTree[1]->access);
     $this->assertEquals($expected_access_result, $this->originalTree[2]->access);
     $this->assertEquals($expected_access_result, $this->originalTree[2]->subtree[3]->access);
     $this->assertEquals($expected_access_result, $this->originalTree[2]->subtree[3]->subtree[4]->access);
     $this->assertEquals($expected_access_result, $this->originalTree[5]->subtree[7]->access);
     $this->assertEquals($expected_access_result, $this->originalTree[6]->access);
     $this->assertEquals($expected_access_result, $this->originalTree[8]->access);
     $this->assertEquals($expected_access_result, $this->originalTree[9]->access);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:22,代码来源:DefaultMenuLinkTreeManipulatorsTest.php

示例11: testFormElement

 /**
  * @covers ::formElement
  */
 public function testFormElement()
 {
     $entity_type_id = $this->randomMachineName();
     $bundle = $this->randomMachineName();
     $field_name = $this->randomMachineName();
     $user_id = mt_rand();
     $required = TRUE;
     $entity = $this->getMock(EntityInterface::class);
     $entity->expects($this->atLeastOnce())->method('bundle')->willReturn($bundle);
     $entity->expects($this->atLeastOnce())->method('getEntityTypeId')->willReturn($entity_type_id);
     $this->fieldDefinition->expects($this->once())->method('getName')->willReturn($field_name);
     $this->fieldDefinition->expects($this->once())->method('isRequired')->willReturn($required);
     $payment = $this->getMock(PaymentInterface::class);
     $this->paymentFactory->expects($this->once())->method('createPayment')->with($this->fieldDefinition)->willReturn($payment);
     $this->currentUser->expects($this->exactly(1))->method('id')->willReturn($user_id);
     $items = $this->getMockBuilder(FieldItemList::class)->disableOriginalConstructor()->getMock();
     $items->expects($this->atLeastOnce())->method('getEntity')->willReturn($entity);
     $form = [];
     $form_state = $this->getMock(FormStateInterface::class);
     $build = $this->sut->formElement($items, 3, [], $form, $form_state);
     $expected_build = array('target_id' => array('#default_value' => NULL, '#limit_allowed_plugin_ids' => $this->configFactoryConfiguration['payment_reference.payment_type']['allowed_plugin_ids'], '#plugin_selector_id' => $this->configFactoryConfiguration['payment_reference.payment_type']['plugin_selector_id'], '#prototype_payment' => $payment, '#queue_category_id' => $entity_type_id . '.' . $bundle . '.' . $field_name, '#queue_owner_id' => (int) $user_id, '#required' => $required, '#type' => 'payment_reference'));
     $this->assertSame($expected_build, $build);
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:26,代码来源:PaymentReferenceTest.php


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