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


PHP QueryFactory::expects方法代码示例

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


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

示例1: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->entityQuery = $this->getMockBuilder('Drupal\\Core\\Entity\\Query\\QueryInterface')->disableOriginalConstructor()->getMock();
     $this->entityQueryFactory = $this->getMockBuilder('Drupal\\Core\\Entity\\Query\\QueryFactory')->disableOriginalConstructor()->getMock();
     $this->entityQueryFactory->expects($this->any())->method('get')->will($this->returnValue($this->entityQuery));
     parent::setUp();
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:10,代码来源:DedupeEntityTest.php

示例2: testCheckNodeAccess

 /**
  * Tests the optimized node access checking.
  *
  * @covers ::checkNodeAccess
  * @covers ::collectNodeLinks
  * @covers ::checkAccess
  */
 public function testCheckNodeAccess()
 {
     $links = array(1 => MenuLinkMock::create(array('id' => 'node.1', 'route_name' => 'entity.node.canonical', 'title' => 'foo', 'parent' => '', 'route_parameters' => array('node' => 1))), 2 => MenuLinkMock::create(array('id' => 'node.2', 'route_name' => 'entity.node.canonical', 'title' => 'bar', 'parent' => '', 'route_parameters' => array('node' => 2))), 3 => MenuLinkMock::create(array('id' => 'node.3', 'route_name' => 'entity.node.canonical', 'title' => 'baz', 'parent' => 'node.2', 'route_parameters' => array('node' => 3))), 4 => MenuLinkMock::create(array('id' => 'node.4', 'route_name' => 'entity.node.canonical', 'title' => 'qux', 'parent' => 'node.3', 'route_parameters' => array('node' => 4))), 5 => MenuLinkMock::create(array('id' => 'test.1', 'route_name' => 'test_route', 'title' => 'qux', 'parent' => '')), 6 => MenuLinkMock::create(array('id' => 'test.2', 'route_name' => 'test_route', 'title' => 'qux', 'parent' => 'test.1')));
     $tree = array();
     $tree[1] = new MenuLinkTreeElement($links[1], FALSE, 1, FALSE, array());
     $tree[2] = new MenuLinkTreeElement($links[2], TRUE, 1, FALSE, array(3 => new MenuLinkTreeElement($links[3], TRUE, 2, FALSE, array(4 => new MenuLinkTreeElement($links[4], FALSE, 3, FALSE, array())))));
     $tree[5] = new MenuLinkTreeElement($links[5], TRUE, 1, FALSE, array(6 => new MenuLinkTreeElement($links[6], FALSE, 2, FALSE, array())));
     $query = $this->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
     $query->expects($this->at(0))->method('condition')->with('nid', array(1, 2, 3, 4));
     $query->expects($this->at(1))->method('condition')->with('status', NODE_PUBLISHED);
     $query->expects($this->once())->method('execute')->willReturn(array(1, 2, 4));
     $this->queryFactory->expects($this->once())->method('get')->with('node')->willReturn($query);
     $node_access_result = AccessResult::allowed()->cachePerPermissions()->addCacheContexts(['user.node_grants:view']);
     $tree = $this->defaultMenuTreeManipulators->checkNodeAccess($tree);
     $this->assertEquals($node_access_result, $tree[1]->access);
     $this->assertEquals($node_access_result, $tree[2]->access);
     // Ensure that access denied is set.
     $this->assertEquals(AccessResult::neutral(), $tree[2]->subtree[3]->access);
     $this->assertEquals($node_access_result, $tree[2]->subtree[3]->subtree[4]->access);
     // Ensure that other routes than entity.node.canonical are set as well.
     $this->assertNull($tree[5]->access);
     $this->assertNull($tree[5]->subtree[6]->access);
     // On top of the node access checking now run the ordinary route based
     // access checkers.
     // Ensure that the access manager is just called for the non-node routes.
     $this->accessManager->expects($this->at(0))->method('checkNamedRoute')->with('test_route', [], $this->currentUser, TRUE)->willReturn(AccessResult::allowed());
     $this->accessManager->expects($this->at(1))->method('checkNamedRoute')->with('test_route', [], $this->currentUser, TRUE)->willReturn(AccessResult::neutral());
     $tree = $this->defaultMenuTreeManipulators->checkAccess($tree);
     $this->assertEquals($node_access_result, $tree[1]->access);
     $this->assertEquals($node_access_result, $tree[2]->access);
     $this->assertEquals(AccessResult::neutral(), $tree[2]->subtree[3]->access);
     $this->assertEquals(AccessResult::allowed()->cachePerPermissions(), $tree[5]->access);
     $this->assertEquals(AccessResult::neutral()->cachePerPermissions(), $tree[5]->subtree[6]->access);
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:41,代码来源:DefaultMenuLinkTreeManipulatorsTest.php

示例3: testBuildTreeWithoutParameters

 /**
  * Tests buildTree with simple menu_name and no parameters.
  */
 public function testBuildTreeWithoutParameters()
 {
     $language = new Language(array('id' => 'en'));
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->returnValue($language));
     // Setup query and the query result.
     $query = $this->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
     $this->entityQueryFactory->expects($this->once())->method('get')->with('menu_link')->will($this->returnValue($query));
     $query->expects($this->once())->method('condition')->with('menu_name', 'test_menu');
     $query->expects($this->once())->method('execute')->will($this->returnValue(array(1, 2, 3)));
     $storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
     $base = array('access' => TRUE, 'weight' => 0, 'title' => 'title');
     $menu_link = $base + array('mlid' => 1, 'p1' => 3, 'p2' => 2, 'p3' => 1);
     $links[1] = $menu_link;
     $menu_link = $base + array('mlid' => 3, 'p1' => 3, 'depth' => 1);
     $links[3] = $menu_link;
     $menu_link = $base + array('mlid' => 2, 'p1' => 3, 'p2' => 2, 'depth' => 2);
     $links[2] = $menu_link;
     $storage->expects($this->once())->method('loadMultiple')->with(array(1, 2, 3))->will($this->returnValue($links));
     $this->menuTree->setStorage($storage);
     // Ensure that static/non static caching works.
     // First setup no working caching.
     $this->cacheBackend->expects($this->at(0))->method('get')->with('links:test_menu:tree-data:en:35786c7117b4e38d0f169239752ce71158266ae2f6e4aa230fbbb87bd699c0e3')->will($this->returnValue(FALSE));
     $this->cacheBackend->expects($this->at(1))->method('set')->with('links:test_menu:tree-data:en:35786c7117b4e38d0f169239752ce71158266ae2f6e4aa230fbbb87bd699c0e3', $this->anything(), Cache::PERMANENT, array('menu' => 'test_menu'));
     // Ensure that the static caching triggered.
     $this->cacheBackend->expects($this->exactly(1))->method('get');
     $this->menuTree->buildTree('test_menu');
     $this->menuTree->buildTree('test_menu');
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:31,代码来源:MenuTreeTest.php


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