File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed
Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Created by PhpStorm.
4+ * User: Jaeger <[email protected] > 5+ * Date: 18/12/12
6+ * Time: 下午12:25
7+ */
8+
9+ namespace Tests \Dom ;
10+
11+
12+ use QL \QueryList ;
13+ use Tests \TestCaseBase ;
14+ use Tightenco \Collect \Support \Collection ;
15+
16+ class RulesTest extends TestCaseBase
17+ {
18+ protected $ html ;
19+ protected $ ql ;
20+
21+ public function setUp ()
22+ {
23+ $ this ->html = $ this ->getSnippet ('snippet-2 ' );
24+ $ this ->ql = QueryList::html ($ this ->html );
25+ }
26+
27+ /**
28+ * @test
29+ */
30+ public function get_data_by_rules ()
31+ {
32+ $ rules = [
33+ 'a ' => ['a ' ,'text ' ],
34+ 'img_src ' => ['img ' ,'src ' ],
35+ 'img_alt ' => ['img ' ,'alt ' ]
36+ ];
37+ $ range = 'ul>li ' ;
38+ $ data = QueryList::rules ($ rules )->range ($ range )->html ($ this ->html )->query ()->getData ();
39+ $ this ->assertInstanceOf (Collection::class,$ data );
40+ $ this ->assertCount (3 ,$ data );
41+ $ this ->assertEquals ('http://querylist.com/2.jpg ' ,$ data [1 ]['img_src ' ]);
42+ }
43+ }
Original file line number Diff line number Diff line change @@ -85,4 +85,19 @@ public function concurrent_requests_advanced_use()
8585 })
8686 ->send ();
8787 }
88+
89+ /**
90+ * @test
91+ */
92+ public function request_with_cache ()
93+ {
94+ $ url = $ this ->urls [0 ];
95+ $ data = QueryList::get ($ url ,null ,[
96+ 'cache ' => sys_get_temp_dir (),
97+ 'cache_ttl ' => 600
98+ ])->getHtml ();
99+ $ data = json_decode ($ data ,true );
100+ $ this ->assertEquals ($ url ,$ data ['url ' ]);
101+
102+ }
88103}
Original file line number Diff line number Diff line change 1+ < div id ="one ">
2+ < ul >
3+ < li >
4+ < a href ="http://querylist.cc "> QueryList官网</ a >
5+ < img src ="http://querylist.com/1.jpg " alt ="这是图片1 " abc ="这是一个自定义属性1 ">
6+ </ li >
7+ < li >
8+ < a href ="http://v3.querylist.cc "> QueryList V3文档</ a >
9+ < img src ="http://querylist.com/2.jpg " alt ="这是图片2 " abc ="这是一个自定义属性2 ">
10+ </ li >
11+ < li >
12+ < a href ="http://v4.querylist.cc "> QueryList V4文档</ a >
13+ < img src ="http://querylist.com/3.jpg " alt ="这是图片3 " abc ="这是一个自定义属性3 ">
14+ </ li >
15+ </ ul >
16+ </ div >
You can’t perform that action at this time.
0 commit comments