/** @test */
 public function product_management()
 {
     // Acessa a funcionalidade produtos e retorna a representação do DOM da página
     $crawler = $this->client->request('GET', 'product');
     // Verifica se existe uma variável chamada 'products'
     $this->assertViewHas('products');
     // Verifica se a lista de produtos contém produtos ao checar a existência dos botões de gerenciamento
     $link_editar = $crawler->filter('a.link-editar');
     $link_remover = $crawler->filter('a.link-remover');
     $this->assertGreaterThan(0, count($link_editar), 'Nenhum botao editar encontrado!');
     $this->assertGreaterThan(0, count($link_remover), 'Nenhum botao remover encontrado!');
     // Se a lista está preenchida
     if (count($link_editar) > 0) {
         // Pega o link do primeiro botão editar
         $url_editar = $link_editar->first()->attr('href');
         // Acessa a funcionalidade product/edit/{id} e retorna a representação do DOM da página
         $crawler = $this->client->request('GET', $url_editar);
         // Verifica se o status retornado é 200
         $this->assertResponseOk();
         // Pega o ID do produto ao ler o valor do hidden field do form
         $product_id = $crawler->filter('input[name=id]')->attr('value');
         // Cria nova instancia do repositório de produtos
         $productRepo = new ProductRepository();
         // Atualiza o produto
         $update_result = $productRepo->updateProduct(array('id' => $product_id, 'name' => 'Product Name', 'description' => 'Product Description', 'price' => '2.456,89', 'free_shipping' => 1));
         // Certifica-se de que a atualização foi feita com sucesso
         $this->assertTrue($update_result);
     }
     // Se a lista está preenchida
     if (count($link_remover) > 0) {
         // Pega o link do primeiro botão remover
         $url_remover = $link_remover->first()->attr('href');
         // Acessa o link
         $this->call('GET', $url_remover);
         // Verifica se é redirecionado para a lista de produtos
         $this->assertRedirectedTo('product');
     }
 }
Esempio n. 2
0
		public function testProductCountUpdatesOnProductUpdate()
		{
			$module_srl = 1001;

			$product_repository = new ProductRepository();

			$product = new SimpleProduct();
			$product->product_srl = 12;
			$product->title = "Some product";
			$product->member_srl = 4;
			$product->module_srl = $module_srl;
			$product->product_type = 'simple';
			$product->sku = 'some-product';
			$product->friendly_url = $product->sku;
			$product->price = 100;
			$product->categories[] = 1000;
			$product->categories[] = 1002;
			$product_repository->insertProduct($product);

			// Check that count was increased
			$category_repository = new CategoryRepository();
			$category = $category_repository->getCategory(1000);
			$this->assertEquals(1, $category->product_count);
			// Check that count was increased
			$category = $category_repository->getCategory(1002);
			$this->assertEquals(1, $category->product_count);
			// Check that count was increased
			$category = $category_repository->getCategory(1008);
			$this->isNull($category->product_count);

			// Delete product
			$args = new stdClass();
			$args->module_srl = $module_srl;
			$products = $product_repository->getAllProducts($args);
			$this->assertNotNull($products);

			$product = array_shift($products);
			$product->categories = array(1002, 1008);
			$product_repository->updateProduct($product);

			// Check that count was decreased
			$category_repository = new CategoryRepository();
			$category = $category_repository->getCategory(1000);
			$this->assertEquals(0, $category->product_count);
			// Check that count was decreased
			$category = $category_repository->getCategory(1002);
			$this->assertEquals(1, $category->product_count);
			// Check that count was increased
			$category = $category_repository->getCategory(1008);
			$this->assertEquals(1, $category->product_count);
		}
Esempio n. 3
0
 /**
  * substract from stock when a product is bought
  * @param $qty
  * @throws ShopException
  */
 public function substractFromStock($qty)
 {
     if ($qty > $this->qty) {
         throw new ShopException("You do not have enough items in stock to ship this order. Go and update stocks for product {$this->product_srl} !");
     }
     $this->qty -= $qty;
     $this->repo->updateProduct($this);
 }
Esempio n. 4
0
	/**
	 * Test inserting product attributes
	 *
	 * Each category has associated a set of attributes
	 * (e.g. All books have the Author attribute, All T-Shirts have Color)
	 * Based on the category a product is in, it can have values for these attributes.
	 *
	 * This test checks that if Color is provided for a product in the Books
	 * category it will not be added.
	 *
	 *
	 * @author Corina Udrescu (dev@xpressengine.org)
	 */
	public function testInsertProductAttributeSkipsAttributesNotInScope()
	{
		$repository = new ProductRepository();
		$product = $repository->getProduct(1);

		$product->attributes[self::ATTRIBUTE_AUTHOR] = "J. K. Rowling";
		$product->attributes[self::ATTRIBUTE_PUBLISH_YEAR] = 2003;
		$product->attributes[self::ATTRIBUTE_COLOR] = "Blue";

		$repository->updateProduct($product);

		$new_product = $repository->getProduct(1);

		$this->assertEquals(2, count($new_product->attributes));

		$this->assertFalse(array_key_exists(self::ATTRIBUTE_COLOR, $new_product->attributes));
		$this->assertEquals("J. K. Rowling", $new_product->attributes[self::ATTRIBUTE_AUTHOR]);
		$this->assertEquals(2003, $new_product->attributes[self::ATTRIBUTE_PUBLISH_YEAR]);
	}