public function testFromJson()
 {
     $jsonObject = $this->getJsonObject('image.json');
     $image = Image::createFromJson($jsonObject);
     $this->assertNotNull($image->getBaseUrl());
     $this->assertEquals('hash1', $image->getHash());
     $this->assertEquals('.jpg', $image->getExt());
     $this->assertEquals('image/jpeg', $image->getMimetype());
     $this->assertEquals(12345678, $image->getFilesize());
     $this->assertEquals(array('tag1', 'tag2'), $image->getTags());
     $imageSize = $image->getImageSize();
     $this->assertInstanceOf('\\AboutYou\\SDK\\Model\\ImageSize', $imageSize);
     $this->assertEquals(1400, $imageSize->getWidth());
     $this->assertEquals(2000, $imageSize->getHeight());
     $image->setBaseUrl();
     $this->assertStringStartsWith('/hash1', $image->getUrl());
     $image->setBaseUrl(false);
     $this->assertStringStartsWith('/hash1', $image->getUrl());
     $image->setBaseUrl(null);
     $this->assertStringStartsWith('/hash1', $image->getUrl());
     $image->setBaseUrl('');
     $this->assertStringStartsWith('/hash1', $image->getUrl());
     $this->assertStringStartsWith('/hash1?width=123&height=456', $image->getUrl(123, 456));
     $ay = new \AY('appid', 'pw');
     $ay->getResultFactory();
     $this->assertStringStartsWith(\AY::IMAGE_URL_LIVE . '/hash1', $image->getUrl());
     $ay->setBaseImageUrl('http://domain.tld');
     $this->assertStringStartsWith('http://domain.tld/hash1', $image->getUrl());
     $ay->setBaseImageUrl(false);
     $this->assertStringStartsWith('/hash1', $image->getUrl());
     $ay->setBaseImageUrl(null);
     $this->assertStringStartsWith(\AY::IMAGE_URL_LIVE . '/hash1', $image->getUrl());
     $ay->getResultFactory()->setBaseImageUrl('http://domain2.tld');
     $this->assertStringStartsWith('http://domain2.tld/hash1', $image->getUrl());
     Image::setBaseUrl('http://domain3.tld');
     $this->assertStringStartsWith('http://domain3.tld/hash1', $image->getUrl());
     $this->assertNull($image->getAdditionalItems());
     $this->assertNull($image->getAngle());
     $this->assertNull($image->getBackground());
     $this->assertNull($image->getColor());
     $this->assertNull($image->getFocus());
     $this->assertNull($image->getGender());
     $this->assertNull($image->getModelData());
     $this->assertNull($image->getNextDetailLevel());
     $this->assertNull($image->getPreparation());
     $this->assertNull($image->getView());
     $this->assertNull($image->getType());
 }
예제 #2
0
 public function testConstructorWithDefaultStrategy()
 {
     $appId = '123';
     $appPassword = '******';
     $apiEndPoint = 'http://localhost.dev/api';
     $loggerInterfaceImplementation = $this->getMock('\\Psr\\Log\\LoggerInterface');
     $cacheMock = $this->getMockForAbstractClass('\\Aboutyou\\Common\\Cache\\CacheProvider');
     $ay = new \AY($appId, $appPassword, $apiEndPoint, null, $loggerInterfaceImplementation, $cacheMock);
     $this->assertEquals($apiEndPoint, $ay->getApiEndPoint());
     $this->assertEquals($loggerInterfaceImplementation, $ay->getLogger());
     $factory = $ay->getResultFactory();
     $this->assertInstanceOf('\\AboutYou\\SDK\\Factory\\DefaultModelFactory', $factory);
     $facetManager = $factory->getFacetManager();
     $this->assertInstanceOf('\\AboutYou\\SDK\\Model\\FacetManager\\DefaultFacetManager', $facetManager);
     /**
      * relies on internal configuration of live image url as constant
      */
     $this->assertEquals(\AY::IMAGE_URL_LIVE, $ay->getBaseImageUrl());
 }
 /**
  * @return \AboutYou\SDK\Factory\ModelFactoryInterface
  */
 protected function getModelFactory()
 {
     $ay = new \AY('id', 'token');
     return $ay->getResultFactory();
 }
 public function getProduct($filename)
 {
     $json = $this->getJsonObjectFromFile('product/' . $filename);
     $product = Product::createFromJson($json, $this->ay->getResultFactory(), 98);
     return $product;
 }