Completed
Push — master ( b74cd0...088e4f )
by Dennis
11:47
created

LanguageTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 67
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A translateReturnsTranslatedString() 0 9 1
A translateWithWrongLLLKeyReturnsEmptyString() 0 9 1
A translateWithRandomStringReturnsRandomString() 0 5 1
1
<?php
2
namespace Dennis\Seeder\Tests\Unit\Traits;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2016 Dennis Römmich <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 2 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
use Dennis\Seeder\Tests\Unit\AccessibleTraitForTest;
28
use TYPO3\CMS\Core\Tests\UnitTestCase;
29
use Dennis\Seeder\Traits;
30
use TYPO3\CMS\Lang\LanguageService;
31
32
/**
33
 * Test case for class \Dennis\Seeder\Tests\Traits\LanguageTest
34
 *
35
 * @author Dennis Römmich <[email protected]>
36
 */
37
class LanguageTest extends UnitTestCase
0 ignored issues
show
Deprecated Code introduced by
The class TYPO3\CMS\Core\Tests\UnitTestCase has been deprecated with message: will be removed once TYPO3 9 LTS is released

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
38
{
39
    use AccessibleTraitForTest;
40
41
    /**
42
     * subject
43
     *
44
     * @var Traits\Language $subject
45
     */
46
    protected $subject;
47
48
    /**
49
     * setUp
50
     *
51
     * @return void
52
     */
53
    public function setUp()
0 ignored issues
show
Coding Style introduced by
setUp uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
54
    {
55
        parent::setUp();
56
57
        $GLOBALS['LANG'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(LanguageService::class);
58
        $GLOBALS['LANG']->init('default');
59
60
        $this->subject = $this->getObjectForTrait(Traits\Language::class);
61
    }
62
63
    /**
64
     * translateReturnsTranslatedString
65
     *
66
     * @test
67
     */
68
    public function translateReturnsTranslatedString()
69
    {
70
        $translation = $this->accessProtectedMethod(
71
            $this->subject,
72
            'translate',
73
            'LLL:EXT:lang/locallang_tca.xlf:pages'
74
        );
75
        $this->assertSame('Page', $translation);
76
    }
77
78
    /**
79
     * translateWithWrongArgumentShouldReturnEmptyString
80
     *
81
     * @test
82
     */
83
    public function translateWithWrongLLLKeyReturnsEmptyString()
84
    {
85
        $translation = $this->accessProtectedMethod(
86
            $this->subject,
87
            'translate',
88
            'LLL:EXT:lang/locallang_tca.xlf:FooBar'
89
        );
90
        $this->assertSame('', $translation);
91
    }
92
93
    /**
94
     * translateWithRandomStringReturnsRandomString
95
     *
96
     * @test
97
     */
98
    public function translateWithRandomStringReturnsRandomString()
99
    {
100
        $translation = $this->accessProtectedMethod($this->subject, 'translate', 'FooBar');
101
        $this->assertSame('FooBar', $translation);
102
    }
103
}
104