public function testInitializesItself() { $add = [['name' => 'language', 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => ['data-autoinit' => 'false']], ['name' => 'levelListening', 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => ['data-allowclear' => 'true', 'data-searchbox' => -1]], ['name' => 'levelReading', 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => ['data-allowclear' => 'true', 'data-searchbox' => -1, 'data-autoinit' => "false"]], ['name' => 'levelSpokenInteraction', 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => ['data-allowclear' => 'true', 'data-searchbox' => -1]], ['name' => 'levelSpokenProduction', 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => ['data-allowclear' => 'true', 'data-searchbox' => -1]], ['name' => 'levelWriting', 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => ['data-allowclear' => 'true', 'data-searchbox' => -1]]]; $callCount = count($add); $arrayContainsPairs = function ($expected, $actual) use(&$arrayContainsPairs) { foreach ($expected as $key => $value) { if (!array_key_exists($key, $actual)) { return false; } if (is_array($value)) { return $arrayContainsPairs($value, $actual[$key]); } return $value === $actual[$key]; } }; $addArgValidator = function ($arg) use($add, $callCount, $arrayContainsPairs) { static $count = 0; /* PPHUnit calls this callback again after all invokations are made * I don't know why, but therefor the need to check if $count is greater that 7 */ return $callCount < $count + 1 || $arrayContainsPairs($add[$count++], $arg); }; $this->target->expects($this->exactly($callCount))->method('add')->with($this->callback($addArgValidator))->will($this->returnSelf()); $this->target->init(); }
/** * @testdox Configures itself in the init() method. */ public function testInitialization() { $this->target->expects($this->once())->method('setAttribute')->with('id', 'jobcompanyname-fieldset'); $this->target->expects($this->once())->method('setName')->with('jobCompanyName'); $addParam = array('type' => 'Jobs/HiringOrganizationSelect', 'property' => true, 'name' => 'companyId', 'options' => array('label' => 'Companyname'), 'attributes' => array('data-placeholder' => 'Select hiring organization', 'data-allowclear' => 'false')); $this->target->expects($this->once())->method('add')->with($addParam); $this->target->init(); }
protected function setUp() { $this->pager = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\pager\\PagerPluginBase')->disableOriginalConstructor()->getMockForAbstractClass(); $view = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock(); $display = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')->disableOriginalConstructor()->getMock(); $options = array('items_per_page' => 5, 'offset' => 1); $this->pager->init($view, $display, $options); $this->pager->current_page = 1; }
/** * Test for method init. * * @dataProvider errorMessageInfo * @SuppressWarnings(PHPMD.NPathComplexity) */ public function testInit($initData) { $errorLevel = isset($initData['errorLevel']) ? $initData['errorLevel'] : null; $rowNumber = isset($initData['rowNumber']) ? $initData['rowNumber'] : null; $columnName = isset($initData['columnName']) ? $initData['columnName'] : null; $errorMessage = isset($initData['errorMessage']) ? $initData['errorMessage'] : null; $errorDescription = isset($initData['errorDescription']) ? $initData['errorDescription'] : null; $this->model->init($initData['errorCode'], $errorLevel, $rowNumber, $columnName, $errorMessage, $errorDescription); }
public function testInitializesItself() { $add = [['type' => 'Core/Datepicker', 'name' => 'startDate', 'options' => ['label' => 'Start date', 'data-width' => '50%', 'class' => 'selectpicker']], ['type' => 'Core/Datepicker', 'name' => 'endDate', 'options' => ['label' => 'End date']], ['type' => 'checkbox', 'name' => 'currentIndicator', 'options' => ['label' => 'ongoing']], ['name' => 'competencyName', 'options' => ['label' => 'Degree'], 'attributes' => ['title' => 'please enter the name of your qualification']], ['name' => 'organizationName', 'options' => ['label' => 'Organization Name'], 'attributes' => ['title' => 'please enter the name of the university or school']], ['name' => 'country', 'options' => ['label' => 'Country'], 'attributes' => ['title' => 'please select the country']], ['name' => 'city', 'options' => ['label' => 'City'], 'attributes' => ['title' => 'please enter the name of the city']], ['name' => 'description', 'type' => 'Zend\\Form\\Element\\Textarea', 'options' => ['label' => 'Description'], 'attributes' => ['title' => 'please enter a description']]]; $addArgValidator = function ($arg) use($add) { static $count = 0; /* PPHUnit calls this callback again after all invokations are made * I don't know why, but therefor the need to check if $count is greater that 7 */ return 7 < $count || $arg === $add[$count++]; }; $this->target->expects($this->exactly(count($add)))->method('add')->with($this->callback($addArgValidator))->will($this->returnSelf()); $this->target->init(); }
/** * @covers ::init() */ public function testInitializesItself() { $add = [['name' => 'typeOfApplication', 'type' => 'select', 'options' => ['value_options' => $this->attributes['typeOfApplicationOptions'], 'label' => 'desired type of work', 'description' => 'Do you want to work permanently or temporary?'], 'attributes' => ['title' => 'please describe your position', 'description' => 'what kind of ', 'data-placeholder' => 'please select', 'data-allowclear' => 'false', 'data-searchbox' => -1, 'multiple' => true, 'data-width' => '100%']], ['name' => 'desiredJob', 'type' => 'Text', 'options' => ['label' => 'desired job position', 'description' => 'Enter the title of your desired job. Eg. "Software Developer" or "Customer Service Representative"'], 'attributes' => ['title' => 'please describe your position']], ['name' => 'geo-location', 'type' => 'Location', 'options' => ['label' => 'desired job location', 'description' => 'Where do you want to work?', 'engine_type' => 'testengine'], 'attributes' => ['title' => 'please describe your position']], ['name' => 'willingnessToTravel', 'type' => 'Select', 'options' => ['value_options' => $this->attributes['willingnessToTravelOptions'], 'label' => 'Willingness to travel', 'description' => 'Enter your willingness to travel.'], 'attributes' => ['data-placeholder' => 'please select', 'data-allowclear' => 'false', 'data-searchbox' => -1, 'data-width' => '100%']], ['name' => 'expectedSalary', 'type' => 'Text', 'options' => ['label' => 'expected Salary', 'description' => 'What is your expected Salary?'], 'attributes' => ['title' => 'please describe your position']]]; $callCount = count($add); $addArgValidator = function ($arg) use($add, $callCount) { static $count = 0; /* PPHUnit calls this callback again after all invokations are made * I don't know why, but therefor the need to check if $count is greater that 7 */ return $callCount - 1 < $count || $arg === $add[$count++]; }; $this->target->expects($this->exactly($callCount))->method('add')->with($this->callback($addArgValidator))->will($this->returnSelf()); $this->target->setLocationEngineType('testengine'); $this->target->init(); }
public function testInitWorks() { $expectedBaseUrl = 'https://example.com/api/v2'; $expectedClientOptions = ['auth' => ['username', 'password']]; $expectedClient = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Provider\\Rest\\Client\\RestClientInterface'); $entity = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport')->disableOriginalConstructor()->getMock(); $settings = $this->getMock('Symfony\\Component\\HttpFoundation\\ParameterBag'); $entity->expects($this->atLeastOnce())->method('getSettingsBag')->will($this->returnValue($settings)); $this->transport->expects($this->once())->method('getClientBaseUrl')->with($settings)->will($this->returnValue($expectedBaseUrl)); $this->transport->expects($this->once())->method('getClientOptions')->with($settings)->will($this->returnValue($expectedClientOptions)); $this->clientFactory->expects($this->once())->method('createRestClient')->with($expectedBaseUrl, $expectedClientOptions)->will($this->returnValue($expectedClient)); $this->transport->init($entity); $this->assertAttributeSame($expectedClient, 'client', $this->transport); $this->assertSame($expectedClient, $this->transport->getClient()); }
public function testInitAddToCustomerGroups() { $searchCriteria = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria); $groupSearchResult = $this->getMockForAbstractClass('\\Magento\\Customer\\Api\\Data\\GroupSearchResultsInterface', [], '', false); $this->groupRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($groupSearchResult); $groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass(); $expectedCode = 'code'; $expectedId = 'id'; $expectedCustomerGroups = [$expectedCode => $expectedId]; $groupTest->expects($this->once())->method('getCode')->willReturn($expectedCode); $groupTest->expects($this->once())->method('getId')->willReturn($expectedId); $groups = [$groupTest]; $groupSearchResult->expects($this->once())->method('getItems')->willReturn($groups); $this->groupPrice->init(); $this->assertEquals($expectedCustomerGroups, $this->getPropertyValue($this->groupPrice, 'customerGroups')); }
/** * @dataProvider wsiDataProvider * * @param mixed $actionParams * @param mixed $expectedParams * @param \stdClass $remoteResponse * @param mixed $expectedData */ public function testWSICompatibility($actionParams, $expectedParams, $remoteResponse, $expectedData) { $this->settings->set('wsi_mode', true); $this->initSettings(true); $testActionName = 'testAction'; $this->soapClientMock->expects($this->at(1))->method('__soapCall')->with($this->equalTo($testActionName), $this->equalTo([(object) $expectedParams]))->will($this->returnValue($remoteResponse)); $this->transport->init($this->transportEntity); $result = $this->transport->call($testActionName, $actionParams); $this->assertEquals($expectedData, $result); }
/** * @dataProvider methodsDataProvider * * @param string $method * @param $endpoint * @param $expectedParameters * @param $result * @param array|null $arguments * @param bool $withPing * @param bool $extensionInstalled */ public function testCalls($method, $endpoint, $expectedParameters, $result, array $arguments = null, $withPing = false, $extensionInstalled = true) { $this->initSettings(false, ['oroPing']); $this->transport->init($this->transportEntity); $this->soapClientMock->expects($withPing ? $this->at(1) : $this->once())->method('__soapCall')->with($endpoint, $expectedParameters)->will($this->returnValue($result)); $pingResponse = null; if ($withPing) { if ($extensionInstalled) { $pingResponse = (object) ['version' => '1.2.3', 'mage_version' => '1.8.0.0', 'admin_url' => 'http://localhost/admin/']; } $this->soapClientMock->expects($this->at(0))->method('__soapCall')->with(SoapTransport::ACTION_PING, ['sessionId' => $this->sessionId])->will($this->returnValue($pingResponse)); } $this->assertEquals($result, call_user_func_array([$this->transport, $method], $arguments)); }
public function testMultipleAttempt() { $this->soapClientMock->expects($this->at(0))->method('__getLastResponseHeaders')->will($this->returnValue("HTTP/1.1 502 Bad gateway\n\r")); $this->soapClientMock->expects($this->at(0))->method('__soapCall')->will($this->throwException(new \Exception('error', 502))); $this->soapClientMock->expects($this->at(1))->method('__getLastResponseHeaders')->will($this->returnValue("HTTP/1.1 503 Service unavailable Explained\n\r")); $this->soapClientMock->expects($this->at(1))->method('__soapCall')->will($this->throwException(new \Exception('error', 503))); $this->soapClientMock->expects($this->at(2))->method('__getLastResponseHeaders')->will($this->returnValue("HTTP/1.1 504 Gateway timeout Explained\n\r")); $this->soapClientMock->expects($this->at(2))->method('__soapCall')->will($this->throwException(new \Exception('error', 504))); $this->soapClientMock->expects($this->at(4))->method('__getLastResponseHeaders')->will($this->returnValue("HTTP/1.1 200 OK\n\r")); $this->soapClientMock->expects($this->at(4))->method('__soapCall'); $this->transport->expects($this->once())->method('getSoapClient')->will($this->returnValue($this->soapClientMock)); $this->settings->set('wsdl_url', 'http://localhost.not.exists/?wsdl'); $this->transport->init($this->transportEntity); $this->transport->call('test'); }
/** * @dataProvider isValidAddMessagesCallDataProvider * * @param array $value * @param bool $hasEmptyColumns * @param array $customerGroups * @param array $expectedMessages */ public function testIsValidAddMessagesCall($value, $hasEmptyColumns, $customerGroups, $expectedMessages) { $priceContextMock = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', [], ['\\Magento\\Framework\\Json\\Helper\\Data', '\\Magento\\ImportExport\\Helper\\Data', '\\Magento\\ImportExport\\Model\\ResourceModel\\Import\\Data', '\\Magento\\Eav\\Model\\Config', '\\Magento\\Framework\\App\\ResourceConnection', '\\Magento\\ImportExport\\Model\\ResourceModel\\Helper', '\\Magento\\Framework\\Stdlib\\StringUtils', 'ProcessingErrorAggregatorInterface'], '', false); $this->tierPrice->expects($this->once())->method('isValidValueAndLength')->willReturn(true); $this->tierPrice->expects($this->any())->method('hasEmptyColumns')->willReturn($hasEmptyColumns); $this->setPropertyValue($this->tierPrice, 'customerGroups', $customerGroups); $searchCriteria = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $this->searchCriteriaBuilder->expects($this->any())->method('create')->willReturn($searchCriteria); $groupSearchResult = $this->getMockForAbstractClass('\\Magento\\Customer\\Api\\Data\\GroupSearchResultsInterface', [], '', false); $this->groupRepository->expects($this->any())->method('getList')->with($searchCriteria)->willReturn($groupSearchResult); $groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass(); $groupTest->expects($this->once())->method('getCode'); $groupTest->expects($this->any())->method('getId'); $groups = [$groupTest]; $groupSearchResult->expects($this->any())->method('getItems')->willReturn($groups); $this->tierPrice->init($priceContextMock); $this->tierPrice->isValid($value); }
public function testInit() { $result = $this->website->init(null); $this->assertEquals($this->website, $result); }
public function testInitializesItself() { $this->target->expects($this->exactly(2))->method('add')->withConsecutive([['type' => 'Collection', 'name' => 'nativeLanguages', 'options' => ['label' => 'Native Language', 'count' => 1, 'should_create_template' => true, 'allow_add' => true, 'target_element' => ['type' => 'Cv/NativeLanguageFieldset']]]], [['type' => 'Collection', 'name' => 'languageSkills', 'options' => ['label' => 'Other languages', 'count' => 1, 'should_create_template' => true, 'allow_add' => true, 'target_element' => ['type' => 'LanguageSkillFieldset']]]]); $this->target->init(); }
public function testInitializesItself() { $formsSpec = ['contact' => ['type' => 'Auth/UserInfo', 'property' => 'contact'], 'image' => ['type' => 'CvContactImage', 'property' => 'contact', 'use_files_array' => true], 'preferredJob' => ['type' => 'Cv/PreferredJobForm', 'property' => 'preferredJob', 'options' => ['is_disable_capable' => true, 'is_disable_elements_capable' => true, 'enable_descriptions' => true, 'description' => 'Where do you want to work tomorrow? This heading gives an immediate overview of your desired next job.']], 'employments' => ['type' => 'CvEmploymentCollection', 'property' => 'employmentsIndexedById'], 'educations' => ['type' => 'CvEducationCollection', 'property' => 'educationsIndexedById'], 'nativeLanguage' => ['type' => 'Cv/NativeLanguageForm', 'property' => true, 'options' => ['enable_descriptions' => true, 'description' => 'Please select from list or enter your mother tongue.']], 'languageSkills' => ['type' => 'Cv/LanguageSkillCollection', 'property' => 'languageSkillsIndexedById'], 'skills' => ['type' => 'CvSkillCollection', 'property' => 'skillsIndexedById'], 'attachments' => 'Cv/Attachments']; $this->target->expects($this->once())->method('setForms')->with($formsSpec); $this->target->init(); }
public function testInitializesItself() { $add = ['name' => 'nativeLanguages', 'type' => 'Zend\\Form\\Element\\Select', 'options' => ['label' => 'Language', 'value_options' => self::$languagesOptions], 'attributes' => ['id' => 'languageskill-language', 'title' => 'what is your native language', 'multiple' => true, 'data-allowclear' => true, 'data-searchbox' => -1]]; $this->target->expects($this->once())->method('add')->with($add); $this->target->init(); }