Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
supercid committed Feb 26, 2025
1 parent 5abb05c commit d5ee5ef
Show file tree
Hide file tree
Showing 18 changed files with 1,305 additions and 371 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Tests

on: [push]

jobs:
php-unit-tests:
name: PHP Unit Tests
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [7.4]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: json, mbstring, xml, zip
coverage: pcov
tools: composer:v2, phpunit:9.5

- name: Update project dependencies
env:
REPO_USR: ${{ secrets.REPO_USR }}
REPO_PSW: ${{ secrets.REPO_PSW }}
run: |
composer config repositories.0 composer https://repo.magento.com
composer config http-basic.repo.magento.com "$REPO_USR" "$REPO_PSW"
composer install --prefer-dist --no-progress --no-suggest
- name: Run unit tests
run: vendor/bin/phpunit -c phpunit.xml.dist

- name: Upload code coverage
uses: codecov/codecov-action@v2
with:
file: ./coverage.xml
flags: unittests
fail_ci_if_error: false

javascript-tests:
name: JavaScript Tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install dependencies
run: npm install

- name: Run JavaScript tests
run: npm test

- name: Upload code coverage
uses: codecov/codecov-action@v2
with:
file: ./coverage/lcov.info
flags: javascripttests
fail_ci_if_error: false

php-integration-tests:
name: PHP Integration Tests
runs-on: ubuntu-latest
needs: php-unit-tests
if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'integration-tests') }}

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: magento_test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Clone Magento
working-directory: magento
env:
REPO_USR: ${{ secrets.REPO_USR }}
REPO_PSW: ${{ secrets.REPO_PSW }}
run: |
composer config repositories.0 composer https://repo.magento.com
composer config http-basic.repo.magento.com "$REPO_USR" "$REPO_PSW"
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.7 .
- name: Checkout module
uses: actions/checkout@v2
with:
path: magento/app/code/Nosto/Tagging

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
extensions: json, mbstring, xml, intl, gd, zip, soap, pdo_mysql
coverage: pcov
tools: composer:v2, phpunit:9.5

- name: Install Magento
working-directory: magento
env:
REPO_USR: ${{ secrets.REPO_USR }}
REPO_PSW: ${{ secrets.REPO_PSW }}
run: |
composer install --prefer-dist --no-progress
bin/magento setup:install --base-url=http://localhost/ --db-host=127.0.0.1 --db-name=magento_test --db-user=root --db-password=root --admin-firstname=Admin --admin-lastname=User [email protected] --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/New_York --use-rewrites=1 --backend-frontname=admin
- name: Run integration tests
working-directory: magento/app/code/Nosto/Tagging
run: vendor/bin/phpunit -c phpunit.integration.xml.dist
59 changes: 59 additions & 0 deletions Test/Integration/Block/CategoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Nosto\Tagging\Test\Integration\Block;

use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Registry;
use Magento\TestFramework\Helper\Bootstrap;
use Nosto\Model\Category\Category as NostoCategory;
use Nosto\Tagging\Block\Category;
use PHPUnit\Framework\TestCase;

/**
* @magentoAppArea frontend
*/
class CategoryTest extends TestCase
{
/** @var ObjectManager */
private $objectManager;

/** @var Registry */
private $registry;

/** @var CategoryRepositoryInterface */
private $categoryRepository;

/** @var Category */
private $block;

protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->registry = $this->objectManager->get(Registry::class);
$this->categoryRepository = $this->objectManager->get(CategoryRepositoryInterface::class);
$this->block = $this->objectManager->get(Category::class);
}

/**
* @magentoDataFixture Magento/Catalog/_files/category.php
*/
public function testGetAbstractObject()
{
$category = $this->categoryRepository->get(333);
$this->registry->register('current_category', $category);

$nostoCategory = $this->block->getAbstractObject();
$this->assertInstanceOf(NostoCategory::class, $nostoCategory);

// Test that we properly build the category path string
$categoryString = $nostoCategory->disableAutoEncodeAll()->__toString();
$this->assertStringContainsString($category->getName(), $categoryString);
}

public function testGetAbstractObjectWithoutCategory()
{
$nostoCategory = $this->block->getAbstractObject();
$this->assertNull($nostoCategory);
}
}
69 changes: 69 additions & 0 deletions Test/Integration/Block/ProductTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Nosto\Tagging\Test\Integration\Block;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Registry;
use Magento\TestFramework\Helper\Bootstrap;
use Nosto\Model\Product\Product as NostoProduct;
use Nosto\Tagging\Block\Product;
use PHPUnit\Framework\TestCase;

/**
* @magentoAppArea frontend
*/
class ProductTest extends TestCase
{
/** @var ObjectManager */
private $objectManager;

/** @var Registry */
private $registry;

/** @var ProductRepositoryInterface */
private $productRepository;

/** @var Product */
private $block;

protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->registry = $this->objectManager->get(Registry::class);
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
$this->block = $this->objectManager->get(Product::class);
}

/**
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
*/
public function testGetAbstractObject()
{
$product = $this->productRepository->get('simple');
$this->registry->register('product', $product);
$this->registry->register('current_product', $product);

$nostoProduct = $this->block->getAbstractObject();
$this->assertInstanceOf(NostoProduct::class, $nostoProduct);
$this->assertEquals($product->getId(), $nostoProduct->getProductId());
}

/**
* @magentoConfigFixture current_store nosto_tagging/currency/use_multiple_currencies 1
*/
public function testHasMultipleCurrencies()
{
$result = $this->block->hasMultipleCurrencies();
$this->assertTrue($result);
}

/**
* @magentoConfigFixture current_store nosto_tagging/currency/use_multiple_currencies 0
*/
public function testDoesNotHaveMultipleCurrencies()
{
$result = $this->block->hasMultipleCurrencies();
$this->assertFalse($result);
}
}
29 changes: 29 additions & 0 deletions Test/Integration/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

// Integration tests bootstrap file
use Magento\Framework\App\Bootstrap;

// Bootstrap setup for Magento integration tests
$bootstrapParams = $_SERVER;
// Set flag to run without installation
$bootstrapParams[Bootstrap::PARAM_REQUIRE_MAINTENANCE_MODE] = false;
$bootstrapParams[Bootstrap::PARAM_REQUIRE_IS_INSTALLED] = false;

// This assumes the tests are run from the Magento root directory
$magentoRootDir = getcwd();
if (!file_exists($magentoRootDir . '/app/etc/di.xml')) {
// If not being run from Magento root, adjust path
if (file_exists(__DIR__ . '/../../../../app/etc/di.xml')) {
$magentoRootDir = realpath(__DIR__ . '/../../../..');
} elseif (file_exists(__DIR__ . '/../../../../../app/etc/di.xml')) {
$magentoRootDir = realpath(__DIR__ . '/../../../../..');
}
}

require $magentoRootDir . '/app/bootstrap.php';
$bootstrap = Bootstrap::create($magentoRootDir, $bootstrapParams);

$objectManager = $bootstrap->createObjectManager();
$objectManager->configure([
'preferences' => [],
]);
Loading

0 comments on commit d5ee5ef

Please sign in to comment.