Failed Conditions
Push — feature/customize-username-tes... ( 2b9ec8...faad56 )
by Kiyotaka
04:27
created

EA11CustomizeCest::test_username()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A EA11CustomizeCest::test_login_with_login_id() 0 13 1
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.ec-cube.co.jp/
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
use Codeception\Util\Fixtures;
14
use Doctrine\ORM\EntityManagerInterface;
15
use Eccube\Entity\Customer;
16
use Eccube\Entity\Master\CustomerStatus;
17
use Eccube\Entity\Master\Pref;
18
use Eccube\Repository\CustomerRepository;
19
use Eccube\Security\Core\Encoder\PasswordEncoder;
20
21
class EA11CustomizeCest
22
{
23
    /**
24
     * @group customize_username
25
     * @see https://github.com/EC-CUBE/ec-cube/pull/4687
26
     */
27
    public function test_login_with_login_id(\AcceptanceTester $I)
28
    {
29
        $loginId = 'customer1';
30
        $Customer = $this->newCustomer('[email protected]');
31
        $Customer->setLoginId($loginId);
0 ignored issues
show
Bug introduced by
The method setLoginId() does not seem to exist on object<Eccube\Entity\Customer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
33
        /** @var EntityManagerInterface $entityManager */
34
        $entityManager = Fixtures::get('entityManager');
35
        $entityManager->persist($Customer);
36
        $entityManager->flush();
37
38
        $I->loginAsMember($loginId, 'password');
39
    }
40
41
    /**
42
     * @group customize_username
43
     * @see https://github.com/EC-CUBE/ec-cube/pull/4687
44
     */
45
    public function test_login_fail_with_email(\AcceptanceTester $I)
46
    {
47
        $email = '[email protected]';
48
        $Customer = $this->newCustomer($email);
49
        $Customer->setLoginId('customer2');
0 ignored issues
show
Bug introduced by
The method setLoginId() does not seem to exist on object<Eccube\Entity\Customer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
51
        /** @var EntityManagerInterface $entityManager */
52
        $entityManager = Fixtures::get('entityManager');
53
        $entityManager->persist($Customer);
54
        $entityManager->flush();
55
56
        $I->amOnPage('/mypage/login');
57
        $I->submitForm('#login_mypage', [
58
            'login_email' => $email,
59
            'login_pass' => 'password',
60
        ]);
61
62
        $I->see('ログインできませんでした。', 'p.ec-errorMessage');
63
    }
64
65
    private function newCustomer($email)
66
    {
67
        $Customer = new Customer();
68
        /** @var EntityManagerInterface $entityManager */
69
        $entityManager = Fixtures::get('entityManager');
70
        /** @var CustomerStatus $Status */
71
        $Status = $entityManager->find(CustomerStatus::class, CustomerStatus::REGULAR);
72
        /** @var Pref $Pref */
73
        $Pref = $entityManager->find(Pref::class, 1);
74
        /** @var CustomerRepository $customerRepository */
75
        $customerRepository = $entityManager->getRepository(Customer::class);
76
77
        $getService = Fixtures::get('getService');
78
        $passwordEncoder = $getService(PasswordEncoder::class);
79
        $salt = $passwordEncoder->createSalt();
80
        $password = $passwordEncoder->encodePassword('password', $salt);
81
        $Customer
82
            ->setName01('test')
83
            ->setName02('test')
84
            ->setKana01('テスト')
85
            ->setKana02('テスト')
86
            ->setEmail($email)
87
            ->setPostalcode('5300001')
88
            ->setPref($Pref)
89
            ->setAddr01('addr01')
90
            ->setAddr02('addr02')
91
            ->setPhoneNumber('0123456789')
92
            ->setPassword($password)
93
            ->setSalt($salt)
94
            ->setSecretKey($customerRepository->getUniqueSecretKey())
95
            ->setStatus($Status)
96
            ->setCreateDate(new \DateTime())
97
            ->setUpdateDate(new \DateTime());
98
99
        return $Customer;
100
    }
101
}
102