127 lines
3.8 KiB
PHP
127 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace KupShop\I18nBundle\Tests;
|
|
|
|
use KupShop\I18nBundle\Translations\ReviewsTranslation;
|
|
use KupShop\I18nBundle\Util\AutomaticReviewsTranslation;
|
|
|
|
class AutomaticTranslationsTest extends \DatabaseTestCase
|
|
{
|
|
/** @var AutomaticReviewsTranslation */
|
|
private $automaticReviewsTranslation;
|
|
/** @var ReviewsTranslation */
|
|
private $reviewsTranslation;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->automaticReviewsTranslation = $this->get(AutomaticReviewsTranslation::class);
|
|
$this->reviewsTranslation = $this->get(ReviewsTranslation::class);
|
|
}
|
|
|
|
public function testSaveSingleObject()
|
|
{
|
|
$result = $this->reviewsTranslation->saveSingleObject('sk', 1, ['pros' => 'Test', 'cons' => 'Test', 'summary' => 'Test']);
|
|
$this->assertTrue($result);
|
|
}
|
|
|
|
public function testAutomaticReview()
|
|
{
|
|
$result = $this->automaticReviewsTranslation->translateReviews('de', 2);
|
|
$this->assertCount(2, $result['add_reviews']);
|
|
$this->assertEquals(2, $result['add_reviews'][3]);
|
|
$this->assertEquals(1, $result['add_reviews'][4]);
|
|
}
|
|
|
|
public function testGetTranslations()
|
|
{
|
|
$result = $this->automaticReviewsTranslation->getReviewsForTranslation('de', 3, 'cs');
|
|
$this->assertCount(4, $result);
|
|
$this->assertEquals(0, $result[0]['actualCount']);
|
|
$this->assertEquals(1, $result[3]['actualCount']);
|
|
}
|
|
|
|
protected function getDataSet()
|
|
{
|
|
return $this->getJsonDataSet('
|
|
{
|
|
"reviews": [
|
|
{
|
|
"id":1,
|
|
"id_product" :3,
|
|
"pros":"Klady 1",
|
|
"cons":"Nevýhody 1",
|
|
"summary":"Shrnutí 1",
|
|
"figure":"3",
|
|
"id_language":"cs"
|
|
},
|
|
{
|
|
"id":2,
|
|
"id_product":3,
|
|
"pros":"Klady 2",
|
|
"cons":"Nevýhody 2",
|
|
"summary":"Shrnutí 2",
|
|
"figure":"3",
|
|
"id_language":"cs"
|
|
}
|
|
,{
|
|
"id":3,
|
|
"id_product":4,
|
|
"pros":"Klady 3",
|
|
"cons":"Nevýhody 3",
|
|
"summary":"Shrnutí 3",
|
|
"figure":"3",
|
|
"id_language":"cs"
|
|
},
|
|
{
|
|
"id":4,
|
|
"id_product":4,
|
|
"pros":"Klady 4",
|
|
"cons":"Nevýhody 4",
|
|
"summary":"Shrnutí 4",
|
|
"figure":"3",
|
|
"id_language":"cs"
|
|
},
|
|
{
|
|
"id":5,
|
|
"id_product":4,
|
|
"pros":"Klady 5",
|
|
"cons":"Nevýhody 5",
|
|
"summary":"Shrnutí 5",
|
|
"figure":"5",
|
|
"id_language":"sk"
|
|
} ,
|
|
{
|
|
"id":6,
|
|
"id_product":6,
|
|
"pros":"Klady 5",
|
|
"cons":"Nevýhody 5",
|
|
"summary":"Shrnutí 5",
|
|
"figure":"3",
|
|
"id_language":"de"
|
|
},
|
|
{
|
|
"id":7,
|
|
"id_product":4,
|
|
"pros":"Klady 6",
|
|
"cons":"Nevýhody 6",
|
|
"summary":"Shrnutí 6",
|
|
"figure":"3",
|
|
"id_language":"cs"
|
|
}
|
|
],
|
|
"reviews_translations": [
|
|
{
|
|
"id":1,
|
|
"id_review":7,
|
|
"pros":"DE Klady 1",
|
|
"cons":"DE Nevýhody 1",
|
|
"summary":"DE Shrnutí 1",
|
|
"id_language":"de"
|
|
}
|
|
]
|
|
}');
|
|
}
|
|
}
|