Example #1
0
 function test_getName()
 {
     $test_name = "Helmut Lang";
     $test_id = 1;
     $test_brand = new Brand($test_name, $test_id);
     $result = $test_brand->getName();
     $this->assertEquals($test_name, $result);
 }
Example #2
0
 function test_setName()
 {
     $name = "Nike";
     $test_brand = new Brand($name, $id);
     $test_brand->setName("Foot Action");
     $result = $test_brand->getName();
     $this->assertEquals("Foot Action", $result);
 }
Example #3
0
 function testUpdate()
 {
     $name = "Foot and feet";
     $test_brand = new Brand($name);
     $test_brand->save();
     $new_name = "Foot peddler";
     $test_brand->updateName($new_name);
     $this->assertEquals($new_name, $test_brand->getName());
 }
Example #4
0
 function testGetName()
 {
     //Arrange
     $brand_name = "La Sportiva";
     $test_brand = new Brand($brand_name);
     //Act
     $result = $test_brand->getName();
     //Assert
     $this->assertEquals($brand_name, $result);
 }
Example #5
0
 function test_getName()
 {
     //Arrange
     $name = "Nike";
     $test_brand = new Brand($name);
     //Act
     $result = $test_brand->getName();
     //Assert
     $this->assertEquals($name, $result);
 }
Example #6
0
 function test_getName()
 {
     //Arrange
     $name = "Nike";
     $website = "http://www.nike.com";
     $test_brand = new Brand($name, $website);
     //Act
     $result = $test_brand->getName();
     //Assert
     $this->assertEquals($name, $result);
 }
Example #7
0
 function testSetName()
 {
     //Arrange
     $name = "addidas";
     $test_brand = new Brand($name);
     $new_name = "nike";
     //Act
     $test_brand->setName($new_name);
     $result = $test_brand->getName();
     //Assert
     $this->assertEquals($new_name, $result);
 }
Example #8
0
 function test_setName()
 {
     //Arrange
     $name = "Running";
     $id = 1;
     $test_brand = new Brand($name, $id);
     //Act
     $test_brand->setName("work");
     $result = $test_brand->getName();
     //Assert
     $this->assertEquals($result, "work");
 }
 function testUpdate()
 {
     // Arrange
     $brand_name = "Babbling Brooks";
     $test_Brand = new Brand($brand_name);
     $test_Brand->save();
     $new_name = "Gibberish Producing Brooks";
     // Act
     $test_Brand->update($new_name);
     $result = $test_Brand->getName();
     // Assert
     $this->assertEquals($new_name, $result);
 }
Example #10
0
 function test_update()
 {
     //Arrange
     $name = "Nike";
     $id = null;
     $test_brand = new Brand($name, $id);
     $test_brand->save();
     $new_name = "Adidas";
     //Act
     $test_brand->update($new_name);
     //Assert
     $this->assertEquals($new_name, $test_brand->getName());
 }
Example #11
0
 public function update(Brand $brand, $errors = array())
 {
     $id = $brand->getId();
     $name = $this->db->quote($brand->getName());
     $description = $this->db->quote($brand->getDescription());
     $query = "UPDATE brand SET name = " . $name . ", description = " . $description . "WHERE id = " . $id;
     $data = $this->db->exec($query);
     if ($data) {
         $id = $this->db->lastInsertId();
         if ($id) {
             try {
                 $brand = $this->findByid($id);
                 return $brand;
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
                 return $errors;
             }
         } else {
             throw new Exception('Last insert error');
         }
     } else {
         throw new Exception('Update error');
     }
 }
 /**
  * @param $name
  * @param $description
  * @param array $errors
  * @return object
  * @throws Exception
  */
 public function create($name, $description, $errors = array())
 {
     $category = new Brand($this->db);
     try {
         $category->setName($name);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $category->setDescription($description);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if (count($errors) == 0) {
         $name = $this->db->quote($category->getName());
         $description = $this->db->quote($category->getDescription());
         $query = "INSERT INTO category (name, description) VALUES(" . $name . ", " . $description . ")";
         $data = $this->db->exec($query);
         if ($data) {
             $id = $this->db->lastInsertId();
             if ($id) {
                 try {
                     $category = $this->findById($id);
                     return $category;
                 } catch (Exception $e) {
                     $errors[] = $e->getMessage();
                     return $errors;
                 }
             } else {
                 throw new Exception('Last insert error');
             }
         } else {
             throw new Exception('Insert error');
         }
     } else {
         return $errors;
     }
 }