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(); }
function test_delete() { $name = "Nike"; $test_brand = new Brand($name, $id); $test_brand->save(); $name2 = "Adidas"; $test_brand2 = new Brand($name2, $id); $test_brand2->save(); $test_brand->delete(); $this->assertEquals([$test_brand2], Brand::getAll()); }
function test_delete() { $test_name = "Helmut Lang"; $test_id = 1; $test_brand = new Brand($test_name, $test_id); $test_brand->save(); $test_name2 = "Y-3"; $test_id2 = 2; $test_brand2 = new Brand($test_name2, $test_id2); $test_brand2->save(); $test_brand->delete(); $result = Brand::getAll(); $this->assertEquals([$test_brand2], $result); }
function testDeleteBrand() { //Arrange $brand_name = "Sketchers"; $test_brand = new Brand($brand_name); $test_brand->save(); $another_brand = "Doc Martin"; $test_brand2 = new Brand($another_brand); $test_brand2->save(); //Act $test_brand->delete(); $result = Brand::getAll(); //Assert $this->assertEquals([$test_brand2], $result); }
function testDeleteJoins() { // Arrange $name = "Get Your Kicks Co."; $test_Store = new Store($name); $test_Store->save(); $name = "Babbling Brooks"; $test_Brand = new Brand($name); $test_Brand->save(); // Act $test_Brand->addStore($test_Store); $test_Brand->delete(); $result = $test_Store->getBrands(); // Assert $this->assertEquals([], $result); }
function testDelete() { //Arrange $brand_name = "Nike"; $id = 1; $test_brand = new Brand($brand_name, $id); $test_brand->save(); $brand_name2 = "Reebok"; $id2 = 2; $test_brand2 = new Brand($brand_name2, $id2); $test_brand2->save(); //Act $test_brand->delete(); //Assert $this->assertEquals([$test_brand2], Brand::getAll()); }
function test_delete() { //Arrange $name = "Nike"; $website = "http://www.nike.com"; $test_brand = new Brand($name, $website); $test_brand->save(); $name2 = "Adidas"; $website2 = "http://www.adidas.com"; $test_brand2 = new Brand($name2, $website2); $test_brand2->save(); //Act $test_brand->delete(); //Assert $result = Brand::getAll(); $this->assertEquals([$test_brand2], $result); }
public function deleteBrand() { $id = null; if (!empty($_GET['id'])) { $id = (int) $_GET['id']; } $brand = new Brand(); $brand->withId($id); if ($brand->hasId()) { $brand->delete(); } header('Location: ' . $this->getUrl('brands')); exit; }
function test_find() { //Arrange $name = "Nike"; $test_brand = new Brand($name); $test_brand->save(); $name2 = "Adidas"; $test_brand2 = new Brand($name2); $test_brand2->save(); //Act $test_brand->delete(); $result = Brand::find($test_brand2->getId()); //Assert $this->assertEquals($test_brand2, $result); }
$brand->nameBrand = "Citroen"; $brand->noteBrand = 10; $brand->save(); $brand2 = new Brand(); $brand2->nameBrand = "Renault"; $brand2->noteBrand = 10; $brand2->save(); $brand3 = new Brand(); $brand3->nameBrand = "Peugeot"; $brand3->noteBrand = 15; $brand3->save(); // update existing brand $brand->nameBrand = "Audi"; $brand->save(); // delete brand $brand->delete(); // select all brand $result = Brand::find(); // select one brand $result = Brand::findOne(array('idBrand' => 1)); // select one brand with order by $result = Brand::findOne(array('noteBrand' => 10), array('nameBrand' => 'ASC')); // Criteria with exact value (noteBrand=10) $collection = Brand::find(array('noteBrand' => 10)); // Criteria with custom operator (noteBrand >= 10) $collection = Brand::find(array('noteBrand' => array('operator' => '>=', 'value' => 10))); // Criteria with Raw SQL $collection = Brand::find(array('noteBrand' => array('IN(9,10,11)'))); // Criteria with custom operator (noteBrand >= 10) // order by field $collection = Brand::find(array('noteBrand' => array('operator' => '>=', 'value' => 10)), array('noteBrand' => 'ASC'));
if (isset($_SESSION['app']) && isset($_COOKIE['app'])) { $brand->updateImage(); } else { echo "<script>window.location='../../'</script>"; } }); // GET $app->get('/brands', function () use($brand) { $brand->getBrands(); }); $app->get('/brands/:id', function ($id) use($brand) { $brand->getBrand($id); }); $app->delete('/brands/:id', function ($id) use($brand) { if (isset($_SESSION['app']) && isset($_COOKIE['app'])) { $brand->delete($id); } else { echo "<script>window.location='../../'</script>"; } }); // $app->post('/brands', function() use($brand, $app) { // $request = $app->request(); // $body = $request->getBody(); // $data = json_decode($body); // $brand->insert($data); // }); $app->put('/brands/:id', function ($id) use($brand, $app) { if (isset($_SESSION['app']) && isset($_COOKIE['app'])) { $request = $app->request(); $body = $request->getBody(); $data = json_decode($body);
function test_delete() { //Arrange $name = "Nike"; $id = null; $test_brand = new Brand($name, $id); $test_brand->save(); $name2 = "Adidas"; $test_brand2 = new Brand($name2, $id); $test_brand2->save(); //Act $test_brand->delete(); $result = Brand::getAll(); //Assert $this->assertEquals($test_brand2, $result[0]); }