/** * {@inheritdoc} */ public function setUp() { $this->entityTypeId = $this->randomName(); $this->provider = $this->randomName(); $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface'); $this->entityType->expects($this->any())->method('getProvider')->will($this->returnValue($this->provider)); $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface'); $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType)); $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface'); $this->breakpointGroupId = $this->randomName(9); $this->breakpointGroup = $this->getMock('Drupal\\breakpoint\\Entity\\BreakpointGroup', array(), array(array('name' => 'test', 'id' => $this->breakpointGroupId))); $this->breakpointGroupStorage = $this->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface'); $this->breakpointGroupStorage->expects($this->any())->method('load')->with($this->breakpointGroupId)->will($this->returnValue($this->breakpointGroup)); $this->entityManager->expects($this->any())->method('getStorage')->will($this->returnValue($this->breakpointGroupStorage)); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); \Drupal::setContainer($container); }
/** * @covers ::render * * @depends testBuildHeader */ public function testRender() { $query = $this->getMock(QueryInterface::class); $query->expects($this->atLeastOnce())->method('pager')->willReturnSelf(); $query->expects($this->atLeastOnce())->method('sort')->willReturnSelf(); $this->entityStorage->expects($this->atLeastOnce())->method('getQuery')->willReturn($query); $this->entityType->expects($this->any())->method('getClass')->willReturn(ConfigEntityBase::class); $this->entityStorage->expects($this->once())->method('loadMultipleOverrideFree')->willReturn([]); $build = $this->sut->render(); unset($build['table']['#attached']); unset($build['table']['#header']); $expected_build = array('#type' => 'table', '#title' => NULL, '#rows' => [], '#attributes' => array('class' => array('payment-method-configuration-list')), '#cache' => ['contexts' => NULL, 'tags' => NULL]); $this->assertInstanceOf(TranslatableMarkup::class, $build['table']['#empty']); unset($build['table']['#empty']); $this->assertEquals($expected_build, $build['table']); }
/** * Tests the sortSearchPages() method. */ public function testSortSearchPages() { $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface'); $entity_type->expects($this->any())->method('getClass')->will($this->returnValue('Drupal\\Tests\\search\\Unit\\TestSearchPage')); $this->storage->expects($this->once())->method('getEntityType')->will($this->returnValue($entity_type)); // Declare entities out of their expected order so we can be sure they were // sorted. We cannot mock these because of uasort(), see // https://bugs.php.net/bug.php?id=50688. $unsorted_entities['test4'] = new TestSearchPage(array('weight' => 0, 'status' => FALSE, 'label' => 'Test4')); $unsorted_entities['test3'] = new TestSearchPage(array('weight' => 10, 'status' => TRUE, 'label' => 'Test3')); $unsorted_entities['test2'] = new TestSearchPage(array('weight' => 0, 'status' => TRUE, 'label' => 'Test2')); $unsorted_entities['test1'] = new TestSearchPage(array('weight' => 0, 'status' => TRUE, 'label' => 'Test1')); $expected = $unsorted_entities; ksort($expected); $sorted_entities = $this->searchPageRepository->sortSearchPages($unsorted_entities); $this->assertSame($expected, $sorted_entities); }