Skip to content

Commit df9e3bb

Browse files
committed
test htpp cache
1 parent 0c85eed commit df9e3bb

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

tests/Dom/RulesTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Jaeger <JaegerCode@gmail.com>
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+
}

tests/Feature/HttpTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

tests/assets/snippet-2.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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>

0 commit comments

Comments
 (0)