Skip to content
Snippets Groups Projects
Commit 5733c86a authored by gloas's avatar gloas
Browse files

Ajout des tests couvrant l'accès à l'url de Vodéclic (vérification de l'encryption)

parent 4c34e4f2
Branches
Tags
No related merge requests found
......@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Webservice_Vodeclic {
class Class_Webservice_Vodeclic extends Class_WebService_Abstract {
protected $_albums;
public function parseXML($xml) {
......@@ -29,9 +29,39 @@ class Class_Webservice_Vodeclic {
}
public function harvest($partenaire_id,$key,$bib_id) {
$http_client = self::getHttpClient();
$content = $http_client->open_url($this->url($partenaire_id,$key,$bib_id));
$catalogue = $this->parseXML($content);
}
public function getAlbums() {
return $this->_albums;
}
public function url($partenaire_id,$key,$bib){
$partenaire = 'partenaire='.$partenaire_id;
$bib_id = '&bib_id='.$bib;
$encrypted_partenaire = '&encrypted_partenaire='.$this->encryptedPartenaire($partenaire_id,$key);
$result=$this->baseUrl().$partenaire.$encrypted_partenaire.$bib_id;
return $result;
}
public function baseUrl(){
return "https://lms.vodeclic.com/api/catalogue.xml?";
}
public function encryptedPartenaire($partenaire_id,$key){
$hash = Class_Hash::sha256WithKey('');
return $hash->encrypt($partenaire_id.$key);
}
}
?>
\ No newline at end of file
......@@ -20,7 +20,8 @@
*/
class Class_WebService_Vodeclic_CatalogueParser {
protected $_albums,
protected
$_albums,
$_current_album;
public function parseXML($xml) {
......
......@@ -28,15 +28,23 @@ class VodeclicTest extends Storm_Test_ModelTestCase{
Class_AdminVar::newInstanceWithId('VODECLIC_KEY', ['valeur' => '12345']);
Class_AdminVar::newInstanceWithId('VODECLIC_BIB_ID', ['valeur' => '12']); */
$this->_partenaire_id = 'api-test';
$this->_key = '6m5js1dPpFNrtAJbsfXO';
$this->_bib_id = "12";
$catalogue_xml = file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/vodeclic_catalogue.xml');
/* $this->_http_client = Storm_Test_ObjectWrapper::mock();
$this->_http_client = Storm_Test_ObjectWrapper::mock();
$this->_http_client
->whenCalled('https://lms.vodeclic.com/api/catalogue.xml')
->answers($catalogue_xml);*/
->whenCalled('open_url')
->with('https://lms.vodeclic.com/api/catalogue.xml?partenaire=api-test&encrypted_partenaire=f13eba4953115a58bdf7952266ecca9fee8f91ddac6ac901042fdb188db02778&bib_id=12')
->answers($catalogue_xml);
Class_WebService_Vodeclic::setDefaultHttpClient($this->_http_client);
$this->_vodeclic = new Class_WebService_Vodeclic();
$this->_vodeclic->parseXML($catalogue_xml);
$this->_vodeclic->harvest($this->_partenaire_id, $this->_key, $this->_bib_id);
$this->_first_album = $this->_vodeclic->getAlbums()[0];
}
......@@ -45,7 +53,6 @@ class VodeclicTest extends Storm_Test_ModelTestCase{
* @test
*/
public function firstAlbumTitreShouldBeSafari2() {
//$first_album = $this->_vodeclic->getAlbums()[0];
$this->assertEquals('Safari 2', $this->_first_album->getTitre());
}
......@@ -57,40 +64,33 @@ class VodeclicTest extends Storm_Test_ModelTestCase{
/** @test */
public function firstAlbumSafari2IdOrigineShouldBe1() {
//$first_album = $this->_vodeclic->getAlbums()[0];
$this->assertEquals('1', $this->_first_album->getIdOrigine());
}
/** @test */
public function firstAlbumSafari2LinkShouldBeSet() {
//$first_Album = $this->_vodeclic->getAlbums()[0];
$this->assertEquals('http://biblio.vodeclic.com/formation/1',$this->_first_album->getUrlOrigine());
}
/** @test */
public function firstAlbumSafari2DesciptionShouldBeSet() {
//$first_ALbum = $this->_vodeclic->getAlbums()[0];
$this->assertEquals("Le parcours pédagogiques Safari 2 de A à Z va vous permettre de prendre complètement en main ce navigateur internet installé par défaut sur tous les ordinateurs Apple. Vous y découvrirez une navigation sur Internet simplifiée à l'aide de la barre d'adresse, du champs de recherche Google, des onglets de Safari 2… Nos vidéos-formations vous apprendront également des astuces pour mieux vivre internet au quotidien avec Safari 2. Ainsi vous apprendrez à maîtriser l'historique, vos signets, les formulaires de remplissage automatique et plein d'autres choses !",$this->_first_album->getDescription());
}
/** @test */
public function firstAlbumSafari2IdLangueShouldBeFre() {
//$first_Album = $this->_vodeclic->getAlbums()[0];
$this->assertEquals('fre',$this->_first_album->getIdLangue());
}
/** @test */
public function firstAlbumSafari2DateMajShouldBeSet (){
//$first_Album = $this->_vodeclic->getAlbums()[0];
$this->assertEquals('2007-08-01T00:00:00+02:00',$this->_first_album->getDateMaj());
}
/** @test */
public function firstAlbumSafari2AnneeShouldBe2007 (){
//$first_Album = $this->_vodeclic->getAlbums()[0];
$this->assertEquals('2007',$this->_first_album->getAnnee());
}
}
}
?>
\ No newline at end of file
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