diff --git a/tests/Dom/RulesTest.php b/tests/Dom/RulesTest.php new file mode 100644 index 0000000..d2d70a7 --- /dev/null +++ b/tests/Dom/RulesTest.php @@ -0,0 +1,43 @@ + + * 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']); + } +} \ No newline at end of file diff --git a/tests/Feature/HttpTest.php b/tests/Feature/HttpTest.php index 493cfbb..cba79e3 100644 --- a/tests/Feature/HttpTest.php +++ b/tests/Feature/HttpTest.php @@ -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']); + + } } \ No newline at end of file diff --git a/tests/assets/snippet-2.html b/tests/assets/snippet-2.html new file mode 100644 index 0000000..88ae3f0 --- /dev/null +++ b/tests/assets/snippet-2.html @@ -0,0 +1,16 @@ +