generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eef5a58
commit ed6c4ac
Showing
13 changed files
with
416 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Html\Tag\MathML; | ||
|
||
use Yiisoft\Html\Tag\Base\NormalTag; | ||
|
||
final class Mmultiscripts extends NormalTag implements MathItemInterface | ||
{ | ||
private MathItemInterface $base; | ||
Check failure on line 11 in src/Tag/MathML/Mmultiscripts.php GitHub Actions / psalm / PHP 8.1-ubuntu-latestPropertyNotSetInConstructor
Check failure on line 11 in src/Tag/MathML/Mmultiscripts.php GitHub Actions / psalm / PHP 8.2-ubuntu-latestPropertyNotSetInConstructor
Check failure on line 11 in src/Tag/MathML/Mmultiscripts.php GitHub Actions / psalm / PHP 8.3-ubuntu-latestPropertyNotSetInConstructor
|
||
private Mprescripts|null $mprescripts = null; | ||
|
||
/** | ||
* @var MathItemInterface[] | ||
*/ | ||
private array $post = []; | ||
|
||
/** | ||
* @var MathItemInterface[] | ||
*/ | ||
private array $pre = []; | ||
|
||
protected function getName(): string | ||
{ | ||
return 'mmultiscripts'; | ||
} | ||
|
||
protected function generateContent(): string | ||
{ | ||
$content = "\n" . $this->base . "\n" . implode("\n", $this->post) . "\n"; | ||
|
||
if ($this->pre) { | ||
$mprescripts = $this->mprescripts ?? Mprescripts::tag(); | ||
$content .= $mprescripts . "\n" . implode("\n", $this->pre) . "\n"; | ||
} | ||
|
||
return $content; | ||
} | ||
|
||
public function base(MathItemInterface $base): self | ||
{ | ||
$new = clone $this; | ||
$new->base = $base; | ||
|
||
return $new; | ||
} | ||
|
||
public function post(MathItemInterface $item, MathItemInterface ...$items): self | ||
{ | ||
$new = clone $this; | ||
|
||
if ($items) { | ||
$new->post = [...[$item], ...$items]; | ||
} else { | ||
$new->post = [$item]; | ||
} | ||
|
||
return $new; | ||
} | ||
|
||
public function pre(MathItemInterface ...$items): self | ||
{ | ||
$new = clone $this; | ||
$new->pre = $items; | ||
|
||
return $new; | ||
} | ||
|
||
public function mprescripts(Mprescripts|null $mprescripts): self | ||
{ | ||
$new = clone $this; | ||
$new->mprescripts = $mprescripts; | ||
|
||
return $new; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Html\Tag\MathML; | ||
|
||
/** | ||
* https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mover | ||
*/ | ||
final class Mover extends AbstractMathItems | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'mover'; | ||
} | ||
|
||
public function accent(bool $accent): self | ||
{ | ||
$new = clone $this; | ||
$new->attributes['accent'] = $accent ? 'true' : 'false'; | ||
|
||
return $new; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Html\Tag\MathML; | ||
|
||
use Yiisoft\Html\Tag\Base\VoidTag; | ||
|
||
final class Mprescripts extends VoidTag | ||
{ | ||
protected function getName(): string | ||
{ | ||
return 'mprescripts'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Html\Tag\MathML; | ||
|
||
use Yiisoft\Html\Tag\Base\NormalTag; | ||
use Yiisoft\Html\Tag\Base\TagContentTrait; | ||
|
||
/** | ||
* @link https://developer.mozilla.org/en-US/docs/Web/MathML/Element/ms | ||
*/ | ||
final class Ms extends NormalTag implements MathItemInterface | ||
{ | ||
use TagContentTrait; | ||
|
||
public function getName(): string | ||
{ | ||
return 'ms'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Html\Tag\MathML; | ||
|
||
/** | ||
* @link https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msqrt | ||
*/ | ||
final class Msqrt extends AbstractMathItems | ||
{ | ||
protected function getName(): string | ||
{ | ||
return 'msqrt'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Html\Tag\MathML; | ||
|
||
/** | ||
* @link https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msub | ||
*/ | ||
final class Msub extends AbstractMathItems | ||
{ | ||
protected function getName(): string | ||
{ | ||
return 'msub'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Html\Tag\MathML; | ||
|
||
/** | ||
* @link https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msubsup | ||
*/ | ||
final class Msubsup extends AbstractMathItems | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'msubsup'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Html\Tag\MathML; | ||
|
||
/** | ||
* @link https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munder | ||
*/ | ||
final class Munder extends AbstractMathItems | ||
{ | ||
protected function getName(): string | ||
{ | ||
return 'munder'; | ||
} | ||
|
||
public function accentunder(bool $accentunder): self | ||
{ | ||
$new = clone $this; | ||
$new->attributes['accentunder'] = $accentunder ? 'true' : 'false'; | ||
|
||
return $new; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Html\Tests\Tag\MathML; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Yiisoft\Html\Tag\MathML\Mi; | ||
use Yiisoft\Html\Tag\MathML\Mmultiscripts; | ||
use Yiisoft\Html\Tag\MathML\Mn; | ||
use Yiisoft\Html\Tag\MathML\Mprescripts; | ||
|
||
final class MmultiscriptsTest extends TestCase | ||
{ | ||
public function testSimple(): void | ||
{ | ||
$mmultiscripts = Mmultiscripts::tag() | ||
->base(Mi::tag()->identifier('X')) | ||
->post( | ||
Mi::tag()->identifier('a'), | ||
Mi::tag()->identifier('b'), | ||
) | ||
->pre( | ||
Mi::tag()->identifier('c'), | ||
Mi::tag()->identifier('d'), | ||
); | ||
|
||
$this->assertSame( | ||
'<mmultiscripts>' . "\n" . | ||
'<mi>X</mi>' . "\n" . | ||
'<mi>a</mi>' . "\n" . | ||
'<mi>b</mi>' . "\n" . | ||
'<mprescripts>' . "\n" . | ||
'<mi>c</mi>' . "\n" . | ||
'<mi>d</mi>' . "\n" . | ||
'</mmultiscripts>', | ||
(string) $mmultiscripts | ||
); | ||
} | ||
|
||
public function testWithoutPre(): void | ||
{ | ||
$mmultiscripts = Mmultiscripts::tag() | ||
->base(Mi::tag()->identifier('X')) | ||
->post( | ||
Mi::tag()->identifier('a'), | ||
Mi::tag()->identifier('b'), | ||
); | ||
|
||
$this->assertSame( | ||
'<mmultiscripts>' . "\n" . | ||
'<mi>X</mi>' . "\n" . | ||
'<mi>a</mi>' . "\n" . | ||
'<mi>b</mi>' . "\n" . | ||
'</mmultiscripts>', | ||
(string) $mmultiscripts | ||
); | ||
} | ||
|
||
public function testCustomMprescripts(): void | ||
{ | ||
$mmultiscripts = Mmultiscripts::tag() | ||
->base(Mi::tag()->identifier('X')) | ||
->mprescripts(Mprescripts::tag()->id('test-id')) | ||
->post( | ||
Mn::tag()->value(1), | ||
Mn::tag()->value(2), | ||
Mn::tag()->value(3), | ||
Mn::tag()->value(4), | ||
) | ||
->pre( | ||
Mn::tag()->value(5), | ||
Mn::tag()->value(6), | ||
Mn::tag()->value(7), | ||
Mn::tag()->value(8), | ||
); | ||
|
||
$this->assertSame( | ||
'<mmultiscripts>' . "\n" . | ||
'<mi>X</mi>' . "\n" . | ||
'<mn>1</mn>' . "\n" . | ||
'<mn>2</mn>' . "\n" . | ||
'<mn>3</mn>' . "\n" . | ||
'<mn>4</mn>' . "\n" . | ||
'<mprescripts id="test-id">' . "\n" . | ||
'<mn>5</mn>' . "\n" . | ||
'<mn>6</mn>' . "\n" . | ||
'<mn>7</mn>' . "\n" . | ||
'<mn>8</mn>' . "\n" . | ||
'</mmultiscripts>', | ||
(string) $mmultiscripts | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Html\Tests\Tag\MathML; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Yiisoft\Html\Tag\MathML\Mi; | ||
use Yiisoft\Html\Tag\MathML\Mo; | ||
use Yiisoft\Html\Tag\MathML\Mover; | ||
use Yiisoft\Html\Tag\MathML\Mrow; | ||
|
||
final class MoverTest extends TestCase | ||
{ | ||
public static function accentDataProvider(): array | ||
{ | ||
return [ | ||
[true], | ||
[false], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider accentDataProvider | ||
*/ | ||
public function testMover(bool $accent): void | ||
{ | ||
$mover = Mover::tag() | ||
->accent($accent) | ||
->items( | ||
Mrow::tag() | ||
->items( | ||
Mi::tag()->identifier('x'), | ||
Mo::tag()->operator('+'), | ||
Mi::tag()->identifier('y'), | ||
Mo::tag()->operator('+'), | ||
Mi::tag()->identifier('z'), | ||
), | ||
Mo::tag()->operator('⏞'), | ||
); | ||
|
||
$this->assertSame( | ||
'<mover accent="' . ($accent ? 'true' : 'false') . '">' . "\n" . | ||
'<mrow>' . "\n" . | ||
'<mi>x</mi>' . "\n" . | ||
'<mo>+</mo>' . "\n" . | ||
'<mi>y</mi>' . "\n" . | ||
'<mo>+</mo>' . "\n" . | ||
'<mi>z</mi>' . "\n" . | ||
'</mrow>' . "\n" . | ||
'<mo>⏞</mo>' . "\n" . | ||
'</mover>', | ||
(string) $mover | ||
); | ||
} | ||
} |
Oops, something went wrong.