Completed
Push — master ( 64fdfa...f07eb7 )
by Aimeos
02:02
created

FosUserTest::testSetPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 */
7
8
9
namespace Aimeos\MShop\Customer\Item;
10
11
12
class FosUserTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $address;
15
	private $object;
16
17
18
	protected function setUp()
19
	{
20
		$addressValues = array(
21
			'customer.address.parentid' => 'referenceid',
22
			'customer.address.position' => 1,
23
		);
24
25
		$this->address = new \Aimeos\MShop\Common\Item\Address\Standard( 'common.address.', $addressValues );
26
27
		$values = array(
28
			'customer.id' => 541,
29
			'customer.siteid' => 123,
30
			'customer.label' => 'unitObject',
31
			'customer.code' => '12345ABCDEF',
32
			'customer.birthday' => '2010-01-01',
33
			'customer.status' => 1,
34
			'customer.password' => 'testpwd',
35
			'customer.vdate' => null,
36
			'customer.company' => 'unitCompany',
37
			'customer.vatid' => 'DE999999999',
38
			'customer.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR,
39
			'customer.title' => 'Dr.',
40
			'customer.firstname' => 'firstunit',
41
			'customer.lastname' => 'lastunit',
42
			'customer.address1' => 'unit str.',
43
			'customer.address2' => ' 166',
44
			'customer.address3' => '4.OG',
45
			'customer.postal' => '22769',
46
			'customer.city' => 'Hamburg',
47
			'customer.state' => 'Hamburg',
48
			'customer.countryid' => 'de',
49
			'customer.languageid' => 'de',
50
			'customer.telephone' => '05554433221',
51
			'customer.email' => '[email protected]',
52
			'customer.telefax' => '05554433222',
53
			'customer.website' => 'www.example.com',
54
			'customer.mtime'=> '2010-01-05 00:00:05',
55
			'customer.ctime'=> '2010-01-01 00:00:00',
56
			'customer.editor' => 'unitTestUser',
57
			'roles' => array( 'ROLE_ADMIN' ),
58
			'salt' => 'test',
59
		);
60
61
		$this->object = new \Aimeos\MShop\Customer\Item\FosUser( $this->address, $values );
62
	}
63
64
	protected function tearDown()
65
	{
66
		unset( $this->object );
67
	}
68
69
	public function testGetPassword()
70
	{
71
		$this->assertEquals( 'testpwd', $this->object->getPassword() );
72
	}
73
74
	public function testSetPassword()
75
	{
76
		$this->object->setPassword( 'new' );
77
		$this->assertTrue( $this->object->isModified() );
78
		$this->assertEquals( 'new', $this->object->getPassword() );
79
	}
80
81
	public function testSetPasswordGenerated()
82
	{
83
		$helper = new \Aimeos\MShop\Common\Item\Helper\Password\Standard( array( 'format' => '%1$s{%2$s}' ) );
84
		$object = new \Aimeos\MShop\Customer\Item\FosUser( $this->address, array(), array(), array(), $helper );
85
86
		$object->setPassword( 'newpwd' );
87
		$this->assertEquals( sha1( 'newpwd{' . $object->getSalt() . '}' ), $object->getPassword() );
88
	}
89
90
	public function testGetRoles()
91
	{
92
		$this->assertEquals( array( 'ROLE_ADMIN' ), $this->object->getRoles() );
93
	}
94
95
	public function testSetRoles()
96
	{
97
		$this->object->setRoles( array( 'ROLE_USER' ) );
98
		$this->assertTrue( $this->object->isModified() );
99
		$this->assertEquals( array( 'ROLE_USER' ), $this->object->getRoles() );
100
	}
101
102
	public function testGetSalt()
103
	{
104
		$this->assertEquals( 'test', $this->object->getSalt() );
105
	}
106
107
	public function testGetSaltGenerated()
108
	{
109
		$object = new \Aimeos\MShop\Customer\Item\FosUser( $this->address, array() );
110
		$this->assertInternalType( 'string', $object->getSalt() );
111
	}
112
113
	public function testSetSalt()
114
	{
115
		$this->object->setSalt( 'new' );
116
		$this->assertTrue( $this->object->isModified() );
117
		$this->assertEquals( 'new', $this->object->getSalt() );
118
	}
119
120
	public function testIsModified()
121
	{
122
		$this->assertFalse( $this->object->isModified() );
123
	}
124
}
125