-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRegistByFileTest.php
More file actions
121 lines (104 loc) · 3.09 KB
/
RegistByFileTest.php
File metadata and controls
121 lines (104 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* UploadFile::registByFile()のテスト
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('NetCommonsModelTestCase', 'NetCommons.TestSuite');
App::uses('UploadFileFixture', 'Files.Test/Fixture');
App::uses('TemporaryUploadFileTesting', 'Files.Test/Testing');
/**
* UploadFile::registByFile()のテスト
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @package NetCommons\Files\Test\Case\Model\UploadFile
*/
class UploadFileRegistByFileTest extends NetCommonsModelTestCase {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.files.upload_file',
'plugin.files.upload_files_content',
'plugin.site_manager.site_setting',
);
/**
* Plugin name
*
* @var string
*/
public $plugin = 'files';
/**
* Model name
*
* @var string
*/
protected $_modelName = 'UploadFile';
/**
* Method name
*
* @var string
*/
protected $_methodName = 'registByFile';
/**
* testRegistByFile method
*
* @return void
*/
public function testRegistByFile() {
copy(dirname(dirname(dirname(__DIR__))) . DS . 'Fixture' . DS . 'logo.gif', TMP . 'logo.gif');
$file = new File(TMP . 'logo.gif');
$pluginKey = 'files';
$contentKey = 'content_key_1';
$fieldName = 'image';
$data = $this->UploadFile->registByFile($file, $pluginKey, $contentKey, $fieldName);
$this->assertTrue($data['UploadFile']['id'] > 0);
$this->UploadFile->delete($this->UploadFile->id);
}
/**
* testRegistByFileFailed method
*
* @return void
*/
public function testRegistByFileFailed() {
copy(dirname(dirname(dirname(__DIR__))) . DS . 'Fixture' . DS . 'logo.gif', TMP . 'logo.gif');
$file = new File(TMP . 'logo.gif');
$pluginKey = 'files';
$contentKey = 'content_key_1';
$fieldName = 'image';
$this->setExpectedException('InternalErrorException');
$this->_mockForReturnFalse('UploadFile', 'Files.UploadFile', 'save');
$this->UploadFile->registByFile($file, $pluginKey, $contentKey, $fieldName);
}
/**
* test RegistByFile TemporaryUploadFileを渡したときは元ファイル名で保存されることのテスト
*
* @return void
*/
public function testRegistByFileWithTemporaryUploadFile() {
copy(dirname(dirname(dirname(__DIR__))) . DS . 'Fixture' . DS . 'logo.gif', TMP . 'logo.gif');
$fileInfo = [
'name' => 'logo.gif',
'type' => 'image/gif',
'size' => 100,
'tmp_name' => TMP . 'logo.gif',
'error' => UPLOAD_ERR_OK,
];
$file = new TemporaryUploadFileTesting($fileInfo);
//$file = new File(TMP . 'logo.gif');
$pluginKey = 'files';
$contentKey = 'content_key_1';
$fieldName = 'image';
$data = $this->UploadFile->registByFile($file, $pluginKey, $contentKey, $fieldName);
$this->assertTrue($data['UploadFile']['id'] > 0);
// 元ファイル名がoriginal_nameに保存されてること
$uploadFile = $this->UploadFile->findById($data['UploadFile']['id']);
$this->assertEquals('logo.gif', $uploadFile['UploadFile']['original_name']);
$this->UploadFile->delete($this->UploadFile->id);
}
}