GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 951ad1...29ba67 )
by Alexey
08:55
created

ImageWriterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 160
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 31 1
B testWriteNewData() 0 44 1
A testRenameFile() 0 52 1
A tearDown() 0 7 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 8.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @author Alexey Tatarinov <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2016 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 */
8
Yii::import('backend.modules.product.modules.import.tests.components.*');
9
Yii::import('backend.modules.product.modules.import.components.*');
10
11
class ImageWriterTest extends CDbTestCase
12
{
13
  protected $fixtures = array(
14
    'product' => 'BProduct',
15
    'product_img' => 'BProductImg',
16
  );
17
18
  private $basePath;
19
20
  private $testSourceDir;
21
22
  private $testOutDir;
23
24
  /**
25
   * @var ImageWriter
26
   */
27
  protected $imageWriter;
28
29
  public function setUp()
30
  {
31
    $imageWriter = new ImageWriter(new DummyConsoleFileLogger('test'), 'f/product/testSrc', 'f/product/testOutput');
32
    $imageWriter->previews = array(
33
      'origin' => array(4500, 4500),
34
      'big' => array(600, 460),
35
      'pre' => array(250, 190),
36
    );
37
38
    $imageWriter->uniqueAttribute = 'id';
39
    $imageWriter->clear = false;
40
    $imageWriter->clearTables = array('{{product_img}}');
41
    $imageWriter->defaultJpegQuality = 95;
42
    $imageWriter->phpThumbErrorExceptionToWarning = true;
43
44
    $this->imageWriter = $imageWriter;
45
46
    $currentDir = dirname(__FILE__);
47
48
    $this->basePath = GlobalConfig::instance()->rootPath;
49
    $this->testSourceDir = $this->basePath.'/f/product/testSrc';
50
    $this->testOutDir = $this->basePath.'/f/product/testOutput';
51
52
    CFileHelper::createDirectory($this->testSourceDir);
53
    CFileHelper::createDirectory($this->testOutDir);
54
    CFileHelper::copyDirectory($currentDir.'/files', $this->testSourceDir);
55
56
    $this->getFixtureManager()->basePath = $currentDir.'/fixtures/';
57
58
    parent::setUp();
59
  }
60
61
  public function testWriteNewData()
62
  {
63
    $data = array(
64
      1 => array(
65
        array(
66
          'file' => 'test_file01.jpg',
67
          'rowIndex' => '1'
68
        ),
69
        array(
70
          'file' => 'test_file02.jpg',
71
          'rowIndex' => '1'
72
        )
73
      ),
74
      2 => array(
75
        array(
76
          'file' => 'test_file03.jpg',
77
          'rowIndex' => '2'
78
        )
79
      )
80
    );
81
82
    $this->imageWriter->actionWithExistingRecord = ImageWriter::DB_ACTION_EXISTING_RECORD_SKIP_WITH_WARNING;
83
    $this->imageWriter->actionWithSameFiles = ImageWriter::FILE_ACTION_RENAME_NEW_FILE;
84
    $this->imageWriter->writeAll($data);
85
86
    $this->assertTrue(empty($this->imageWriter->logger->testLog['error']));
87
    $this->assertTrue(empty($this->imageWriter->logger->testLog['warning']));
88
89
    $this->assertNotNull(BProductImg::model()->findByAttributes(array('parent' => 1, 'name' => 'test_file01.jpg', 'type' => 'main')));
90
    $this->assertNotNull(BProductImg::model()->findByAttributes(array('parent' => 1, 'name' => 'test_file02.jpg', 'type' => 'gallery')));
91
    $this->assertNotNull(BProductImg::model()->findByAttributes(array('parent' => 2, 'name' => 'test_file03.jpg', 'type' => 'main')));
92
93
    $this->assertTrue(file_exists($this->testOutDir.'/test_file01.jpg'));
94
    $this->assertTrue(file_exists($this->testOutDir.'/pre_test_file01.jpg'));
95
    $this->assertTrue(file_exists($this->testOutDir.'/big_test_file01.jpg'));
96
97
    $this->assertTrue(file_exists($this->testOutDir.'/test_file02.jpg'));
98
    $this->assertTrue(file_exists($this->testOutDir.'/pre_test_file02.jpg'));
99
    $this->assertTrue(file_exists($this->testOutDir.'/big_test_file02.jpg'));
100
101
    $this->assertTrue(file_exists($this->testOutDir.'/test_file03.jpg'));
102
    $this->assertTrue(file_exists($this->testOutDir.'/pre_test_file03.jpg'));
103
    $this->assertTrue(file_exists($this->testOutDir.'/big_test_file03.jpg'));
104
  }
105
106
  public function testRenameFile()
107
  {
108
    $data = array(
109
      1 => array(
110
        array(
111
          'file' => 'test_file01.jpg',
112
          'rowIndex' => '1'
113
        ),
114
        array(
115
          'file' => 'test_file02.jpg',
116
          'rowIndex' => '1'
117
        )
118
      ),
119
      2 => array(
120
        array(
121
          'file' => 'test_file01.jpg',
122
          'rowIndex' => '2'
123
        )
124
      )
125
    );
126
127
    $this->imageWriter->actionWithExistingRecord = ImageWriter::DB_ACTION_EXISTING_RECORD_SKIP_SILENT;
128
    $this->imageWriter->actionWithSameFiles = ImageWriter::FILE_ACTION_RENAME_NEW_FILE;
129
130
    $this->assertNull(BProductImg::model()->findByAttributes(array('parent' => 2)));
131
132
    $this->imageWriter->writeAll($data);
133
134
    $this->assertTrue(empty($this->imageWriter->logger->testLog['error']));
135
    $this->assertTrue(empty($this->imageWriter->logger->testLog['warning']));
136
137
    $this->assertTrue(file_exists($this->testOutDir.'/test_file01.jpg'));
138
    $this->assertTrue(file_exists($this->testOutDir.'/pre_test_file01.jpg'));
139
    $this->assertTrue(file_exists($this->testOutDir.'/big_test_file01.jpg'));
140
141
    $this->assertTrue(file_exists($this->testOutDir.'/test_file02.jpg'));
142
    $this->assertTrue(file_exists($this->testOutDir.'/pre_test_file02.jpg'));
143
    $this->assertTrue(file_exists($this->testOutDir.'/big_test_file02.jpg'));
144
145
    $this->assertNotNull(BProductImg::model()->findByAttributes(array('parent' => 1, 'name' => 'test_file01.jpg', 'type' => 'main')));
146
    $this->assertNotNull(BProductImg::model()->findByAttributes(array('parent' => 1, 'name' => 'test_file02.jpg', 'type' => 'gallery')));
147
148
    $record = BProductImg::model()->findByAttributes(array('parent' => 2));
149
150
    $this->assertNotNull($record);
151
152
    $fileName = $record['name'];
153
154
    $this->assertTrue(file_exists($this->testOutDir.'/'.$fileName));
155
    $this->assertTrue(file_exists($this->testOutDir.'/pre_'.$fileName));
156
    $this->assertTrue(file_exists($this->testOutDir.'/big_'.$fileName));
157
  }
158
159
  /*  public function testUpdateDbRecord()
160
  {
161
  }*/
162
163
  public function tearDown()
164
  {
165
    CFileHelper::removeDirectory($this->testSourceDir);
166
    CFileHelper::removeDirectory($this->testOutDir);
167
168
    parent::tearDown();
169
  }
170
}