Asserts that a haystack contains a needle.
public static assertContains ( mixed $needle, mixed $haystack, string $message = '', boolean $ignoreCase = false, boolean $checkForObjectIdentity = true, boolean $checkForNonObjectIdentity = false ) | ||
$needle | mixed | |
$haystack | mixed | |
$message | string | |
$ignoreCase | boolean | |
$checkForObjectIdentity | boolean | |
$checkForNonObjectIdentity | boolean |
/** * Assert that comment about authorized amount exist in Comments History section on order page in backend. * * @param SalesOrderView $salesOrderView * @param OrderIndex $salesOrder * @param string $orderId * @param array $prices * @return void */ public function processAssert(SalesOrderView $salesOrderView, OrderIndex $salesOrder, $orderId, array $prices) { $salesOrder->open(); $salesOrder->getSalesOrderGrid()->searchAndOpen(['id' => $orderId]); $actualAuthorizedAmount = $salesOrderView->getOrderHistoryBlock()->getCommentsHistory(); \PHPUnit_Framework_Assert::assertContains(self::AUTHORIZED_AMOUNT . $prices['grandTotal'], $actualAuthorizedAmount, 'Incorrect authorized amount value for the order #' . $orderId); }
/** * Assert that created CMS page displays with error message on unassigned store views on frontend. * * @param CmsPage $cms * @param FrontendCmsPage $frontendCmsPage * @param Browser $browser * @param CmsIndex $cmsIndex * @param string|null $notFoundMessage * @return void */ public function processAssert(CmsPage $cms, FrontendCmsPage $frontendCmsPage, Browser $browser, CmsIndex $cmsIndex, $notFoundMessage = null) { $browser->open($_ENV['app_frontend_url'] . $cms->getIdentifier()); $notFoundMessage = $notFoundMessage !== null ? $notFoundMessage : self::ERROR_MESSAGE; $cmsIndex->getHeaderBlock()->selectStore('Default Store View'); \PHPUnit_Framework_Assert::assertContains($notFoundMessage, $frontendCmsPage->getCmsPageContentBlock()->getPageContent(), 'Wrong page content is displayed.'); }
/** * @Then /^I should see "([^"]*)"$/ */ public function iShouldSee($match) { if ($this->response instanceof \Exception) { throw $this->response; } PHPUnit_Framework_Assert::assertContains($match, $this->response->getContent()); }
/** * @Then /^I should see "(?P<text>[^"]*)" in (?P<tableName>[\w\d\-]+) table row with "(?P<row>[^"]*)"$/ * @Then /^I should see "(?P<text>[^"]*)" in (?P<row>\d+)(st|nd|rd|th)? (?P<tableName>[\w\d\-]+) table row$/ */ public function assertTableRowContains($text, $row, $tableName) { $table = $this->findTable($tableName); $row = is_numeric($row) ? $table->getRow($row - 1) : $table->findRow($row); Assert::assertNotEmpty($row, "Couldn't find row {$row} in table: " . PHP_EOL . $table->dump()); Assert::assertContains($text, $row, "Couldn't find {$text} in row " . $table->dumpRows(array($row))); }
/** * @param int $expectedType Expected triggered error type (pass one of PHP's E_* constants) * @param string[] $expectedMessages Expected error messages * @param callable $testCode A callable that is expected to trigger the error messages */ public static function assertErrorsAreTriggered($expectedType, $expectedMessages, $testCode) { if (!is_callable($testCode)) { throw new \InvalidArgumentException(sprintf('The code to be tested must be a valid callable ("%s" given).', gettype($testCode))); } $e = null; $triggeredMessages = array(); try { $prevHandler = set_error_handler(function ($type, $message, $file, $line, $context) use($expectedType, &$triggeredMessages, &$prevHandler) { if ($expectedType !== $type) { return null !== $prevHandler && call_user_func($prevHandler, $type, $message, $file, $line, $context); } $triggeredMessages[] = $message; }); call_user_func($testCode); } catch (\Exception $e) { } catch (\Throwable $e) { } restore_error_handler(); if (null !== $e) { throw $e; } \PHPUnit_Framework_Assert::assertCount(count($expectedMessages), $triggeredMessages); foreach ($triggeredMessages as $i => $message) { \PHPUnit_Framework_Assert::assertContains($expectedMessages[$i], $message); } }
/** * @Given /^I open "([^"]*)" dialog$/ */ public function iOpenDialog($dialog) { $client = self::getClientInstance(); $route = 'oro_' . str_replace(' ', '_', strtolower($dialog)); $client->request('GET', $this->getUrl($route)); WebTestCase::assertHtmlResponseStatusCodeEquals($client->getResponse(), 200); PHPUnit_Framework_Assert::assertContains('Create User - Users - User Management - System', $client->getCrawler()->html()); }
/** * Assert that success message is displayed after Catalog Price Rule saved * * @param CatalogRuleIndex $pageCatalogRuleIndex * @return void */ public function processAssert(CatalogRuleIndex $pageCatalogRuleIndex) { $actualMessages = $pageCatalogRuleIndex->getMessagesBlock()->getSuccessMessages(); if (!is_array($actualMessages)) { $actualMessages = [$actualMessages]; } \PHPUnit_Framework_Assert::assertContains(self::SUCCESS_MESSAGE, $actualMessages, 'Wrong success message is displayed.' . "\nExpected: " . self::SUCCESS_MESSAGE . "\nActual: " . implode(',', $actualMessages)); }
/** * Assert that after adding products by sku, wrong requested quantity error message appears. * * @param CheckoutCart $checkoutCart * @param array $requiredAttentionProducts * @return void */ public function processAssert(CheckoutCart $checkoutCart, array $requiredAttentionProducts) { foreach ($requiredAttentionProducts as $product) { $currentMessage = $checkoutCart->getAdvancedCheckoutCart()->getFailedItemErrorMessage($product); \PHPUnit_Framework_Assert::assertContains(self::ERROR_QUANTITY_MESSAGE, $currentMessage); \PHPUnit_Framework_Assert::assertContains(sprintf($this->allowedQtyMessage, $product->getStockData()[$this->saleQtyType]), $currentMessage); } }
/** * Assert that requested quantity is not available error message is displayed after adding products to cart by sku. * * @param CheckoutCart $checkoutCart * @param array $requiredAttentionProducts * @return void */ public function processAssert(CheckoutCart $checkoutCart, $requiredAttentionProducts) { foreach ($requiredAttentionProducts as $product) { $currentMessage = $checkoutCart->getAdvancedCheckoutCart()->getFailedItemErrorMessage($product); \PHPUnit_Framework_Assert::assertContains(self::ERROR_QUANTITY_MESSAGE, $currentMessage); \PHPUnit_Framework_Assert::assertContains(sprintf(self::LEFT_IN_STOCK_ERROR_MESSAGE, $product->getStockData()['qty']), $currentMessage); } }
/** * Assert that part of license agreement text is present on Terms & Agreement page. * * @param Install $installPage * @return void */ public function processAssert(Install $installPage) { try { \PHPUnit_Framework_Assert::assertContains(self::LICENSE_AGREEMENT_TEXT, $installPage->getLicenseBlock()->getLicense(), 'License agreement text is absent.'); } catch (\Exception $e) { \PHPUnit_Framework_Assert::assertContains(self::DEFAULT_LICENSE_AGREEMENT_TEXT, $installPage->getLicenseBlock()->getLicense(), 'License agreement text is absent.'); } }
/** * @Given /^I open "([^"]*)" dialog$/ */ public function iOpenDialog($dialog) { $client = $this->getInstance(); $route = 'oro_' . str_replace(' ', '_', strtolower($dialog)); $client->request('GET', $client->generate($route)); \Oro\Bundle\TestFrameworkBundle\Test\ToolsAPI::assertJsonResponse($client->getResponse(), 200, ''); PHPUnit_Framework_Assert::assertContains('Create User - Users - System', $client->getCrawler()->html()); }
function assertContains($expected, $collection) { foreach ($collection as $actual) { if ($expected == $actual) { return; } } PHPUnit_Framework_Assert::assertContains($expected, $collection); }
/** * Assert that readiness check items are passed. * * @param SetupWizard $setupWizard * @return void */ public function processAssert(SetupWizard $setupWizard) { \PHPUnit_Framework_Assert::assertContains(self::UPDATER_APPLICATION_MESSAGE, $setupWizard->getReadiness()->getUpdaterApplicationCheck(), 'Updater application check is incorrect.'); \PHPUnit_Framework_Assert::assertContains(self::CRON_SCRIPT_MESSAGE, $setupWizard->getReadiness()->getCronScriptCheck(), 'Cron scripts are incorrect.'); \PHPUnit_Framework_Assert::assertContains(self::DEPENDENCY_CHECK_MESSAGE, $setupWizard->getReadiness()->getDependencyCheck(), 'Dependency check is incorrect.'); \PHPUnit_Framework_Assert::assertContains(self::PHP_VERSION_MESSAGE, $setupWizard->getReadiness()->getPhpVersionCheck(), 'PHP version is incorrect.'); \PHPUnit_Framework_Assert::assertContains(self::PHP_SETTING_REGEXP, $setupWizard->getReadiness()->getSettingsCheck(), 'PHP settings check failed.'); \PHPUnit_Framework_Assert::assertRegExp(self::PHP_EXTENSIONS_REGEXP, $setupWizard->getReadiness()->getPhpExtensionsCheck(), 'PHP extensions missed.'); }
/** * @Then the field :name should have an error containing :message */ public function theFieldShouldHaveAnErrorContaining($name, $message) { $field = $this->assertSession()->fieldExists($name); $parent = $field->getParent(); if (false === stripos($parent->getAttribute('class'), $this->fieldContainerClass)) { $parent = $parent->getParent(); } Assert::assertContains($message, $parent->getText()); }
/** * Assert that comment about captured amount exist in Comments History section on order page in Admin. * * @param SalesOrderView $salesOrderView * @param OrderIndex $salesOrder * @param string $orderId * @param array $capturedPrices * @return void */ public function processAssert(SalesOrderView $salesOrderView, OrderIndex $salesOrder, $orderId, array $capturedPrices) { $salesOrder->open(); $salesOrder->getSalesOrderGrid()->searchAndOpen(['id' => $orderId]); $actualCapturedAmount = $salesOrderView->getOrderHistoryBlock()->getCapturedAmount(); foreach ($capturedPrices as $key => $capturedPrice) { \PHPUnit_Framework_Assert::assertContains(self::CAPTURED_AMOUNT . $capturedPrice, $actualCapturedAmount[$key], 'Incorrect captured amount value for the order #' . $orderId); } }
/** * @Then :file file should contain: * * @param string $file * @param PyStringNode $strings */ public function fileShouldContain($file, PyStringNode $strings) { PHPUnit::assertFileExists($file); $contents = file_get_contents($file); $strings = $strings->getStrings(); array_walk($strings, function ($string) use($contents) { PHPUnit::assertContains($string, $contents); }); }
/** * Assert that add view review links are present on product page. * * @param Browser $browser * @param CatalogProductView $catalogProductView * @param InjectableFixture $product * @param Review $review * @return void */ public function processAssert(Browser $browser, CatalogProductView $catalogProductView, InjectableFixture $product, Review $review) { $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); // Verify add review link \PHPUnit_Framework_Assert::assertTrue($catalogProductView->getReviewViewBlock()->getAddReviewLink()->isVisible(), 'Add review link is not visible on product page.'); // Verify view review link $viewReviewLink = $catalogProductView->getReviewViewBlock()->getViewReviewLink($review); \PHPUnit_Framework_Assert::assertTrue($viewReviewLink->isVisible(), 'View review link is not visible on product page.'); \PHPUnit_Framework_Assert::assertContains('1', $viewReviewLink->getText(), 'There is more than 1 approved review.'); }
/** * Assert that created CMS block displayed on frontend category page (in order to assign block to category: * go to category page> Display settings> CMS Block). * * @param CmsIndex $cmsIndex * @param CmsBlock $cmsBlock * @param CatalogCategoryView $catalogCategoryView * @param FixtureFactory $fixtureFactory * @return void */ public function processAssert(CmsIndex $cmsIndex, CmsBlock $cmsBlock, CatalogCategoryView $catalogCategoryView, FixtureFactory $fixtureFactory) { $category = $fixtureFactory->createByCode('catalogCategory', ['dataSet' => 'default_subcategory', 'data' => ['display_mode' => 'Static block and products', 'landing_page' => $cmsBlock->getTitle()]]); $category->persist(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategory($category->getName()); $categoryViewContent = $catalogCategoryView->getViewBlock()->getText(); $cmsBlockContent = explode("\n", $categoryViewContent); \PHPUnit_Framework_Assert::assertContains($cmsBlock->getContent(), $cmsBlockContent); }
/** * @Then /^Email on address (.*) must be sent$/ */ public function emailOnAddressMustBeSent($address) { $emails = $this->getEmails(); if (!$emails) { throw new \Exception('Email not sent'); } /** @var \Swift_Message $message */ $message = $emails[0]; \PHPUnit_Framework_Assert::assertContains($address, trim(current($message->getTo()))); }
/** * @Then I should get a :arg1 with a rank :arg2 with the following cards: */ public function iShouldGetAWithARankWithTheFollowingCards($arg1, $arg2, TableNode $table) { $expectedCards = $table->getRow(0); $result = $this->handFinder->findHand($this->cards); PHPUnit_Framework_Assert::assertContains($arg1, $result); PHPUnit_Framework_Assert::assertContains($arg2, $result); foreach ($expectedCards as $expectedCard) { PHPUnit_Framework_Assert::assertContains($expectedCard, $result['cards']); } }
/** * @test */ public function it_detects_proper_values_and_constants() { $enum = new FakeEnum(); \PHPUnit_Framework_Assert::assertContains('SOME_KEY', $enum->keys()); \PHPUnit_Framework_Assert::assertArrayHasKey('SOME_KEY', $enum->values()); \PHPUnit_Framework_Assert::assertArrayNotHasKey('some-value', $enum->values()); \PHPUnit_Framework_Assert::assertContains('some-value', $enum->values()); \PHPUnit_Framework_Assert::assertSame('SOME_KEY', $enum->getConstantForValue('some-value')); \PHPUnit_Framework_Assert::assertTrue($enum->has('some-value')); \PHPUnit_Framework_Assert::assertFalse($enum->has('SOME-VALUE')); }
public function testCLIListUsers() { $kernel = $this->app['Illuminate\\Contracts\\Console\\Kernel']; // insert $kernel->call('api:new-user', ['email' => '*****@*****.**']); // list $kernel->call('api:list-users'); $output = $kernel->output(); PHPUnit::assertNotEmpty($output); PHPUnit::assertContains('*****@*****.**', $output); }
/** * Assert that order Id is present in search results * * @param Dashboard $dashboard * @param GlobalSearch $search * @param OrderIndex $orderIndex * @return void */ public function processAssert(Dashboard $dashboard, GlobalSearch $search, OrderIndex $orderIndex) { $order = $search->getDataFieldConfig('query')['source']->getEntity(); $orderId = "Order #" . $order->getId(); $isVisibleInResult = $dashboard->getAdminPanelHeader()->isSearchResultVisible($orderId); \PHPUnit_Framework_Assert::assertTrue($isVisibleInResult, 'Order Id ' . $order->getId() . ' is absent in search results'); $dashboard->getAdminPanelHeader()->navigateToGrid("Orders"); $isOrderGridVisible = $orderIndex->getSalesOrderGrid()->isVisible(); \PHPUnit_Framework_Assert::assertTrue($isOrderGridVisible, 'Order grid is not visible'); \PHPUnit_Framework_Assert::assertContains((string) $order->getId(), $orderIndex->getSalesOrderGrid()->getAllIds(), 'Order grid does not have ' . $order->getId() . ' in search results'); }
/** * @Given /^response should (?P<not>|not )contain "([^"]*)"$/ */ public function responseShouldContain($not = '', $expectedValue) { $shouldNotExist = !empty($not); $value = $this->decodeJson($this->lastResponse->getContent()); $value = is_array($value) ? array_keys($value) : $value; if ($shouldNotExist) { \PHPUnit_Framework_Assert::assertNotContains($expectedValue, $value); } else { \PHPUnit_Framework_Assert::assertContains($expectedValue, $value); } }
/** * Assert that customer name is present in search results * * @param Dashboard $dashboard * @param GlobalSearch $search * @param CustomerIndex $customerIndex * @return void */ public function processAssert(Dashboard $dashboard, GlobalSearch $search, CustomerIndex $customerIndex) { $customer = $search->getDataFieldConfig('query')['source']->getEntity(); $customerName = $customer->getFirstname() . " " . $customer->getLastname(); $isVisibleInResult = $dashboard->getAdminPanelHeader()->isSearchResultVisible($customerName); \PHPUnit_Framework_Assert::assertTrue($isVisibleInResult, 'Customer name ' . $customerName . ' is absent in search results'); $dashboard->getAdminPanelHeader()->navigateToGrid("Customers"); $isCustomerGridVisible = $customerIndex->getCustomerGridBlock()->isVisible(); \PHPUnit_Framework_Assert::assertTrue($isCustomerGridVisible, 'Customer grid is not visible'); \PHPUnit_Framework_Assert::assertContains((string) $customer->getId(), $customerIndex->getCustomerGridBlock()->getAllIds(), 'Customer grid does not have ' . $customerName . ' in search results'); }
/** * @param NodeElement|string $field * @param string $value */ public function assertEmbedField($field, $value) { if (!$field instanceof NodeElement) { $field = $this->findEmbedField($field); } $text = $field->getText(); if (empty($value)) { \PHPUnit_Framework_Assert::assertEmpty($text, sprintf('The grid column body should be empty, got "%s".', $field->getValue(), $text)); } else { \PHPUnit_Framework_Assert::assertContains($value, $text, sprintf('The grid column body "%s" does not contain "%s", got "%s".', $field->getValue(), $value, $text)); } }
protected function setStatusTestingApp($enabled) { $this->sendingTo($enabled ? 'post' : 'delete', '/cloud/apps/testing'); $this->theHTTPStatusCodeShouldBe('200'); $this->theOCSStatusCodeShouldBe('100'); $this->sendingTo('get', '/cloud/apps?filter=enabled'); $this->theHTTPStatusCodeShouldBe('200'); if ($enabled) { PHPUnit_Framework_Assert::assertContains('testing', $this->response->getBody()->getContents()); } else { PHPUnit_Framework_Assert::assertNotContains('testing', $this->response->getBody()->getContents()); } }
/** * @param string|string[] $expected * @param Exception $ex */ public function assertUsageException($expected, Exception $ex) { Assert::assertInstanceOf('UsageException', $ex); /** @var UsageException $ex */ if (is_string($expected)) { $expected = array('code' => $expected); } if (isset($expected['code'])) { Assert::assertEquals($expected['code'], $ex->getCodeString()); } if (isset($expected['message'])) { Assert::assertContains($expected['message'], $ex->getMessage()); } }
/** * Assert product MAP related data on product view page. * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView * @param InjectableFixture $product * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, InjectableFixture $product) { /** @var CatalogProductSimple $product */ $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); $catalogCategoryView->getListProductBlock()->getProductItem($product)->open(); $viewBlock = $catalogProductView->getMsrpViewBlock(); $priceBlock = $viewBlock->getPriceBlock(); \PHPUnit_Framework_Assert::assertEquals($product->getMsrp(), $priceBlock->getOldPrice(), 'Displayed on Product view page MAP is incorrect'); \PHPUnit_Framework_Assert::assertFalse($priceBlock->isRegularPriceVisible(), 'Regular price on Product view page is visible and not expected.'); $viewBlock->openMapBlock(); $mapBlock = $viewBlock->getMapBlock(); \PHPUnit_Framework_Assert::assertContains($product->getMsrp(), $mapBlock->getOldPrice(), 'Displayed on Product view page MAP is incorrect.'); \PHPUnit_Framework_Assert::assertEquals($product->getPrice(), $mapBlock->getActualPrice(), 'Displayed on Product view page price is incorrect.'); }
/** * Assert that Gift Wrapping can be found during one page checkout on frontend. * * @param CatalogProductView $catalogProductView * @param CheckoutCart $checkoutCart * @param BrowserInterface $browser * @param CheckoutOnepage $checkoutOnepage * @param GiftWrapping $giftWrapping * @param Address $billingAddress * @param CatalogProductSimple $product * @param Customer $customer * @param CustomerAccountLogout $customerAccountLogout * @return void */ public function processAssert(CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, BrowserInterface $browser, CheckoutOnepage $checkoutOnepage, GiftWrapping $giftWrapping, Address $billingAddress, CatalogProductSimple $product, Customer $customer, CustomerAccountLogout $customerAccountLogout) { // Preconditions $customer->persist(); $product->persist(); // Steps $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $catalogProductView->getViewBlock()->addToCart($product); $checkoutCart->open()->getCartBlock()->getProceedToCheckoutBlock()->proceedToCheckout(); $checkoutOnepage->getLoginBlock()->loginCustomer($customer); $checkoutOnepage->getBillingBlock()->fillBilling($billingAddress); $checkoutOnepage->getBillingBlock()->clickContinue(); \PHPUnit_Framework_Assert::assertContains($giftWrapping->getDesign(), $checkoutOnepage->getGiftOptionsBlock()->getGiftWrappingsAvailable(), "Gift Wrapping '{$giftWrapping->getDesign()}' is not present in one page checkout on frontend."); $customerAccountLogout->open(); }