public function testBasic() { $brand = new \Brand(array('title' => 'Apple')); $brand->save(); $brand = \Brand::loadOne(1); $brand->attachFileFromPath('logo', __DIR__ . '/../README.md'); $this->assertEquals('01/1/logo/README.md', $brand->logo[0]['link'], 'original file name'); $brand->attachFileFromPath('logo', __DIR__ . '/../README.md'); $this->assertEquals('01/1/logo/README_1.md', $brand->logo[1]['link'], 'duplicate of original file name'); $brand = \Brand::loadOne(1); $this->assertEquals(2, count($brand->logo), 'loaded two files on demand'); $brand->delete(); $this->assertEmpty(FSService::getInstance()->in(__DIR__ . '/upload/01/')->find(), 'No files left after deleting'); $brand = new \Brand(array('title' => 'Apple')); $_FILES['logo'] = array('tmp_name' => __DIR__ . '/../README.md', 'name' => 'readme.md'); $_FILES['info_file'] = array('tmp_name' => __DIR__ . '/../README.md', 'name' => 'readme.md'); $brand->setFieldNameForAlias('info', 'info_file'); $brand->save(); $this->assertEquals(2, count(FSService::getInstance()->in(__DIR__ . '/upload/02/2')->find()), 'Two files saved to object'); $brand->delete(); $brand = new \Brand(array('title' => 'Apple')); $_FILES['logo'] = array('tmp_name' => __DIR__ . '/../README.md', 'name' => 'readme.md'); $_FILES['info'] = array('tmp_name' => __DIR__ . '/../README.md', 'name' => 'readme.md'); $brand->skipFileAliasForSave('logo'); $brand->save(); $this->assertEquals(1, count(FSService::getInstance()->in(__DIR__ . '/upload/03/3')->find()), 'Skipped logo'); $brand->delete(); }
/** * Loading structure from YAML files * First loading "structure.yml" if it exists * * @param mixed $path Path where yaml are stored * @return $this */ public function loadStructureFiles($path = null) { if (empty($path)) { $path = $this->_structuresPath; } $files = FSService::getInstance()->in($path, true)->find('*.yml', FSService::TYPE_FILE, FSService::HYDRATE_NAMES_PATH); $data = array(); //if (isset($files['structure.yml'])) { // $data = Yaml::parse(file_get_contents($files['structure.yml'])); // if (is_null($data)) $data = array(); // unset($files['structure.yml']); //} foreach ($files as $file) { $modelData = Yaml::parse(file_get_contents($file)); $modelName = !empty($modelData['model']) ? $modelData['model'] : substr($file, strrpos($file, '/') + 1, -4); $modelNamespace = "Entities"; $data = array_merge($data, array($modelNamespace . "\\" . ucfirst($modelName) => $modelData)); } $data = self::fixYamlStructures($data); $this->_structures = $data; return $this; }