Debian Codegraph @

extensions/Math/tests/phpunit/unit/WikiTexVC/Nodes/BoxTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes;
4
5 use ArgumentCountError;
6 use MediaWiki\Extension\Math\WikiTexVC\Nodes\Box;
7 use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
8 use MediaWikiUnitTestCase;
9 use RuntimeException;
10 use TypeError;
11
12 /**
13 * @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\Box
14 */
15 class BoxTest extends MediaWikiUnitTestCase {
16
17 public function testEmptyBox() {
18 $this->expectException( ArgumentCountError::class );
19 new Box();
20 throw new ArgumentCountError( 'Should not create an empty box' );
21 }
22
23 public function testOneArgumentBox() {
24 $this->expectException( ArgumentCountError::class );
25 new Box( '\\hbox' );
26 throw new ArgumentCountError( 'Should not create a box with one argument' );
27 }
28
29 public function testIncorrectTypeBox() {
30 $this->expectException( TypeError::class );
31 new Box( '\\hbox', new Literal( 'a' ) );
32 throw new RuntimeException( 'Should not create a box with incorrect type' );
33 }
34
35 public function testBasicFunctionBox() {
36 $box = new Box( '\\hbox', 'a' );
37 $this->assertEquals( '{\\hbox{a}}', $box->render(), 'Should create a basic function' );
38 }
39
40 public function testGetters() {
41 $box = new Box( '\\hbox', 'a' );
42 $this->assertNotEmpty( $box->getArg() );
43 $this->assertNotEmpty( $box->getFname() );
44 }
45
46 public function testExtractIdentifiersBox() {
47 $box = new Box( '\\hbox', 'a' );
48 $this->assertEquals( [], $box->extractIdentifiers(), 'Should extract identifiers' );
49 }
50
51 public function testCurliesBox() {
52 $box = new Box( '\\hbox', 'a' );
53 $this->assertEquals( '{\\hbox{a}}', $box->inCurlies(), 'Should create exactly one set of curlies' );
54 }
55
56 public function testRenderMML() {
57 $box = new Box( '\\hbox', 'a' );
58 $this->assertStringContainsString( '</mtext>', $box->renderMML(), 'Render MathML as text.' );
59 }
60
61 public function testTrailingSpaceBoxMML() {
62 $box = new Box( '\\hbox', 'a ' );
63 $this->assertStringContainsString( '&#xA0;', $box->renderMML(), 'Should have trailing rendered space' );
64 }
65
66 public function testPrecedingSpaceBoxMML() {
67 $box = new Box( '\\hbox', ' a' );
68 $this->assertStringContainsString( '&#xA0;', $box->renderMML(), 'Should have preceding rendered space' );
69 }
70 }