Commit 13e17b15 authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

FIX(tags): redirect view method when is HTML format

Refs: #954
parent edf51ca2
Pipeline #13560 passed with stage
in 6 minutes and 40 seconds
......@@ -160,7 +160,11 @@ class TagsController extends AppController
}
/**
* View method of a given tag
* API view method of a given tag
*
* URL : API /$lang/tags/$idTag.json
* Webapp /$lang/tags/$idTag ---> redirect 301 to /$lang/tags/$idTag/software
* /$lang/tags/$idTag/ ---> redirect 301 to /$lang/tags/$idTag/software
*
* @param string|null $id Tag id.
* @return Response|null
......@@ -168,17 +172,23 @@ class TagsController extends AppController
*/
public function view($id = null)
{
if ($this->request->is('json')) {
$tag = $this->Tags->get(
$id,
['contain' => ['Softwares']]
);
$tag = $this->Tags->get(
$id,
['contain' => ['Softwares']]
);
$this->set('tag', $tag);
$this->set('_serialize', ['tag']);
return null;
$this->set('tag', $tag);
$this->set('_serialize', ['tag']);
return null;
} else {
$idTag = (int) $id;
$lang = $this->selectedLanguage;
return $this->redirect("/$lang/tags/$idTag/software", 301);
}
}
/**
* Returns a list of software associated to a given tag
*
......
......@@ -198,7 +198,36 @@ class TagsControllerTest extends ApiIntegrationTestCase
}
/**
* Test view method of Tags controller. Show us all data of one tag, here is tested tag id=4.
* Test view method of Tags controller for HTML format
* must redirect to new tag URL
*
* URL : Webapp /$lang/tags/$idTag ---> redirect 301 to /$lang/tags/$idTag/software
* /$lang/tags/$idTag/ ---> redirect 301 to /$lang/tags/$idTag/software
*
* @group public
* @group tag
* @group tag_public
* @group tag_method_view
*
* @return void
*/
public function testViewMethodForHtmlFormat()
{
$this->get('/tags/4');
$this->currentResponseIsRedirectionToAnotherUrl('/en/tags/4/software', 301);
$this->get('/fr/tags/4');
$this->currentResponseIsRedirectionToAnotherUrl('/fr/tags/4/software', 301);
$this->get('/fr/tags/4/');
$this->currentResponseIsRedirectionToAnotherUrl('/fr/tags/4/software', 301);
}
/**
* Test API view method of Tags controller for JSON format.
* Show us all data of one tag, here is tested tag id=4.
*
* URL : API /$lang/tags/$idTag.json
*
* @group public
* @group tag
......@@ -207,7 +236,7 @@ class TagsControllerTest extends ApiIntegrationTestCase
*
* @return void
*/
public function testView()
public function testViewMethodForJsonFormat()
{
$this->get('/api/v1/tags/4.json');
......
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