Commit f8c6c13b authored by Laurent's avatar Laurent Committed by Patrick Barroca

hotline #91398 : Skilleos API Update

Conflicts:
	library/digital_resources/Skilleos/Service/Parser.php
	library/digital_resources/Skilleos/tests/SkilleosTest.php
	library/digital_resources/Skilleos/tests/results.json
parent eddb72ad
- ticket #91398 : MAJ API Skilleos
\ No newline at end of file
......@@ -23,8 +23,8 @@
class Skilleos_Service extends Class_DigitalResource_Service {
public static
$REST_URL = 'http://moncompte.skilleos.com/rest/api/trainings',
$TOKEN_URL = 'http://moncompte.skilleos.com/oauth/v2/token';
$REST_URL = 'https://moncompte.skilleos.com/rest/api/trainings',
$TOKEN_URL = 'https://moncompte.skilleos.com/oauth/v2/token';
protected
$_parser,
......@@ -73,7 +73,7 @@ class Skilleos_Service extends Class_DigitalResource_Service {
public function httpGetCatalogue() {
return $this->httpGet(static::$REST_URL,
return $this->httpGet(static::$REST_URL.'/'.$this->_config->getAdminVar('BIB_ID').'.json',
['headers' => [ 'Authorization' => 'Bearer ' . $this->getToken()]]);
}
......
......@@ -28,24 +28,34 @@ class Skilleos_Service_Parser extends Class_WebService_BibNumerique_RessourceNum
->setDescription($json->introduction.$json->description.$json->contenu_and_objectif);
$this->_lessons = [];
$this->_posters[] = isset($json->picture) ? $json->picture->url : $json->ressource->url;
$this->_posters[] = $json->picture->url;
$this->addAuthor($json->teacher->name);
foreach ($json->lessons as $lesson) {
$current=new Class_AlbumRessource();
$current->setTitre($lesson->lesson->name);
$this->_lessons[]=$current;
foreach ($json->sections as $section) {
$this->_lessons[] = $this->_buildResourceFromSection($section);
}
$this->setRessources($this->_lessons);
return $this->import();
}
protected function _buildResourceFromSection($section) {
$description="";
foreach ($section->lessons as $lesson) {
$description .= $lesson->name."\n";
}
return (new Class_AlbumRessource())
->setTitre($section->name)
->setDescription($description);
}
public function fillAlbum($album) {
return $album->setTypeDocId(Skilleos_Config::getInstance()->getDocType());
}
public function getRessourceCategorieLibelle() {
return Skilleos_Config::getInstance()->getDocTypeLabel();
}
......
......@@ -191,19 +191,25 @@ abstract class SkilleosServiceTestCase extends AbstractControllerTestCase {
$http_client = $this->mock()
->whenCalled('open_url')
->with('http://moncompte.skilleos.com/oauth/v2/token?grant_type=client_credentials&client_id=id&client_secret=secret')
->with('https://moncompte.skilleos.com/oauth/v2/token?grant_type=client_credentials&client_id=id&client_secret=secret')
->answers($token_json)
->whenCalled('open_url')
->with('http://moncompte.skilleos.com/rest/api/trainings',
->with('https://moncompte.skilleos.com/rest/api/trainings/QUEST.json',
['headers' => ['Authorization' => "Bearer YTEzMDA1M2Q1ZGRmYmE0YjJkNWQ3MGY3ZGUyYTI3ZWJkMjBjOGI2NzIzMDIzMDc0MDAyYTE0NGJjMTRmMzkzMg"]])
->answers($results_json)
->whenCalled('getResponse')
->with('https://moncompte.skilleos.com/uploads/ressources/default/0001/12/thumb_11659_default_big.png')
->with('https://moncompte.skilleos.com/uploads/ressources/default/0001/09/thumb_8235_default_big.png')
->answers(new Class_Testing_HttpResponse(['Body' => null]))
->whenCalled('getResponse')
->with('https://moncompte.skilleos.com/uploads/ressources/default/0001/12/thumb_7965_default_big.png')
->answers(new Class_Testing_HttpResponse(['Body' => null]))
->whenCalled('getResponse')
->with('https://moncompte.skilleos.com/uploads/ressources/default/0001/11/thumb_10672_default_big.png')
->with('https://moncompte.skilleos.com/uploads/ressources/default/0001/11/thumb_7966_default_big.png')
->answers(new Class_Testing_HttpResponse(['Body' => null]))
->beStrict();
......@@ -215,7 +221,6 @@ abstract class SkilleosServiceTestCase extends AbstractControllerTestCase {
$this->_service->setTimeSource(new TimeSourceForTest('2017-02-06 10:00:00'));
$this->_service->harvest();
Class_Album::clearCache();
}
}
......@@ -244,13 +249,13 @@ class SkilleosServiceHarvestTest extends SkilleosServiceTestCase {
/** @test */
public function urlOriginShouldBeSet() {
$this->assertEquals('http://skilleos.com/sigb/sso/',Class_Album::find(5)->getUrlOrigine());
$this->assertEquals('http://skilleos.com/sigb/sso/', Class_Album::find(5)->getUrlOrigine());
}
/** @test */
public function categoryShouldBeSkilleos() {
$this->assertEquals('Cours en ligne Skilleos',Class_Album::find(5)->getCategoryLabel());
$this->assertEquals('Cours en ligne Skilleos', Class_Album::find(5)->getCategoryLabel());
}
......@@ -258,30 +263,59 @@ class SkilleosServiceHarvestTest extends SkilleosServiceTestCase {
public function matiereSportEtBienEtreShouldBeCreated() {
$id = Class_Album::find(6)->getMatiere();
$labels= Class_CodifMatiere::find($id)->getLibelle();
$this->assertEquals('Sport & Bien-être', $labels);
$this->assertEquals('Arts & Musique', $labels);
}
/** @test */
public function albumTitleShouldBeMeditationRelaxation() {
$this->assertEquals('Hatha Yoga', Class_Album::find(5)->getTitre());
public function albumTitleShouldBeAfterEffectsCS6() {
$this->assertEquals('After Effects CS6 : les Fondamentaux',
Class_Album::find(5)->getTitre());
}
/** @test */
public function descriptionShouldContains() {
$this->assertContains('Des instructions pour rendre',Class_Album::find(6)->getDescription());
public function descriptionShouldContainsLEncredeChine() {
$this->assertContains('L\'encre de Chine', Class_Album::find(6)->getDescription());
}
/** @test */
public function descriptionShouldContainsEnfinUnCoursPourApprendreADessiner() {
$this->assertContains('Enfin un cours pour apprendre à dessiner',
Class_Album::find(6)->getDescription());
}
/** @test */
public function descriptionShouldContainsThemesAbordes() {
$this->assertContains('Thèmes abordés',
Class_Album::find(6)->getDescription());
}
/** @test */
public function authorShouldBeChristopheDelvalle() {
$this->assertEquals('Christophe Delvallé',
Class_Album::find(6)->getAuthors()[0]->getName());
}
/** @test */
public function posterShouldContainsExpectedUrl() {
$this->assertEquals('https://moncompte.skilleos.com/uploads/ressources/default/0001/08/thumb_7965_default_big.png', Class_Album::find(6)->getPoster());
}
/** @test */
public function authorShouldBeYogaChezMoi() {
$this->assertEquals('Tatiana Abbey', Class_Album::find(6)->getAuthors()[0]->getName());
public function ressourcesShouldContainsSectionTitles() {
$this->assertContains('LA PLUME', Class_Album::find(6)->getRessources()[0]->getTitre());
}
/** @test */
public function thumbnailShouldBeThumbDotpng() {
$this->assertEquals('https://moncompte.skilleos.com/uploads/ressources/default/0001/11/thumb_10683_default_big.png', Class_Album::find(6)->getPoster());
public function ressourceDescriptionShouldContainsLessonTitles() {
$this->assertContains('Théorie', Class_Album::find(6)->getRessources()[0]->getDescription());
}
......@@ -307,7 +341,7 @@ class SkilleosServiceHarvestTest extends SkilleosServiceTestCase {
public function withAlbumIdShouldRedirectToSkilleos() {
$this->dispatch('/opac/modules/skilleos/album_id/6',true);
$ticket = (new Class_CasTicket())->getTicketForCurrentUser();
$this->assertXPathContentContains('//script','/sigb/sso/602?casid=QUEST&ticket='.$ticket, $this->_response->getBody());
$this->assertXPathContentContains('//script','/sigb/sso/175?casid=QUEST&ticket='.$ticket, $this->_response->getBody());
}
}
......@@ -389,13 +423,13 @@ class SkilleosDashboardTest extends SkilleosServiceTestCase {
/** @test */
public function getTokenUrlShouldBePresent() {
$this->assertXPathContentContains('//pre', 'http://moncompte.skilleos.com/oauth/v2/token?grant_type=client_credentials');
$this->assertXPathContentContains('//pre', 'https://moncompte.skilleos.com/oauth/v2/token?grant_type=client_credentials');
}
/** @test */
public function getCatalogueUrlShouldBePresent() {
$this->assertXPathContentContains('//pre', 'http://moncompte.skilleos.com/rest/api/trainings');
$this->assertXPathContentContains('//pre', 'https://moncompte.skilleos.com/rest/api/trainings');
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment