Passed
Branch master (c443f0)
by Johan
04:00
created

SetupCreateObjectTest::testPlaceCard()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
// php artisan test
4
namespace Tests\Unit;
5
6
use Tests\TestCase;
7
use Joki20\Http\Controllers\PokerSquares;
8
use Joki20\Http\Controllers\Setup;
9
/**
10
 * Test cases for class Guess.
11
 */
12
class SetupCreateObjectTest extends TestCase
13
{
14
    // /**
15
    //  * Construct object and verify that the object is instance of class
16
    //  */
17
    public function testCreateObjectPokerSquares()
18
    {
19
        $setup = new Setup();
20
        $this->assertInstanceOf("\Joki20\Http\Controllers\Setup", $setup);
21
    }
22
23
    public function testSetupName()
24
    {
25
        $setup = new Setup();
26
27
        $exp = 265;
28
        $res = strlen($setup->name());
29
30
        $this->assertEquals($exp, $res);
31
32
        $exp = '<div class="enterName"><form method="POST" autocomplete="off">
33
                <input type="text" name="setName" placeholder="Name" minlength=3 onfocus=this.placeholder = required >
34
                <input type="submit" value="GO">
35
            </form></div>
36
        ';
37
        $res = $setup->name();
38
        $this->assertEquals($exp, $res);
39
    }
40
41
    public function testPrepareSessions()
42
    {
43
        $setup = new Setup();
44
        $_POST['setName'] = 'Johan';
45
        $setup->prepareSessions();
46
47
        $exp = 'Johan';
48
        $res = session('name');
49
        $this->assertEquals($exp, $res);
50
    }
51
52
    public function testShuffleDeck()
53
    {
54
        $setup = new Setup();
55
56
        $setup->shuffleDeck();
57
        $firstShuffle = session('deck');
58
        $setup->shuffleDeck();
59
        $secondShuffle = session('deck');
60
        $this->assertNotEquals($firstShuffle, $secondShuffle);
61
    }
62
63
    public function testPrepareStack()
64
    {
65
        $setup = new Setup();
66
        //
67
        session()->put('deck', ['a','b','c','d','e','f']);
68
        $beforeFirstValue = session('deck')[0];
69
        $setup->prepareStack(); // reverses order of array
70
        $afterLastValue = session('deck')[5];
71
        $this->assertEquals($beforeFirstValue, $afterLastValue);
72
73
    }
74
75
    public function testDisplayGrid()
76
    {
77
        $setup = new Setup();
78
79
        session()->put('scoreRow0.score', 10);
80
        session()->put('scoreRow1.score', 10);
81
        session()->put('scoreRow2.score', 10);
82
        session()->put('scoreRow3.score', 10);
83
        session()->put('scoreRow4.score', 10);
84
        session()->put('scoreColumn0.score', 10);
85
        session()->put('scoreColumn1.score', 10);
86
        session()->put('scoreColumn2.score', 10);
87
        session()->put('scoreColumn3.score', 10);
88
        session()->put('scoreColumn4.score', 10);
89
90
        $setup->displayGrid();
91
        $exp = 100;
92
        $res = session('totalScore');
93
94
        $this->assertEquals($exp, $res);
95
96
        session()->put('round', 20);
97
        $substring = '<tr>';
98
        $exp = $setup->displayGrid();
99
        $this->assertStringContainsString($substring, $exp);
100
    }
101
102
    public function testPlaceCard() {
103
        $setup = new Setup();
104
105
        session()->put('deck', [1,2,3,4,5,6,7,8,9]);
106
        $_POST['position'] = '00';
107
        session()->put('round', 14);
108
        $setup->placeCard();
109
110
        $exp = 15;
111
        $res = session('round');
112
113
        $this->assertEquals($exp, $res);
114
    }
115
116
}
117