Completed
Pull Request — master (#58)
by Nic
08:29
created

OrderHistoryControllerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
c 1
b 0
f 0
dl 0
loc 99
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 25 1
A testTestOrderHistoryControllerPermission() 0 16 1
A testOrderPaginatedList() 0 15 1
1
<?php
2
3
namespace Dynamic\Foxy\Orders\Tests\Controller;
4
5
use Dynamic\Foxy\Extension\Purchasable;
6
use Dynamic\Foxy\Model\Variation;
7
use Dynamic\Foxy\Orders\Model\Order;
8
use Dynamic\Foxy\Orders\Page\OrderHistory;
9
use Dynamic\Foxy\Orders\Page\OrderHistoryController;
10
use Dynamic\Foxy\Orders\Tests\TestOnly\Extension\TestVariationDataExtension;
11
use Dynamic\Foxy\Orders\Tests\TestOnly\Page\TestProduct;
12
use SilverStripe\Dev\FunctionalTest;
13
use SilverStripe\ORM\ArrayList;
14
use SilverStripe\ORM\PaginatedList;
15
use SilverStripe\ORM\ValidationException;
16
use SilverStripe\Security\Member;
17
use SilverStripe\Versioned\Versioned;
18
19
/**
20
 * Class OrderHistoryControllerTest
21
 * @package Dynamic\Foxy\Orders\Tests\Controller
22
 */
23
class OrderHistoryControllerTest extends FunctionalTest
24
{
25
    /**
26
     * @var string[]
27
     */
28
    protected static $fixture_file = [
29
        '../orders.yml',
30
        '../orderhistory.yml',
31
        '../customers.yml',
32
    ];
33
34
    /**
35
     * @var string[]
36
     */
37
    protected static $extra_dataobjects = [
38
        TestProduct::class,
39
    ];
40
41
    /**
42
     * @var \string[][]
43
     */
44
    protected static $required_extensions = [
45
        Variation::class => [
46
            TestVariationDataExtension::class,
47
        ],
48
        TestProduct::class => [
49
            Purchasable::class,
50
        ],
51
    ];
52
53
    /**
54
     * @throws ValidationException
55
     */
56
    protected function setUp()
57
    {
58
        parent::setUp();
59
60
        /*$factory = Injector::inst()->create(FixtureFactory::class);
61
62
        $blueprint = Injector::inst()->create(FixtureBlueprint::class, OrderHistory::class);
63
64
        $blueprint->addCallback('afterCreate', function ($obj, $identifier, $data, $fixtures) {
65
            $obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
66
        });
67
68
        $factory->define('OrderHistory', $blueprint);//*/
69
70
        /** @var OrderHistory $page */
71
        $page = $this->objFromFixture(OrderHistory::class, 'one');
72
        $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
0 ignored issues
show
Bug introduced by
The method copyVersionToStage() does not exist on Dynamic\Foxy\Orders\Page\OrderHistory. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        $page->/** @scrutinizer ignore-call */ 
73
               copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
Loading history...
73
74
        /** @var Order $order */
75
        $order = $this->objFromFixture(Order::class, 'one');
76
        /** @var Member $customer */
77
        $customer = $this->idFromFixture(Member::class, 'customerone');
78
79
        $order->MemberID = $customer;
0 ignored issues
show
Documentation Bug introduced by
It seems like $customer of type SilverStripe\Security\Member is incompatible with the declared type integer of property $MemberID.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
80
        $order->write();
81
    }
82
83
    /**
84
     *
85
     */
86
    public function testTestOrderHistoryControllerPermission()
87
    {
88
        $this->logOut();
89
        /** @var OrderHistory $page */
90
        $page = $this->objFromFixture(OrderHistory::class, 'one');
91
        $controller = OrderHistoryController::create($page);
92
        $ordersPage = $this->get($controller->Link());
93
94
        $this->assertContains('Please login to view this page.', $ordersPage->getBody());
95
96
        /** @var Member $customer */
97
        $customer = $this->objFromFixture(Member::class, 'customerone');
98
        $this->logInAs($customer);
99
100
        $newOrdersPage = $this->get($controller->Link());
101
        $this->assertNotContains('Please login to view this page.', $newOrdersPage->getBody());
102
    }
103
104
    /**
105
     *
106
     */
107
    public function testOrderPaginatedList()
108
    {
109
        $this->logOut();
110
        /** @var OrderHistory $page */
111
        $page = $this->objFromFixture(OrderHistory::class, 'one');
112
        $controller = OrderHistoryController::create($page);
113
114
        $this->assertInstanceOf(ArrayList::class, $controller->OrderPaginatedList());
115
116
        $customer = $this->objFromFixture(Member::class, 'customerone');
117
        $this->logInAs($customer);
118
119
        $newController = OrderHistoryController::create($page);
120
121
        $this->assertInstanceOf(PaginatedList::class, $newController->OrderPaginatedList());
122
    }
123
}
124