Skip to content

Commit

Permalink
Новые теги
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerych1984 committed Feb 1, 2025
1 parent eef5a58 commit ed6c4ac
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .phpunit.result.cache

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions src/Tag/MathML/Mmultiscripts.php
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

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

PropertyNotSetInConstructor

src/Tag/MathML/Mmultiscripts.php:11:31: PropertyNotSetInConstructor: Property Yiisoft\Html\Tag\MathML\Mmultiscripts::$base is not defined in constructor of Yiisoft\Html\Tag\MathML\Mmultiscripts or in any private or final methods called in the constructor (see https://psalm.dev/074)

Check failure on line 11 in src/Tag/MathML/Mmultiscripts.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

PropertyNotSetInConstructor

src/Tag/MathML/Mmultiscripts.php:11:31: PropertyNotSetInConstructor: Property Yiisoft\Html\Tag\MathML\Mmultiscripts::$base is not defined in constructor of Yiisoft\Html\Tag\MathML\Mmultiscripts or in any private or final methods called in the constructor (see https://psalm.dev/074)

Check failure on line 11 in src/Tag/MathML/Mmultiscripts.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

PropertyNotSetInConstructor

src/Tag/MathML/Mmultiscripts.php:11:31: PropertyNotSetInConstructor: Property Yiisoft\Html\Tag\MathML\Mmultiscripts::$base is not defined in constructor of Yiisoft\Html\Tag\MathML\Mmultiscripts or in any private or final methods called in the constructor (see https://psalm.dev/074)
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];

Check warning on line 56 in src/Tag/MathML/Mmultiscripts.php

View check run for this annotation

Codecov / codecov/patch

src/Tag/MathML/Mmultiscripts.php#L56

Added line #L56 was not covered by tests
}

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;
}
}
24 changes: 24 additions & 0 deletions src/Tag/MathML/Mover.php
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;
}
}
15 changes: 15 additions & 0 deletions src/Tag/MathML/Mprescripts.php
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';
}
}
21 changes: 21 additions & 0 deletions src/Tag/MathML/Ms.php
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

Check warning on line 17 in src/Tag/MathML/Ms.php

View check run for this annotation

Codecov / codecov/patch

src/Tag/MathML/Ms.php#L17

Added line #L17 was not covered by tests
{
return 'ms';

Check warning on line 19 in src/Tag/MathML/Ms.php

View check run for this annotation

Codecov / codecov/patch

src/Tag/MathML/Ms.php#L19

Added line #L19 was not covered by tests
}
}
16 changes: 16 additions & 0 deletions src/Tag/MathML/Msqrt.php
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

Check warning on line 12 in src/Tag/MathML/Msqrt.php

View check run for this annotation

Codecov / codecov/patch

src/Tag/MathML/Msqrt.php#L12

Added line #L12 was not covered by tests
{
return 'msqrt';

Check warning on line 14 in src/Tag/MathML/Msqrt.php

View check run for this annotation

Codecov / codecov/patch

src/Tag/MathML/Msqrt.php#L14

Added line #L14 was not covered by tests
}
}
16 changes: 16 additions & 0 deletions src/Tag/MathML/Msub.php
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

Check warning on line 12 in src/Tag/MathML/Msub.php

View check run for this annotation

Codecov / codecov/patch

src/Tag/MathML/Msub.php#L12

Added line #L12 was not covered by tests
{
return 'msub';

Check warning on line 14 in src/Tag/MathML/Msub.php

View check run for this annotation

Codecov / codecov/patch

src/Tag/MathML/Msub.php#L14

Added line #L14 was not covered by tests
}
}
16 changes: 16 additions & 0 deletions src/Tag/MathML/Msubsup.php
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

Check warning on line 12 in src/Tag/MathML/Msubsup.php

View check run for this annotation

Codecov / codecov/patch

src/Tag/MathML/Msubsup.php#L12

Added line #L12 was not covered by tests
{
return 'msubsup';

Check warning on line 14 in src/Tag/MathML/Msubsup.php

View check run for this annotation

Codecov / codecov/patch

src/Tag/MathML/Msubsup.php#L14

Added line #L14 was not covered by tests
}
}
3 changes: 0 additions & 3 deletions src/Tag/MathML/Msup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

namespace Yiisoft\Html\Tag\MathML;

use Override;

/**
* @link https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msup
*/
final class Msup extends AbstractMathItems
{
#[Override]
protected function getName(): string
{
return 'msup';
Expand Down
24 changes: 24 additions & 0 deletions src/Tag/MathML/Munder.php
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;
}
}
94 changes: 94 additions & 0 deletions tests/Tag/MathML/MmultiscriptsTest.php
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
);
}
}
56 changes: 56 additions & 0 deletions tests/Tag/MathML/MoverTest.php
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('&#x23DE;'),
);

$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>&#x23DE;</mo>' . "\n" .
'</mover>',
(string) $mover
);
}
}
Loading

0 comments on commit ed6c4ac

Please sign in to comment.