64 private $themeModelFactory;
68 $customizationConfig = $this->createMock(\
Magento\
Theme\Model\
Config\Customization::class);
69 $this->customizationFactory = $this->createPartialMock(
74 $this->_imageFactory = $this->createPartialMock(
78 $this->themeFactory = $this->createPartialMock(
82 $this->domainFactory = $this->createPartialMock(
86 $this->themeModelFactory = $this->createPartialMock(\
Magento\
Theme\Model\ThemeFactory::class, [
'create']);
87 $this->validator = $this->createMock(\
Magento\Framework\View\
Design\
Theme\Validator::class);
88 $this->appState = $this->createMock(\
Magento\Framework\
App\State::class);
91 $arguments = $objectManagerHelper->getConstructArguments(
94 'customizationFactory' => $this->customizationFactory,
95 'customizationConfig' => $customizationConfig,
96 'imageFactory' => $this->_imageFactory,
97 'resourceCollection' => $this->resourceCollection,
98 'themeFactory' => $this->themeFactory,
99 'domainFactory' => $this->domainFactory,
100 'validator' => $this->validator,
101 'appState' => $this->appState,
102 'themeModelFactory' => $this->themeModelFactory
111 $this->_model =
null;
119 $this->_imageFactory->expects($this->once())->method(
'create')->with([
'theme' => $this->_model]);
120 $this->_model->getThemeImage();
131 $this->_model->setType(
$type);
132 $this->assertEquals($isVirtual, $this->_model->isVirtual());
155 $this->_model->setType(
$type);
156 $this->assertEquals($isPhysical, $this->_model->isPhysical());
179 $this->_model->setType(
$type);
180 $this->assertEquals($isVisible, $this->_model->isVisible());
203 public function testIsDeletable($themeType, $isDeletable)
205 $themeModel = $this->createPartialMock(\
Magento\
Theme\Model\Theme::class, [
'getType']);
206 $themeModel->expects($this->once())->method(
'getType')->will($this->returnValue($themeType));
208 $this->assertEquals($isDeletable, $themeModel->isDeletable());
230 $this->_model->setCode($originalCode);
231 $this->assertSame($expectedCode, $this->_model->getCode());
240 'string code' => [
'theme/code',
'theme/code'],
241 'null code' => [
null,
''],
242 'number code' => [10,
'10']
252 $inheritedTheme = $this->getMockBuilder(\
Magento\Framework\View\
Design\ThemeInterface::class)->getMock();
254 $this->_model->setParentId(10);
255 $this->themeFactory->expects($this->once())
258 ->willReturn($inheritedTheme);
260 $this->assertContainsOnlyInstancesOf(
262 $this->_model->getInheritedThemes()
264 $this->assertCount(2, $this->_model->getInheritedThemes());
275 ->setMethods([
'delete',
'getId'])
276 ->getMockForAbstractClass();
277 $theme->expects($this->once())
279 ->willReturn($expectId);
280 $theme->expects($this->once())
284 $this->_model->setId(1);
285 $this->resourceCollection->expects($this->at(0))
286 ->method(
'addFieldToFilter')
287 ->with(
'parent_id', 1)
289 $this->resourceCollection->expects($this->at(1))
290 ->method(
'addFieldToFilter')
293 $this->resourceCollection->expects($this->once())
294 ->method(
'getFirstItem')
296 $this->resourceCollection->expects($this->once())
297 ->method(
'updateChildRelations')
298 ->with($this->_model);
300 $this->assertInstanceOf(get_class($this->_model), $this->_model->afterDelete());
310 ->setMethods([
'getId'])
311 ->getMockForAbstractClass();
312 $theme->expects($this->once())
316 $this->_model->setId(1);
317 $this->resourceCollection->expects($this->at(0))
318 ->method(
'addFieldToFilter')
319 ->with(
'parent_id', 1)
321 $this->resourceCollection->expects($this->at(1))
322 ->method(
'addFieldToFilter')
325 $this->resourceCollection->expects($this->once())
326 ->method(
'getFirstItem')
329 $this->assertNull($this->_model->getStagingVersion());
338 $this->assertNull($this->_model->getStagingVersion());
348 $this->domainFactory->expects($this->once())
350 ->with($this->_model)
352 $this->assertEquals(
$result, $this->_model->getDomainModel());
362 $this->_model->getDomainModel(
'bla-bla-bla');
373 $this->validator->expects($this->once())
375 ->with($this->_model)
377 $this->validator->expects($this->once())
378 ->method(
'getErrorMessages')
379 ->willReturn([[
__(
'testMessage')]]);
380 $this->assertInstanceOf(get_class($this->_model), $this->_model->beforeSave());
389 $this->validator->expects($this->once())
391 ->with($this->_model)
393 $this->assertInstanceOf(get_class($this->_model), $this->_model->beforeSave());
402 $this->_model->setId(1);
403 $this->resourceCollection->expects($this->once())
404 ->method(
'addTypeFilter')
407 $this->resourceCollection->expects($this->once())
408 ->method(
'addFieldToFilter')
409 ->with(
'parent_id', [
'eq' => 1])
411 $this->resourceCollection->expects($this->once())
414 $this->assertTrue($this->_model->hasChildThemes());
423 $this->customizationFactory->expects($this->once())
426 $this->getMockBuilder(\
Magento\Framework\View\
Design\
Theme\CustomizationInterface::class)->getMock()
428 $this->assertInstanceOf(
441 $this->assertTrue($this->_model->isEditable());
443 $this->assertFalse($this->_model->isEditable());
452 $areaCode =
'frontend';
453 $this->appState->expects($this->once())
454 ->method(
'getAreaCode')
455 ->willReturn($areaCode);
458 $this->_model->setThemePath(
$path);
469 $this->_model->setParentTheme(
'parent_theme');
470 $this->assertEquals(
'parent_theme', $this->_model->getParentTheme());
480 $this->_model->setData($themeData);
481 $this->assertEquals($expected, $this->_model->toArray());
489 $parentTheme = $this->getMockBuilder(\
Magento\
Theme\Model\Theme::class)
490 ->disableOriginalConstructor()
492 $childTheme = clone $parentTheme;
494 $parentTheme->expects($this->once())
496 ->willReturn(
'parent_theme');
498 $childTheme->expects($this->exactly(2))
500 ->willReturn(
'child_theme');
505 [
'theme_data' =>
'theme_data'],
506 [
'theme_data' =>
'theme_data']
508 'valid with parent' => [
510 'theme_data' =>
'theme_data',
511 'parent_theme' => $parentTheme
514 'theme_data' =>
'theme_data',
515 'parent_theme' =>
'parent_theme' 518 'valid with children' => [
520 'theme_data' =>
'theme_data',
521 'inherited_themes' => [
522 'key1' => $childTheme,
523 'key2' => $childTheme
527 'theme_data' =>
'theme_data',
528 'inherited_themes' => [
529 'key1' =>
'child_theme',
530 'key2' =>
'child_theme' 546 $themeMock = $this->getMockBuilder(\
Magento\
Theme\Model\Theme::class)
547 ->disableOriginalConstructor()
549 $themeMock->expects($this->exactly($expectedCallCount))
550 ->method(
'populateFromArray')
551 ->willReturn(
'theme_instance');
553 $this->themeModelFactory->expects($this->exactly($expectedCallCount))
555 ->willReturn($themeMock);
557 $this->_model->populateFromArray(
$value);
558 $this->assertEquals($expected, $this->_model->getData());
568 'value' => [
'theme_data' =>
'theme_data'],
569 'expected' => [
'theme_data' =>
'theme_data']
571 'valid data with parent' => [
573 'theme_data' =>
'theme_data',
575 'theme_data' =>
'theme_data' 579 'theme_data' =>
'theme_data',
580 'parent_theme' =>
'theme_instance' 582 'expected call count' => 1
584 'valid data with children' => [
586 'theme_data' =>
'theme_data',
587 'inherited_themes' => [
588 'key1' => [
'theme_data' =>
'theme_data'],
589 'key2' => [
'theme_data' =>
'theme_data']
593 'theme_data' =>
'theme_data',
594 'inherited_themes' => [
595 'key1' =>
'theme_instance',
596 'key2' =>
'theme_instance' 599 'expected call count' => 2
isDeletableDataProvider()
testIsVisible($type, $isVisible)
testGetDomainModelWithIncorrectType()
testPopulateFromArray(array $value, array $expected, $expectedCallCount=0)
testGetCode($originalCode, $expectedCode)
testGetStagingVersionWithoutTheme()
testIsVirtual($type, $isVirtual)
testToArray(array $themeData, array $expected)
populateFromArrayDataProvider()
testIsPhysical($type, $isPhysical)