Completed
Push — master ( 597ac5...b01469 )
by Robbie
9s
created

testGenericOutputIsGivenAboutContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace SilverLeague\Console\Tests\Command\Object;
4
5
use SilverLeague\Console\Tests\Command\AbstractCommandTest;
6
use SilverStripe\Security\Member;
7
use Symfony\Component\Console\Tester\CommandTester;
8
9
/**
10
 * @coversDefaultClass \SilverLeague\Console\Command\Object\DebugCommand
11
 * @package silverstripe-console
12
 * @author  Robbie Averill <[email protected]>
13
 */
14
class DebugCommandTest extends AbstractCommandTest
15
{
16
    /**
17
     * @var Member
18
     */
19
    protected $member;
20
21
    /**
22
     * Get a member to test with
23
     */
24
    public function setUp()
25
    {
26
        parent::setUp();
27
        $this->member = Member::get()->first();
28
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    protected function getTestCommand()
34
    {
35
        return 'object:debug';
36
    }
37
38
    /**
39
     * Test that when an invalid class name (non existent or not a DataObject) is given that an error is returned
40
     */
41
    public function testErrorWhenInvalidClassNameProvided()
42
    {
43
        $tester = $this->executeTest(['object' => "A\B\C\D\E\F\G"]);
44
        $this->assertContains('does not exist', $tester->getDisplay());
45
46
        $tester = $this->executeTest(['object' => "SilverStripe\Core\Object"]);
47
        $this->assertContains('is not a DataObject', $tester->getDisplay());
48
    }
49
50
    /**
51
     * Test that when all required arguments are provided and valid the data is retrieved and output directly
52
     */
53
    public function testGetDataImmediatelyWhenAllArgumentsProvidedAndSortingIsApplied()
54
    {
55
        $tester = $this->executeTest(['object' => Member::class, 'id' => $this->member->ID]);
56
        $display = $tester->getDisplay();
57
        $this->assertContains($this->member->Email, $display);
58
59
        // Should be identical
60
        $tester2 = $this->executeTest(['object' => Member::class, 'id' => $this->member->ID]);
61
        $this->assertSame($display, $tester2->getDisplay());
62
63
        // Should be different
64
        $tester3 = $this->executeTest(['object' => Member::class, 'id' => $this->member->ID, '--no-sort' => true]);
65
        $this->assertNotSame($display, $tester3->getDisplay());
66
    }
67
68
    /**
69
     * Simuluating the interactive input, test that we can lookup a model by a column and a value. Also test
70
     * that password columns are not returned
71
     */
72
    public function testSearchMemberByColumn()
73
    {
74
        $tester = new CommandTester($this->command);
75
76
        // Simulate interactive inputs
77
        $tester->setInputs(['Email', $this->member->Email]);
78
79
        $tester->execute(['object' => Member::class]);
80
        $display = $tester->getDisplay();
81
        $this->assertContains($this->member->Email, $display);
82
83
        // Check there's no passwords in the output
84
        $this->assertNotContains('Password', $display);
85
    }
86
87
    /**
88
     * Ensure that table output can be returned if the option is provided
89
     */
90
    public function testCanOutputAsTable()
91
    {
92
        $tester = $this->executeTest(['object' => Member::class, 'id' => $this->member->ID, '--output-table' => true]);
93
94
        $this->assertContains('+--------', $tester->getDisplay());
95
    }
96
97
    /**
98
     * Test that generic info output is provided about the class and ID
99
     */
100
    public function testGenericOutputIsGivenAboutContext()
101
    {
102
        $tester = $this->executeTest(['object' => Member::class, 'id' => $this->member->ID]);
103
104
        $display = $tester->getDisplay();
105
        $this->assertContains('Object: ' . Member::class, $display);
106
        $this->assertContains('ID: ' . $this->member->ID, $display);
107
    }
108
}
109