<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Http\Controllers\GoogleShoppingController;
class GoogleShoppingControllerTest extends TestCase {
public function testGoogleShoppingSearchResultsAreReturned() {
$g = new GoogleShoppingController();
$urls = $g->getGoogleShoppingSearchResults();
// assert that the function only returns an array
$this->assertTrue(is_array($urls));
// assert that the search query actually results links w/ query strings
$this->assertContains('query', $urls);
}
public function testParseGoogleShoppingProductLinks() {
$g = new GoogleShoppingController();
$urls = $g->parseGoogleShoppingProductLinks();
// assert that the function only returns an array
$this->assertTrue(is_array($urls));
// asssert that array items contain only links beignning
// with string => '/shopping/product/*'
foreach ($urls as $url) {
$this->assertContains('/shopping/product/', $url);
}
}
public function testParseGoogleSponsoredProductLinks() {
$g = new GoogleShoppingController();
$urls = $g->parseGoogleShoppingProductLinks();
// assert that the function only returns an array
$this->assertTrue(is_array($urls));
// asssert that array items contain only links to google sponsored products
// checking for 'http' because the function will only return arrays containing
// original store page links
// with string => 'http'
foreach ($urls as $url) {
$this->assertContains('http', $url);
}
}
}