Skip to content

Commit

Permalink
[shopsys] frontend API testing on b2b domain (#3508)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitek-rostislav authored Nov 4, 2024
2 parents 80a2050 + 80a408f commit 48beb86
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 108 deletions.
157 changes: 50 additions & 107 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,11 @@
<matches string="${domains-info.ids}" pattern="\d+\s+\d+"/>
<then>
<property name="domains-info.is-multidomain" value="true"/>
<property name="phpunit-exclude-group" value="singledomain"/>
</then>
<else>
<property name="domains-info.is-multidomain" value="false"/>
<property name="phpunit-exclude-group" value="multidomain"/>
</else>
</if>
</target>
Expand Down Expand Up @@ -1412,103 +1414,60 @@
</trycatch>
</target>

<target name="tests-functional" depends="tests-functional-application,tests-functional-frontend-api" description="Runs functional tests."/>
<target name="tests-functional" depends="tests-functional-application,tests-functional-frontend-api,tests-functional-frontend-api-b2b" description="Runs functional tests."/>

<target name="tests-functional-application" depends="production-protection,clean,test-clean-redis,domains-info-load" description="Runs application functional tests." hidden="true">
<if>
<istrue value="${domains-info.is-multidomain}"/>
<then>
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="Functional"/>
<arg value="--exclude-group"/>
<arg value="singledomain"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
</exec>
</then>
<else>
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="Functional"/>
<arg value="--exclude-group"/>
<arg value="multidomain"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
</exec>
</else>
</if>
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="Functional"/>
<arg value="--exclude-group"/>
<arg value="${phpunit-exclude-group}"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
</exec>
</target>

<target name="tests-functional-frontend-api" depends="production-protection,clean,test-clean-redis,domains-info-load" description="Runs Frontend API functional tests." hidden="true">
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="FrontendApiFunctional"/>
<arg value="--exclude-group"/>
<arg value="${phpunit-exclude-group}"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
</exec>
</target>

<target name="tests-functional-frontend-api-b2b" depends="production-protection,clean,test-clean-redis,domains-info-load" description="Runs Frontend API functional tests on B2B domain." hidden="true">
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="FrontendApiFunctionalB2b"/>
<arg value="--exclude-group"/>
<arg value="${phpunit-exclude-group}"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
</exec>
</target>

<target name="tests-functional-single" depends="set-functional-test-name,production-protection,clean,test-clean-redis,domains-info-load" description="Runs custom functional test.">
<if>
<istrue value="${domains-info.is-multidomain}"/>
<not><equals arg1="${test.functional.name}" arg2="all"/></not>
<then>
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="FrontendApiFunctional"/>
<arg value="Functional,FrontendApiFunctional,FrontendApiFunctionalB2b"/>
<arg value="--exclude-group"/>
<arg value="singledomain"/>
<arg value="${phpunit-exclude-group}"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
<arg value="--filter"/>
<arg value="${test.functional.name}"/>
</exec>
</then>
<else>
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="FrontendApiFunctional"/>
<arg value="--exclude-group"/>
<arg value="multidomain"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
</exec>
</else>
</if>
</target>

<target name="tests-functional-single" depends="set-functional-test-name,production-protection,clean,test-clean-redis,domains-info-load" description="Runs custom functional test.">
<if>
<istrue value="${domains-info.is-multidomain}"/>
<then>
<if>
<not><equals arg1="${test.functional.name}" arg2="all"/></not>
<then>
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="Functional,FrontendApiFunctional"/>
<arg value="--exclude-group"/>
<arg value="singledomain"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
<arg value="--filter"/>
<arg value="${test.functional.name}"/>
</exec>
</then>
</if>
</then>
<else>
<if>
<not><equals arg1="${test.functional.name}" arg2="all"/></not>
<then>
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="Functional,FrontendApiFunctional"/>
<arg value="--exclude-group"/>
<arg value="multidomain"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
<arg value="--filter="/>
<arg value="${test.functional.name}"/>
</exec>
</then>
</if>
</else>
</if>
</target>

Expand Down Expand Up @@ -1539,31 +1498,15 @@
</target>

<target name="tests-smoke" depends="production-protection,clean,test-clean-redis,domains-info-load" description="Runs smoke tests.">
<if>
<istrue value="${domains-info.is-multidomain}"/>
<then>
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="Smoke"/>
<arg value="--exclude-group"/>
<arg value="singledomain"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
</exec>
</then>
<else>
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="Smoke"/>
<arg value="--exclude-group"/>
<arg value="multidomain"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
</exec>
</else>
</if>
<exec executable="${path.phpunit.executable}" logoutput="true" passthru="true" checkreturn="true">
<arg value="--colors=always"/>
<arg value="--testsuite"/>
<arg value="Smoke"/>
<arg value="--exclude-group"/>
<arg value="${phpunit-exclude-group}"/>
<arg value="--configuration"/>
<arg value="${path.root}/phpunit.xml"/>
</exec>
</target>

<target name="tests-unit" depends="production-protection,clean,tests-unit-jest" description="Runs unit tests.">
Expand Down
14 changes: 14 additions & 0 deletions src/Component/Domain/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,18 @@ public function isB2b(): bool
{
return $this->getCurrentDomainConfig()->isB2b();
}

/**
* @return \Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig|null
*/
public function findFirstB2bDomain(): ?DomainConfig
{
foreach ($this->getAll() as $domainConfig) {
if ($domainConfig->isB2b()) {
return $domainConfig;
}
}

return null;
}
}
7 changes: 6 additions & 1 deletion tests/Test/TestTranslatableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Metadata\MetadataFactory;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Component\Domain\Exception\NoDomainSelectedException;
use Shopsys\FrameworkBundle\Model\Administration\AdministrationFacade;
use Shopsys\FrameworkBundle\Model\Localization\TranslatableListener;

Expand Down Expand Up @@ -35,7 +36,11 @@ public function getCurrentLocale()
return $this->adminLocale;
}

return $this->getFirstDomainLocale();
try {
return $this->domain->getLocale();
} catch (NoDomainSelectedException) {
return $this->getFirstDomainLocale();
}
}

/**
Expand Down

0 comments on commit 48beb86

Please sign in to comment.