Skip to content

Commit

Permalink
Rewrite all fixtures from manual back to core
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Dec 16, 2024
1 parent 002e385 commit a84bf22
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 287 deletions.
11 changes: 6 additions & 5 deletions Test/Integration/DataLayer/Event/AddToCartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
use Magento\Framework\App\ObjectManager;
use PHPUnit\Framework\TestCase;
use Yireo\GoogleTagManager2\DataLayer\Event\AddToCart;
use Yireo\GoogleTagManager2\Test\Integration\FixtureTrait\CreateProduct;
use Yireo\GoogleTagManager2\Test\Integration\FixtureTrait\GetProduct;

/**
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoDbIsolation disabled
*/
class AddToCartTest extends TestCase
{
use CreateProduct;
use GetProduct;

/**
* @magentoConfigFixture current_store googletagmanager2/settings/enabled 1
* @magentoConfigFixture current_store googletagmanager2/settings/method 1
* @magentoConfigFixture current_store googletagmanager2/settings/id test
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Catalog/_files/category_with_three_products.php
*/
public function testValidDataLayerWithCart()
{
/** @var Product $product */
$product = $this->getProduct(1);
$product = $this->getProductBySku('simple1002');
$addToCartEvent = ObjectManager::getInstance()->get(AddToCart::class);
$data = $addToCartEvent->setProduct($product)->get();
$this->assertCount(1, $data['ecommerce']['items']);
Expand Down
3 changes: 0 additions & 3 deletions Test/Integration/DataLayer/Event/PurchaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
use Magento\Sales\Api\OrderRepositoryInterface;
use PHPUnit\Framework\TestCase;
use Yireo\GoogleTagManager2\DataLayer\Event\Purchase;
use Yireo\GoogleTagManager2\Test\Integration\FixtureTrait\CreateProduct;

/**
* @magentoAppArea frontend
*/
class PurchaseTest extends TestCase
{
use CreateProduct;

/**
* @magentoConfigFixture current_store googletagmanager2/settings/enabled 1
* @magentoConfigFixture current_store googletagmanager2/settings/method 1
Expand Down
24 changes: 11 additions & 13 deletions Test/Integration/DataLayer/Event/ViewCartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,36 @@

use Magento\Checkout\Model\Cart as CartModel;
use Magento\Checkout\Model\Session;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\ObjectManager;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\CartInterface;
use PHPUnit\Framework\TestCase;
use Yireo\GoogleTagManager2\DataLayer\Event\ViewCart;
use Yireo\GoogleTagManager2\DataLayer\Tag\Cart\CartItems;
use Yireo\GoogleTagManager2\Test\Integration\FixtureTrait\CreateProduct;

/**
* @magentoAppArea frontend
*/
class ViewCartTest extends TestCase
{
use CreateProduct;

/**
* @magentoConfigFixture current_store googletagmanager2/settings/enabled 1
* @magentoConfigFixture current_store googletagmanager2/settings/method 1
* @magentoConfigFixture current_store googletagmanager2/settings/id test
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_products.php
*/
public function testValidViewCartEvent()
{
$om = ObjectManager::getInstance();
$cart = $om->create(CartInterface::class);

$product = $this->getProduct(1);
$cart->addProduct($product, 2);
$cart->collectTotals();
$cart->save();
$cartId = $cart->getId();
$quoteRepository = ObjectManager::getInstance()->get(CartRepositoryInterface::class);
$searchCriteriaBuilder = ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
$searchCriteriaBuilder->addFilter('reserved_order_id', 'test_quote_with_simple_products');
$searchCriteriaBuilder->setPageSize(1);
$searchResults = $quoteRepository->getList($searchCriteriaBuilder->create());
$quote = $searchResults->getItems()[0];
$cartId = $quote->getId();

$checkoutSession = ObjectManager::getInstance()->get(Session::class);
$checkoutSession->setQuoteId($cartId);
Expand All @@ -45,7 +43,7 @@ public function testValidViewCartEvent()
$cartRepository = ObjectManager::getInstance()->get(CartRepositoryInterface::class);
$cart = $cartRepository->get($cartId);
$this->assertNotEmpty($cart->getItems());
$this->assertCount(1, $cart->getItems());
$this->assertCount(2, $cart->getItems());

$cartItems = $om->create(CartItems::class, ['cart' => $cart]);
$viewCartEvent = $om->create(ViewCart::class, ['cartItems' => $cartItems]);
Expand All @@ -57,6 +55,6 @@ public function testValidViewCartEvent()
$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']);
$this->assertEquals(1, (int)$data['ecommerce']['items'][0]['quantity']);
}
}
16 changes: 12 additions & 4 deletions Test/Integration/DataLayer/Mapper/CategoryDataMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@
use Magento\Framework\App\ObjectManager;
use PHPUnit\Framework\TestCase;
use Yireo\GoogleTagManager2\DataLayer\Mapper\CategoryDataMapper;
use Yireo\GoogleTagManager2\Test\Integration\FixtureTrait\CreateCategory;
use Yireo\GoogleTagManager2\Test\Integration\FixtureTrait\GetCategory;

/**
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoDbIsolation disabled
*/
class CategoryDataMapperTest extends TestCase
{
use CreateCategory;
use GetCategory;

/**
* @magentoDataFixture Magento/Catalog/_files/category_with_three_products.php
*/
public function testMapByCategory()
{
$category = $this->createCategory(3);
$category = $this->getCategoryByName('Category 999');
$categoryDataMapper = ObjectManager::getInstance()->get(CategoryDataMapper::class);
$categoryData = $categoryDataMapper->mapByCategory($category);
$this->assertEquals('Category ' . $category->getId(), $categoryData['category_name']);
$this->assertEquals('Category 999', $categoryData['category_name']);
$this->assertEquals($category->getId(), $categoryData['category_id']);
}
}
14 changes: 11 additions & 3 deletions Test/Integration/DataLayer/Mapper/ProductDataMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
use Magento\Framework\App\ObjectManager;
use PHPUnit\Framework\TestCase;
use Yireo\GoogleTagManager2\DataLayer\Mapper\ProductDataMapper;
use Yireo\GoogleTagManager2\Test\Integration\FixtureTrait\CreateProduct;
use Yireo\GoogleTagManager2\Test\Integration\FixtureTrait\GetProduct;

/**
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoDbIsolation disabled
*/
class ProductDataMapperTest extends TestCase
{
use CreateProduct;
use GetProduct;

/**
* @magentoDataFixture Magento/Catalog/_files/category_with_three_products.php
*/
public function testMapByProduct()
{
$product = $this->getProducts()[0];
$product = $this->getProductBySku('simple1002');
$productDataMapper = ObjectManager::getInstance()->get(ProductDataMapper::class);
$productData = $productDataMapper->mapByProduct($product);
$this->assertArrayHasKey('item_name', $productData);
Expand Down
59 changes: 0 additions & 59 deletions Test/Integration/FixtureTrait/CreateCategory.php

This file was deleted.

Loading

0 comments on commit a84bf22

Please sign in to comment.