new things hope this works
This commit is contained in:
@@ -28,7 +28,7 @@ class FighterImporter {
|
||||
* Array of all fighters.
|
||||
* @var array[]
|
||||
*/
|
||||
protected $fighters = [];
|
||||
public $fighters = [];
|
||||
|
||||
/**
|
||||
* The current weight class.
|
||||
@@ -160,9 +160,19 @@ class FighterImporter {
|
||||
// Here you are Dan.
|
||||
// Implement caching to store instead of needing fresh requests.
|
||||
for ($i=0; $i<=100; $i++) {
|
||||
$ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15';
|
||||
$headers = [
|
||||
'referer' => true,
|
||||
'verify' => false,
|
||||
'headers' => [
|
||||
'User-Agent' => 'DC SCRAPER/v1.0',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
|
||||
'Accept-Encoding' => 'gzip, deflate, br',
|
||||
]
|
||||
];
|
||||
$url = $base_url . "&page=$i";
|
||||
$cid = "ufc:" . $url;
|
||||
$request = $this->httpClient->request('GET', $url, ['verify' => false]);
|
||||
/* $cid = "ufc:" . $url; */
|
||||
$request = $this->httpClient->request('GET', $url, $headers);
|
||||
$content = $request->getBody()->getContents();
|
||||
$check = strpos($content, "No Result Found For");
|
||||
if (!$check) {
|
||||
@@ -174,6 +184,10 @@ class FighterImporter {
|
||||
}
|
||||
}
|
||||
|
||||
public function quickTest($str) {
|
||||
return "hello$str";
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract fighters from an html string.
|
||||
*/
|
||||
|
||||
3
web/modules/custom/ufc/tests/fixtures/AthleteListing.php
vendored
Normal file
3
web/modules/custom/ufc/tests/fixtures/AthleteListing.php
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
return [];
|
||||
130
web/modules/custom/ufc/tests/src/Kernel/WebScraperKernelTest.php
Normal file
130
web/modules/custom/ufc/tests/src/Kernel/WebScraperKernelTest.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\ufc\Kernel;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\ufc\Services\FightImporter
|
||||
* @group ufc
|
||||
*/
|
||||
class WebScraperKernelTest extends UnitTestCase {
|
||||
|
||||
protected $fighterImporter;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->fighterImporter = $this->createMock('Drupal\ufc\Services\FighterImporter');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider extractFighterNamesDataProvider
|
||||
*/
|
||||
public function testExtractFighterNames($test_input) {
|
||||
$this->assertEquals("1", 2, "These do not match.");
|
||||
}
|
||||
|
||||
private function extractFighterNamesDataProvider(): array {
|
||||
return [
|
||||
['
|
||||
<ul class="l-flex--4col-1to4">
|
||||
<li class="l-flex__item">
|
||||
<div class="node node--type-athlete node--view-mode-all-athletes-result ds-1col clearfix">
|
||||
<div class="c-listing-athlete-flipcard white">
|
||||
<div class="c-listing-athlete-flipcard__inner">
|
||||
<div class="c-listing-athlete-flipcard__front">
|
||||
<div class="c-listing-athlete__thumbnail">
|
||||
<div class="field field--name-image field--type-entity-reference field--label-hidden field__item">
|
||||
<div class="layout layout--onecol">
|
||||
<div class="layout__region layout__region--content">
|
||||
<img src="https://dmxg5wxfqgb4u.cloudfront.net/styles/teaser/s3/2022-07/ABDELWAHAB_HAMDY_07-30.png?h=a30e7339&itok=hQJx5TxB" width="400" height="300" loading="lazy" class="image-style-teaser">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="c-listing-athlete__text">
|
||||
<span class="c-listing-athlete__nickname">
|
||||
<div class="field field--name-nickname field--type-string field--label-hidden">
|
||||
<div class="field__item">"The Hammer"</div>
|
||||
</div>
|
||||
</span>
|
||||
<span class="c-listing-athlete__name">
|
||||
Hamdy Abdelwahab
|
||||
</span>
|
||||
<span class="c-listing-athlete__title">
|
||||
<div class="field field--name-stats-weight-class field--type-entity-reference field--label-hidden field__items">
|
||||
<div class="field__item">Heavyweight</div>
|
||||
</div>
|
||||
</span>
|
||||
<span class="c-listing-athlete__record">5-0-0 (W-L-D)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="c-listing-athlete-flipcard__back">
|
||||
<div class="c-listing-athlete__bgimg">
|
||||
<div class="field field--name-image-body-right field--type-entity-reference field--label-hidden field__item">
|
||||
<div class="layout layout--onecol">
|
||||
<div class="layout__region layout__region--content">
|
||||
<img src="https://dmxg5wxfqgb4u.cloudfront.net/styles/event_fight_card_upper_body_of_standing_athlete/s3/2022-07/ABDELWAHAB_HAMDY_R_07-30.png?itok=pAbtNV-r" width="185" height="580" loading="lazy" class="image-style-event-fight-card-upper-body-of-standing-athlete">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="c-listing-athlete-flipcard__text__back">
|
||||
<span class="c-listing-athlete__nickname">
|
||||
<div class="field field--name-nickname field--type-string field--label-hidden">
|
||||
<div class="field__item">"The Hammer"</div>
|
||||
</div>
|
||||
</span>
|
||||
<span class="c-listing-athlete__name">
|
||||
Hamdy Abdelwahab
|
||||
</span>
|
||||
</div>
|
||||
<div class="c-listing-athlete-flipcard__action">
|
||||
<a href="/athlete/hamdy-abdelwahab" class="e-button--black "><span class="e-button__text">
|
||||
Athlete Profile
|
||||
</span></a>
|
||||
</div>
|
||||
<div class="c-listing-athlete-flipcard__footer">
|
||||
<h4>Follow</h4>
|
||||
<ul class="c-listing-athlete-flipcard__social-menu">
|
||||
<li class="c-listing-athlete-flipcard__social-item">
|
||||
<a class="c-listing-athlete-flipcard__social-link" href="https://twitter.com/Hamdyabdelwah" target="_blank">
|
||||
<span class="c-listing-athlete-flipcard__social-icon">
|
||||
<span class="e-icon--small">
|
||||
<svg class="e-icon__svg">
|
||||
<title>Twitter</title>
|
||||
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/themes/custom/ufc/assets/svg/sprite-ui.svg#twitter"></use>
|
||||
</svg>
|
||||
</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="c-listing-athlete-flipcard__social-item">
|
||||
<a class="c-listing-athlete-flipcard__social-link" href="https://instagram.com/hamdy.abdelwahab1" target="_blank">
|
||||
<span class="c-listing-athlete-flipcard__social-icon">
|
||||
<span class="e-icon--small">
|
||||
<svg class="e-icon__svg">
|
||||
<title>Instagram</title>
|
||||
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/themes/custom/ufc/assets/svg/sprite-ui.svg#instagram"></use>
|
||||
</svg>
|
||||
</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
']
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
30
web/modules/custom/ufc/tests/src/Unit/WebScraperTest.php
Normal file
30
web/modules/custom/ufc/tests/src/Unit/WebScraperTest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\ufc\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\ufc\Services\FightImporter
|
||||
* @group ufc
|
||||
*/
|
||||
class WebScraperTest extends UnitTestCase {
|
||||
|
||||
protected $fighterImporter;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->fighterImporter = $this->createMock('Drupal\ufc\Services\FighterImporter');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider extractFighterNamesDataProvider
|
||||
*/
|
||||
public function testExtractFighterNames($test_input) {
|
||||
$this->assertEquals("1", 2, "These do not match.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user