@@ -41,6 +41,32 @@ public function testInnerHtml()
4141 $ this ->assertEquals ("<a href='http://google.com'>link</a><br /> " , $ parent ->innerHtml ());
4242 }
4343
44+ public function testInnerHtmlMagic ()
45+ {
46+ $ parent = new HtmlNode ('div ' );
47+ $ parent ->getTag ()->setAttributes ([
48+ 'class ' => [
49+ 'value ' => 'all ' ,
50+ 'doubleQuote ' => true ,
51+ ],
52+ ]);
53+ $ childa = new HtmlNode ('a ' );
54+ $ childa ->getTag ()->setAttributes ([
55+ 'href ' => [
56+ 'value ' => 'http://google.com ' ,
57+ 'doubleQuote ' => false ,
58+ ],
59+ ]);
60+ $ childbr = new HtmlNode ('br ' );
61+ $ childbr ->getTag ()->selfClosing ();
62+
63+ $ parent ->addChild ($ childa );
64+ $ parent ->addChild ($ childbr );
65+ $ childa ->addChild (new TextNode ('link ' ));
66+
67+ $ this ->assertEquals ("<a href='http://google.com'>link</a><br /> " , $ parent ->innerHtml );
68+ }
69+
4470 public function testOuterHtml ()
4571 {
4672 $ div = new Tag ('div ' );
@@ -84,6 +110,32 @@ public function testOuterHtmlEmpty()
84110 $ this ->assertEquals ("<a href='http://google.com'></a> " , $ node ->OuterHtml ());
85111 }
86112
113+ public function testOuterHtmlMagic ()
114+ {
115+ $ parent = new HtmlNode ('div ' );
116+ $ parent ->getTag ()->setAttributes ([
117+ 'class ' => [
118+ 'value ' => 'all ' ,
119+ 'doubleQuote ' => true ,
120+ ],
121+ ]);
122+ $ childa = new HtmlNode ('a ' );
123+ $ childa ->getTag ()->setAttributes ([
124+ 'href ' => [
125+ 'value ' => 'http://google.com ' ,
126+ 'doubleQuote ' => false ,
127+ ],
128+ ]);
129+ $ childbr = new HtmlNode ('br ' );
130+ $ childbr ->getTag ()->selfClosing ();
131+
132+ $ parent ->addChild ($ childa );
133+ $ parent ->addChild ($ childbr );
134+ $ childa ->addChild (new TextNode ('link ' ));
135+
136+ $ this ->assertEquals ('<div class="all"><a href= \'http://google.com \'>link</a><br /></div> ' , $ parent ->outerHtml );
137+ }
138+
87139 public function testText ()
88140 {
89141 $ a = new Tag ('a ' );
@@ -100,4 +152,63 @@ public function testTextNone()
100152
101153 $ this ->assertEmpty ($ node ->text ());
102154 }
155+
156+ public function testTextMagic ()
157+ {
158+ $ node = new HtmlNode ('a ' );
159+ $ node ->addChild (new TextNode ('link ' ));
160+
161+ $ this ->assertEquals ('link ' , $ node ->text );
162+ }
163+
164+ public function testGetAttribute ()
165+ {
166+ $ node = new HtmlNode ('a ' );
167+ $ node ->getTag ()->setAttributes ([
168+ 'href ' => [
169+ 'value ' => 'http://google.com ' ,
170+ 'doubleQuote ' => false ,
171+ ],
172+ 'class ' => [
173+ 'value ' => 'outerlink rounded ' ,
174+ 'doubleQuote ' => true ,
175+ ],
176+ ]);
177+
178+ $ this ->assertEquals ('outerlink rounded ' , $ node ->getAttribute ('class ' ));
179+ }
180+
181+ public function testGetAttributeMagic ()
182+ {
183+ $ node = new HtmlNode ('a ' );
184+ $ node ->getTag ()->setAttributes ([
185+ 'href ' => [
186+ 'value ' => 'http://google.com ' ,
187+ 'doubleQuote ' => false ,
188+ ],
189+ 'class ' => [
190+ 'value ' => 'outerlink rounded ' ,
191+ 'doubleQuote ' => true ,
192+ ],
193+ ]);
194+
195+ $ this ->assertEquals ('http://google.com ' , $ node ->href );
196+ }
197+
198+ public function testGetAttributes ()
199+ {
200+ $ node = new HtmlNode ('a ' );
201+ $ node ->getTag ()->setAttributes ([
202+ 'href ' => [
203+ 'value ' => 'http://google.com ' ,
204+ 'doubleQuote ' => false ,
205+ ],
206+ 'class ' => [
207+ 'value ' => 'outerlink rounded ' ,
208+ 'doubleQuote ' => true ,
209+ ],
210+ ]);
211+
212+ $ this ->assertEquals ('outerlink rounded ' , $ node ->getAttributes ()['class ' ]);
213+ }
103214}
0 commit comments