SkinTemplateTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * @covers SkinTemplate
  4. *
  5. * @group Output
  6. *
  7. * @author Bene* < benestar.wikimedia@gmail.com >
  8. */
  9. class SkinTemplateTest extends MediaWikiTestCase {
  10. /**
  11. * @dataProvider makeListItemProvider
  12. */
  13. public function testMakeListItem( $expected, $key, $item, $options, $message ) {
  14. $template = $this->getMockForAbstractClass( BaseTemplate::class );
  15. $this->assertEquals(
  16. $expected,
  17. $template->makeListItem( $key, $item, $options ),
  18. $message
  19. );
  20. }
  21. public function makeListItemProvider() {
  22. return [
  23. [
  24. '<li class="class" title="itemtitle"><a href="url" title="title">text</a></li>',
  25. '',
  26. [
  27. 'class' => 'class',
  28. 'itemtitle' => 'itemtitle',
  29. 'href' => 'url',
  30. 'title' => 'title',
  31. 'text' => 'text'
  32. ],
  33. [],
  34. 'Test makeListItem with normal values'
  35. ]
  36. ];
  37. }
  38. /**
  39. * @return PHPUnit_Framework_MockObject_MockObject|OutputPage
  40. */
  41. private function getMockOutputPage( $isSyndicated, $html ) {
  42. $mock = $this->getMockBuilder( OutputPage::class )
  43. ->disableOriginalConstructor()
  44. ->getMock();
  45. $mock->expects( $this->once() )
  46. ->method( 'isSyndicated' )
  47. ->will( $this->returnValue( $isSyndicated ) );
  48. $mock->expects( $this->any() )
  49. ->method( 'getHTML' )
  50. ->will( $this->returnValue( $html ) );
  51. return $mock;
  52. }
  53. public function provideGetDefaultModules() {
  54. $defaultStyles = [
  55. 'mediawiki.legacy.shared',
  56. 'mediawiki.legacy.commonPrint',
  57. ];
  58. $buttonStyle = 'mediawiki.ui.button';
  59. $feedStyle = 'mediawiki.feedlink';
  60. return [
  61. [
  62. false,
  63. '',
  64. $defaultStyles
  65. ],
  66. [
  67. true,
  68. '',
  69. array_merge( $defaultStyles, [ $feedStyle ] )
  70. ],
  71. [
  72. false,
  73. 'FOO mw-ui-button BAR',
  74. array_merge( $defaultStyles, [ $buttonStyle ] )
  75. ],
  76. [
  77. true,
  78. 'FOO mw-ui-button BAR',
  79. array_merge( $defaultStyles, [ $buttonStyle, $feedStyle ] )
  80. ],
  81. ];
  82. }
  83. /**
  84. * @covers Skin::getDefaultModules
  85. * @dataProvider provideGetDefaultModules
  86. */
  87. public function testgetDefaultModules( $isSyndicated, $html, $expectedModuleStyles ) {
  88. $skin = new SkinTemplate();
  89. $context = new DerivativeContext( $skin->getContext() );
  90. $context->setOutput( $this->getMockOutputPage( $isSyndicated, $html ) );
  91. $skin->setContext( $context );
  92. $modules = $skin->getDefaultModules();
  93. $actualStylesModule = call_user_func_array( 'array_merge', $modules['styles'] );
  94. $this->assertArraySubset(
  95. $expectedModuleStyles,
  96. $actualStylesModule,
  97. 'style modules'
  98. );
  99. }
  100. }