3 namespace Drupal\Tests\forum\Unit;
5 use Drupal\Tests\UnitTestCase;
8 * @coversDefaultClass \Drupal\forum\ForumManager
11 class ForumManagerTest extends UnitTestCase {
14 * Tests ForumManager::getIndex().
16 public function testGetIndex() {
17 $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
19 $storage = $this->getMockBuilder('\Drupal\taxonomy\VocabularyStorage')
20 ->disableOriginalConstructor()
23 $config_factory = $this->getMock('\Drupal\Core\Config\ConfigFactoryInterface');
25 $config = $this->getMockBuilder('\Drupal\Core\Config\Config')
26 ->disableOriginalConstructor()
29 $config_factory->expects($this->once())
31 ->will($this->returnValue($config));
33 $config->expects($this->once())
35 ->will($this->returnValue('forums'));
37 $entity_manager->expects($this->once())
38 ->method('getStorage')
39 ->will($this->returnValue($storage));
41 // This is sufficient for testing purposes.
42 $term = new \stdClass();
44 $storage->expects($this->once())
46 ->will($this->returnValue($term));
48 $connection = $this->getMockBuilder('\Drupal\Core\Database\Connection')
49 ->disableOriginalConstructor()
52 $translation_manager = $this->getMockBuilder('\Drupal\Core\StringTranslation\TranslationManager')
53 ->disableOriginalConstructor()
56 $comment_manager = $this->getMockBuilder('\Drupal\comment\CommentManagerInterface')
57 ->disableOriginalConstructor()
60 $manager = $this->getMock('\Drupal\forum\ForumManager', ['getChildren'], [
68 $manager->expects($this->once())
69 ->method('getChildren')
70 ->will($this->returnValue([]));
72 // Get the index once.
73 $index1 = $manager->getIndex();
75 // Get it again. This should not return the previously generated index. If
76 // it does not, then the test will fail as the mocked methods will be called
78 $index2 = $manager->getIndex();
80 $this->assertEquals($index1, $index2);