/** * @dataProvider pathDataProvider * @param array $data Set of data for the test * @param array $expected Expected set of results */ public function testConstructedFullPath($data, $expected) { $table = $this->getMockBuilder('Cake\\ORM\\Table')->setMethods(['alias'])->getMock(); $table->method('alias')->willReturn('ProfferTest'); $entity = new Entity($data['entity']); $path = new ProfferPath($table, $entity, $data['field'], $data['settings'][$data['field']]); $i = 1; foreach ($data['settings'][$data['field']]['thumbnailSizes'] as $prefix => $dimensions) { $this->assertEquals($expected[$i], $path->fullPath($prefix)); $i++; } $this->assertEquals($expected[0], $path->fullPath()); }
/** * Load a table, get it's config and then regenerate the thumbnails for that tables upload fields. * * @param string $table The name of the table * @return void */ public function generate($table) { $this->checkTable($table); $config = $this->Table->behaviors()->Proffer->config(); foreach ($config as $field => $settings) { $records = $this->{$this->Table->alias()}->find()->select([$this->Table->primaryKey(), $field, $settings['dir']])->where(["{$field} IS NOT NULL", "{$field} != ''"]); foreach ($records as $item) { if ($this->param('verbose')) { $this->out(__('Processing ' . $this->Table->alias() . ' ' . $item->get($this->Table->primaryKey()))); } if (!empty($this->param('path-class'))) { $class = (string) $this->param('path-class'); $path = new $class($this->Table, $item, $field, $settings); } else { $path = new ProfferPath($this->Table, $item, $field, $settings); } if (!empty($this->param('image-class'))) { $class = (string) $this->param('image_class'); $transform = new $class($this->Table, $path); } else { $transform = new ImageTransform($this->Table, $path); } $transform->processThumbnails($settings); if ($this->param('verbose')) { $this->out(__('Thumbnails regenerated for ' . $path->fullPath())); } else { $this->out(__('Thumbnails regenerated for ' . $this->Table->alias() . ' ' . $item->get($field))); } } } $this->out($this->nl(0)); $this->out(__('<info>Completed</info>')); }