1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file contains only the ApiControllerTest class. |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Tests\AppBundle\Controller; |
7
|
|
|
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
9
|
|
|
use Symfony\Component\DependencyInjection\Container; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Integration tests for XTools' external API. |
13
|
|
|
* @group integration |
14
|
|
|
*/ |
15
|
|
|
class ApiControllerTest extends WebTestCase |
16
|
|
|
{ |
17
|
|
|
/** @var Container The DI container. */ |
18
|
|
|
protected $container; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Create the HTTP client and get the DI container. |
22
|
|
|
*/ |
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$client = static::createClient(); |
26
|
|
|
$this->container = $client->getContainer(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Test that we can retrieve the namespace information. |
31
|
|
|
*/ |
32
|
|
|
public function testNamespaces() |
33
|
|
|
{ |
34
|
|
|
$client = static::createClient(); |
35
|
|
|
$isSingle = $this->container->getParameter('app.single_wiki'); |
36
|
|
|
|
37
|
|
|
// Test 404 (for single-wiki setups, that wiki's namespaces are always returned). |
38
|
|
|
$crawler = $client->request('GET', '/api/namespaces/wiki.that.doesnt.exist.org'); |
39
|
|
|
if ($isSingle) { |
40
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
41
|
|
|
} else { |
42
|
|
|
$this->assertEquals(404, $client->getResponse()->getStatusCode()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (!$isSingle && $this->container->getParameter('app.is_labs')) { |
46
|
|
|
$crawler = $client->request('GET', '/api/namespaces/fr.wikipedia.org'); |
47
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
48
|
|
|
|
49
|
|
|
// Check that a correct namespace value was returned |
50
|
|
|
$response = (array) json_decode($client->getResponse()->getContent()); |
51
|
|
|
$namespaces = (array) $response['namespaces']; |
52
|
|
|
$this->assertEquals('Utilisateur', array_values($namespaces)[2]); // User in French |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|