Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Aug 9, 2024
1 parent 2196fc8 commit 8778746
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 0 additions & 2 deletions DataLayer/Tag/Cart/CartValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Yireo\GoogleTagManager2\DataLayer\Tag\Cart;

use Magento\Checkout\Model\Cart as CartModel;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Yireo\GoogleTagManager2\Api\Data\TagInterface;
use Yireo\GoogleTagManager2\Util\PriceFormatter;

Expand Down
8 changes: 6 additions & 2 deletions Test/Integration/DataLayer/Event/ViewCartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Yireo\GoogleTagManager2\Test\Integration\DataLayer\Event;

use Magento\Checkout\Model\Cart as CartModel;
use Magento\Framework\App\ObjectManager;
use Magento\Quote\Api\Data\CartInterface;
use PHPUnit\Framework\TestCase;
Expand All @@ -25,14 +26,15 @@ class ViewCartTest extends TestCase
*/
public function testValidViewCartEvent()
{
$this->markTestSkipped('Broken test');
$om = ObjectManager::getInstance();
$cart = $om->create(CartInterface::class);

$product = $this->createProduct(1);
$item = $cart->addProduct($product);
$item->setQty(2);
$cart->setItems([$item]);
$cart->setSubtotal(42.0);
$om->get(CartModel::class)->setQuote($cart);

$this->assertNotEmpty($cart->getItems());
$this->assertCount(1, $cart->getItems());
Expand All @@ -43,7 +45,9 @@ public function testValidViewCartEvent()
$data = $viewCartEvent->get();
$this->assertTrue($data['meta']['cacheable']);
$this->assertEquals('view_cart', $data['event']);
$this->assertNotEmpty($data['ecommerce']['items']);
$this->assertEquals('USD', $data['ecommerce']['currency']);
$this->assertNotEquals(0.0, $data['ecommerce']['value']);
$this->assertNotEmpty($data['ecommerce']['items'], 'No ecommerce items found');
$this->assertEquals(2, (int)$data['ecommerce']['items'][0]['quantity']);
}
}
5 changes: 5 additions & 0 deletions Test/Integration/Page/AddToWishlistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ class AddToWishlistTest extends PageTestCase

/**
* @magentoDbIsolation disabled
* @magentoAppIsolation disabled
* @magentoAppArea frontend
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @magentoConfigFixture current_store cataloginventory/options/show_out_of_stock 1
* @return void
* @throws LocalizedException
* @throws NoSuchEntityException
Expand All @@ -34,6 +36,8 @@ public function testAddToWishlist()

$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
$product = $productRepository->get('simple');
$product->setData('is_saleable', 1);
$productRepository->save($product);

$wishlist = $this->getWishlist();
$this->assertEquals(0, $wishlist->getItemsCount());
Expand All @@ -42,6 +46,7 @@ public function testAddToWishlist()
$request = $this->getRequest();

$request->setPostValue([
'wishlist_id' => $wishlist->getId(),
'product' => $product->getId(),
'formKey' => $this->objectManager->get(FormKey::class)->getFormKey(),
]);
Expand Down

0 comments on commit 8778746

Please sign in to comment.