Пример #1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->themeManager = $this->getMock('Drupal\\Core\\Theme\\ThemeManagerInterface');
     $mock_active_theme = $this->getMockBuilder('Drupal\\Core\\Theme\\ActiveTheme')->disableOriginalConstructor()->getMock();
     $mock_active_theme->expects($this->any())->method('getLibrariesOverride')->willReturn([]);
     $this->themeManager->expects($this->any())->method('getActiveTheme')->willReturn($mock_active_theme);
     $this->libraryDiscoveryParser = new TestLibraryDiscoveryParser($this->root, $this->moduleHandler, $this->themeManager);
 }
 /**
  * Tests the getInfo() method when render element plugins are used.
  *
  * @covers ::getInfo
  * @covers ::buildInfo
  *
  * @dataProvider providerTestGetInfoElementPlugin
  */
 public function testGetInfoElementPlugin($plugin_class, $expected_info)
 {
     $this->moduleHandler->expects($this->once())->method('alter')->with('element_info', $this->anything())->will($this->returnArgument(0));
     $plugin = $this->getMock($plugin_class);
     $plugin->expects($this->once())->method('getInfo')->willReturn(array('#theme' => 'page'));
     $element_info = $this->getMockBuilder('Drupal\\Core\\Render\\ElementInfoManager')->setConstructorArgs(array(new \ArrayObject(), $this->cache, $this->cacheTagsInvalidator, $this->moduleHandler, $this->themeManager))->setMethods(array('getDefinitions', 'createInstance'))->getMock();
     $this->themeManager->expects($this->any())->method('getActiveTheme')->willReturn(new ActiveTheme(['name' => 'test']));
     $element_info->expects($this->once())->method('createInstance')->with('page')->willReturn($plugin);
     $element_info->expects($this->once())->method('getDefinitions')->willReturn(array('page' => array('class' => 'TestElementPlugin')));
     $this->assertEquals($expected_info, $element_info->getInfo('page'));
 }
 /**
  * Tests the destruct method.
  *
  * @covers ::destruct
  */
 public function testDestruct()
 {
     $this->activeTheme = $this->getMockBuilder('Drupal\\Core\\Theme\\ActiveTheme')->disableOriginalConstructor()->getMock();
     $this->themeManager->expects($this->once())->method('getActiveTheme')->willReturn($this->activeTheme);
     $this->activeTheme->expects($this->once())->method('getName')->willReturn('kitten_theme');
     $this->libraryDiscoveryCollector = new LibraryDiscoveryCollector($this->cache, $this->lock, $this->libraryDiscoveryParser, $this->themeManager);
     $this->libraryDiscoveryParser->expects($this->once())->method('buildByExtension')->with('test')->willReturn($this->libraryData);
     $lock_key = 'library_info:kitten_theme:Drupal\\Core\\Cache\\CacheCollector';
     $this->lock->expects($this->once())->method('acquire')->with($lock_key)->will($this->returnValue(TRUE));
     $this->cache->expects($this->exactly(2))->method('get')->with('library_info:kitten_theme')->willReturn(FALSE);
     $this->cache->expects($this->once())->method('set')->with('library_info:kitten_theme', array('test' => $this->libraryData), Cache::PERMANENT, ['library_info']);
     $this->lock->expects($this->once())->method('release')->with($lock_key);
     // This should get data and persist the key.
     $this->libraryDiscoveryCollector->get('test');
     $this->libraryDiscoveryCollector->destruct();
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->libraryDiscovery = $this->getMockBuilder('Drupal\\Core\\Asset\\LibraryDiscovery')->disableOriginalConstructor()->getMock();
     $this->libraryDependencyResolver = $this->getMock('\\Drupal\\Core\\Asset\\LibraryDependencyResolverInterface');
     $this->libraryDependencyResolver->expects($this->any())->method('getLibrariesWithDependencies')->willReturnArgument(0);
     $this->moduleHandler = $this->getMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->themeManager = $this->getMock('\\Drupal\\Core\\Theme\\ThemeManagerInterface');
     $active_theme = $this->getMockBuilder('\\Drupal\\Core\\Theme\\ActiveTheme')->disableOriginalConstructor()->getMock();
     $active_theme->expects($this->any())->method('getName')->willReturn('bartik');
     $this->themeManager->expects($this->any())->method('getActiveTheme')->willReturn($active_theme);
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $english = $this->getMock('\\Drupal\\Core\\Language\\LanguageInterface');
     $english->expects($this->any())->method('getId')->willReturn('en');
     $japanese = $this->getMock('\\Drupal\\Core\\Language\\LanguageInterface');
     $japanese->expects($this->any())->method('getId')->willReturn('jp');
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->onConsecutiveCalls($english, $english, $japanese, $japanese));
     $this->cache = new TestMemoryBackend('llama');
     $this->assetResolver = new AssetResolver($this->libraryDiscovery, $this->libraryDependencyResolver, $this->moduleHandler, $this->themeManager, $this->languageManager, $this->cache);
 }
Пример #5
0
 /**
  * Tests getting the theme registry defined by a module.
  */
 public function testGetRegistryForModule()
 {
     $test_theme = new ActiveTheme(['name' => 'test_theme', 'path' => 'core/modules/system/tests/themes/test_theme/test_theme.info.yml', 'engine' => 'twig', 'owner' => 'twig', 'stylesheets_remove' => [], 'libraries_override' => [], 'libraries_extend' => [], 'libraries' => [], 'extension' => '.twig', 'base_themes' => []]);
     $test_stable = new ActiveTheme(['name' => 'test_stable', 'path' => 'core/modules/system/tests/themes/test_stable/test_stable.info.yml', 'engine' => 'twig', 'owner' => 'twig', 'stylesheets_remove' => [], 'libraries_override' => [], 'libraries_extend' => [], 'libraries' => [], 'extension' => '.twig', 'base_themes' => []]);
     $this->themeManager->expects($this->exactly(2))->method('getActiveTheme')->willReturnOnConsecutiveCalls($test_theme, $test_stable);
     // Include the module and theme files so that hook_theme can be called.
     include_once $this->root . '/core/modules/system/tests/modules/theme_test/theme_test.module';
     include_once $this->root . '/core/modules/system/tests/themes/test_stable/test_stable.theme';
     $this->moduleHandler->expects($this->exactly(2))->method('getImplementations')->with('theme')->will($this->returnValue(array('theme_test')));
     $this->moduleHandler->expects($this->atLeastOnce())->method('getModuleList')->willReturn([]);
     $registry = $this->registry->get();
     // Ensure that the registry entries from the module are found.
     $this->assertArrayHasKey('theme_test', $registry);
     $this->assertArrayHasKey('theme_test_template_test', $registry);
     $this->assertArrayHasKey('theme_test_template_test_2', $registry);
     $this->assertArrayHasKey('theme_test_suggestion_provided', $registry);
     $this->assertArrayHasKey('theme_test_specific_suggestions', $registry);
     $this->assertArrayHasKey('theme_test_suggestions', $registry);
     $this->assertArrayHasKey('theme_test_function_suggestions', $registry);
     $this->assertArrayHasKey('theme_test_foo', $registry);
     $this->assertArrayHasKey('theme_test_render_element', $registry);
     $this->assertArrayHasKey('theme_test_render_element_children', $registry);
     $this->assertArrayHasKey('theme_test_function_template_override', $registry);
     $this->assertArrayNotHasKey('test_theme_not_existing_function', $registry);
     $this->assertFalse(in_array('test_stable_preprocess_theme_test_render_element', $registry['theme_test_render_element']['preprocess functions']));
     $info = $registry['theme_test_function_suggestions'];
     $this->assertEquals('module', $info['type']);
     $this->assertEquals('core/modules/system/tests/modules/theme_test', $info['theme path']);
     $this->assertEquals('theme_theme_test_function_suggestions', $info['function']);
     $this->assertEquals(array(), $info['variables']);
     // The second call will initialize with the second theme. Ensure that this
     // returns a different object and the discovery for the second theme's
     // preprocess function worked.
     $other_registry = $this->registry->get();
     $this->assertNotSame($registry, $other_registry);
     $this->assertTrue(in_array('test_stable_preprocess_theme_test_render_element', $other_registry['theme_test_render_element']['preprocess functions']));
 }