Skip to content

Commit

Permalink
test htpp cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jae-jae committed Dec 12, 2018
1 parent 0c85eed commit df9e3bb
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/Dom/RulesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Created by PhpStorm.
* User: Jaeger <[email protected]>
* Date: 18/12/12
* Time: 下午12:25
*/

namespace Tests\Dom;


use QL\QueryList;
use Tests\TestCaseBase;
use Tightenco\Collect\Support\Collection;

class RulesTest extends TestCaseBase
{
protected $html;
protected $ql;

public function setUp()
{
$this->html = $this->getSnippet('snippet-2');
$this->ql = QueryList::html($this->html);
}

/**
* @test
*/
public function get_data_by_rules()
{
$rules = [
'a' => ['a','text'],
'img_src' => ['img','src'],
'img_alt' => ['img','alt']
];
$range = 'ul>li';
$data = QueryList::rules($rules)->range($range)->html($this->html)->query()->getData();
$this->assertInstanceOf(Collection::class,$data);
$this->assertCount(3,$data);
$this->assertEquals('http://querylist.com/2.jpg',$data[1]['img_src']);
}
}
15 changes: 15 additions & 0 deletions tests/Feature/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,19 @@ public function concurrent_requests_advanced_use()
})
->send();
}

/**
* @test
*/
public function request_with_cache()
{
$url = $this->urls[0];
$data = QueryList::get($url,null,[
'cache' => sys_get_temp_dir(),
'cache_ttl' => 600
])->getHtml();
$data = json_decode($data,true);
$this->assertEquals($url,$data['url']);

}
}
16 changes: 16 additions & 0 deletions tests/assets/snippet-2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div id="one">
<ul>
<li>
<a href="http://querylist.cc">QueryList官网</a>
<img src="http://querylist.com/1.jpg" alt="这是图片1" abc="这是一个自定义属性1">
</li>
<li>
<a href="http://v3.querylist.cc">QueryList V3文档</a>
<img src="http://querylist.com/2.jpg" alt="这是图片2" abc="这是一个自定义属性2">
</li>
<li>
<a href="http://v4.querylist.cc">QueryList V4文档</a>
<img src="http://querylist.com/3.jpg" alt="这是图片3" abc="这是一个自定义属性3">
</li>
</ul>
</div>

0 comments on commit df9e3bb

Please sign in to comment.