File tree Expand file tree Collapse file tree 2 files changed +37
-4
lines changed
Expand file tree Collapse file tree 2 files changed +37
-4
lines changed Original file line number Diff line number Diff line change 99use Sabberworm \CSS \Parsing \SourceException ;
1010use Sabberworm \CSS \Parsing \UnexpectedEOFException ;
1111use Sabberworm \CSS \Parsing \UnexpectedTokenException ;
12+ use Sabberworm \CSS \ShortClassNameProvider ;
1213
1314/**
1415 * This class represents URLs in CSS. `URL`s always output in `URL("")` notation.
1516 */
1617class URL extends PrimitiveValue
1718{
19+ use ShortClassNameProvider;
20+
1821 /**
1922 * @var CSSString
2023 */
@@ -80,4 +83,19 @@ public function render(OutputFormat $outputFormat): string
8083 {
8184 return "url( {$ this ->url ->render ($ outputFormat )}) " ;
8285 }
86+
87+ /**
88+ * @return array<string, bool|int|float|string|array<mixed>|null>
89+ *
90+ * @internal
91+ */
92+ public function getArrayRepresentation (): array
93+ {
94+ return [
95+ 'class ' => $ this ->getShortClassName (),
96+ // We're using the term "uri" here to match the wording used in the specs:
97+ // https://www.w3.org/TR/CSS22/syndata.html#uri
98+ 'uri ' => $ this ->url ->getArrayRepresentation (),
99+ ];
100+ }
83101}
Original file line number Diff line number Diff line change @@ -84,12 +84,27 @@ public function getLineNumberReturnsLineNumberProvidedToConstructor(): void
8484 /**
8585 * @test
8686 */
87- public function getArrayRepresentationThrowsException (): void
87+ public function getArrayRepresentationIncludesClassName (): void
8888 {
89- $ this -> expectException (\BadMethodCallException::class );
89+ $ subject = new URL ( new CSSString ( ' https://example.com ' ) );
9090
91- $ subject = new URL (new CSSString ('http://example.com ' ));
91+ $ result = $ subject ->getArrayRepresentation ();
92+
93+ self ::assertArrayHasKey ('class ' , $ result );
94+ self ::assertSame ('URL ' , $ result ['class ' ]);
95+ }
96+
97+ /**
98+ * @test
99+ */
100+ public function getArrayRepresentationIncludesUri (): void
101+ {
102+ $ uri = 'https://example.com ' ;
103+ $ subject = new URL (new CSSString ($ uri ));
104+
105+ $ result = $ subject ->getArrayRepresentation ();
92106
93- $ subject ->getArrayRepresentation ();
107+ self ::assertArrayHasKey ('uri ' , $ result );
108+ self ::assertSame (['class ' => 'CSSString ' , 'contents ' => $ uri ], $ result ['uri ' ]);
94109 }
95110}
You can’t perform that action at this time.
0 commit comments