forked from ezsystems/ezpublish-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LanguageServiceMaximumSupportedLanguagesTest.php
108 lines (91 loc) · 3.42 KB
/
LanguageServiceMaximumSupportedLanguagesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* File containing the LanguageServiceMaximumSupportedLanguagesTest class
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace eZ\Publish\API\Repository\Tests;
use eZ\Publish\API\Repository\Tests\SetupFactory\Legacy as LegacySetupFactory;
/**
* Test case for maximum number of languages supported in the LanguageService.
*
* @see eZ\Publish\API\Repository\LanguageService
* @group integration
* @group language
*/
class LanguageServiceMaximumSupportedLanguagesTest extends BaseTest
{
/**
* @var \eZ\Publish\API\Repository\LanguageService
*/
private $languageService;
/**
* @var array
*/
private $createdLanguages = array();
/**
* Creates as much languages as possible
*/
public function setUp()
{
parent::setUp();
$this->languageService = $this->getRepository()->getContentLanguageService();
$languageCreate = $this->languageService->newLanguageCreateStruct();
$languageCreate->enabled = true;
// SKIP If using sqlite, PHP 5.3 and 64bit, tests will fail as int column seems to be limited to 32bit on 64bit
if ( PHP_VERSION_ID < 50400 && PHP_INT_SIZE === 8 )
{
$setupFactory = $this->getSetupFactory();
if ( $setupFactory instanceof LegacySetupFactory && $setupFactory->getDB() === 'sqlite' )
{
$this->markTestSkipped( "Skip on Sqlite, PHP 5.3 and 64bit, as int column is limited to 32bit on 64bit" );
}
}
// Create as much languages as possible
for ( $i = count( $this->languageService->loadLanguages() ) + 1; $i <= 8 * PHP_INT_SIZE - 2; ++$i )
{
$languageCreate->name = "Language $i";
$languageCreate->languageCode = sprintf( "lan-%02d", $i );
try
{
$this->createdLanguages[] = $this->languageService->createLanguage( $languageCreate );
}
catch ( \Exception $e )
{
if ( PHP_INT_SIZE === 8 && $i === 32 )
{
throw new \Exception( "PHP/HHVM is 64bit, but seems INT column in db only supports 32bit", 0, $e );
}
throw new \Exception( "Unknown issue on iteration $i, PHP_INT_SIZE: " . PHP_INT_SIZE, 0, $e );
}
}
}
public function tearDown()
{
while ( ( $language = array_pop( $this->createdLanguages ) ) !== null )
{
$this->languageService->deleteLanguage( $language );
}
parent::tearDown();
}
/**
* Test for the number of maximum language that can be created.
*
* @see \eZ\Publish\API\Repository\LanguageService::createLanguage()
*
* @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testNewLanguageCreateStruct
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Maximum number of languages reached!
*/
public function testCreateMaximumLanguageLimit()
{
$languageCreate = $this->languageService->newLanguageCreateStruct();
$languageCreate->enabled = true;
$languageCreate->name = "Bad Language";
$languageCreate->languageCode = "lan-ER";
$this->languageService->createLanguage( $languageCreate );
}
}