2017-04-03 06:30:01 +02:00
|
|
|
<?php
|
|
|
|
|
2017-06-29 08:45:17 +02:00
|
|
|
namespace SilverStripe\View\Tests\Shortcodes;
|
2017-04-03 06:30:01 +02:00
|
|
|
|
|
|
|
use Embed\Http\DispatcherInterface;
|
|
|
|
use Embed\Http\ImageResponse;
|
|
|
|
use Embed\Http\Response;
|
|
|
|
use Embed\Http\Url;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
|
|
|
|
class MockResolver implements DispatcherInterface
|
|
|
|
{
|
|
|
|
protected $url = null;
|
|
|
|
|
|
|
|
protected $expectedContent = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor. Sets the url.
|
|
|
|
*
|
|
|
|
* @param string $url The url value
|
|
|
|
* @param array $config The resolver configuration
|
|
|
|
*/
|
|
|
|
public function __construct($url, array $config)
|
|
|
|
{
|
|
|
|
$this->url = $url;
|
|
|
|
if (empty($config['expectedContent'])) {
|
|
|
|
throw new InvalidArgumentException("Mock resolvers need expectedContent");
|
|
|
|
}
|
|
|
|
$this->expectedContent = $config['expectedContent'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch an url.
|
|
|
|
*
|
|
|
|
* @param Url $url
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function dispatch(Url $url)
|
|
|
|
{
|
|
|
|
return new Response(
|
|
|
|
$url,
|
|
|
|
$url,
|
|
|
|
200,
|
|
|
|
'application/json',
|
|
|
|
$this->expectedContent,
|
|
|
|
[],
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve multiple image urls at once.
|
|
|
|
*
|
|
|
|
* @param Url[] $urls
|
|
|
|
*
|
|
|
|
* @return ImageResponse[]
|
|
|
|
*/
|
|
|
|
public function dispatchImages(array $urls)
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|