You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
979 B

2 years ago
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jaeger <JaegerCode@gmail.com>
  5. * Date: 18/12/12
  6. * Time: 下午12:25
  7. */
  8. namespace Tests\Dom;
  9. use QL\QueryList;
  10. use Tests\TestCaseBase;
  11. use Tightenco\Collect\Support\Collection;
  12. class RulesTest extends TestCaseBase
  13. {
  14. protected $html;
  15. protected $ql;
  16. protected function setUp(): void
  17. {
  18. $this->html = $this->getSnippet('snippet-2');
  19. $this->ql = QueryList::html($this->html);
  20. }
  21. /**
  22. * @test
  23. */
  24. public function get_data_by_rules()
  25. {
  26. $rules = [
  27. 'a' => ['a','text'],
  28. 'img_src' => ['img','src'],
  29. 'img_alt' => ['img','alt']
  30. ];
  31. $range = 'ul>li';
  32. $data = QueryList::rules($rules)->range($range)->html($this->html)->query()->getData();
  33. $this->assertInstanceOf(Collection::class,$data);
  34. $this->assertCount(3,$data);
  35. $this->assertEquals('http://querylist.com/2.jpg',$data[1]['img_src']);
  36. }
  37. }