assertCount example



        $this->repository->create([$data]$this->context);

        /** @var ProductEntity $product */
        $product = $this->repository
            ->search(new Criteria([$id])$this->context)
            ->get($id);

        static::assertInstanceOf(PriceCollection::class$product->getPrice());

        static::assertCount(2, $product->getPrice());

        static::assertEquals(
            new Price(Defaults::CURRENCY, 10, 15, false),
            $product->getCurrencyPrice(Defaults::CURRENCY)
        );

        static::assertEquals(
            new Price($id, 100, 150, true),
            $product->getCurrencyPrice($id)
        );
    }

    

        try {
            $this->conditionRepository->create([
                [
                    'type' => (new LineItemWithQuantityRule())->getName(),
                    'ruleId' => Uuid::randomHex(),
                ],
            ]$this->context);
            static::fail('Exception was not thrown');
        } catch (WriteException $stackException) {
            $exceptions = iterator_to_array($stackException->getErrors());
            static::assertCount(3, $exceptions);
            static::assertSame('/0/value/id', $exceptions[0]['source']['pointer']);
            static::assertSame(NotBlank::IS_BLANK_ERROR, $exceptions[0]['code']);

            static::assertSame('/0/value/quantity', $exceptions[1]['source']['pointer']);
            static::assertSame(NotBlank::IS_BLANK_ERROR, $exceptions[1]['code']);

            static::assertSame('/0/value/operator', $exceptions[2]['source']['pointer']);
            static::assertSame(NotBlank::IS_BLANK_ERROR, $exceptions[2]['code']);
        }
    }

    
public function testMigrateGermanIsStandard(): void
    {
        // This is intended, the current german language ID will become the english language id afterwards         $englishId = $this->getDeDeLanguageId();
        $context = new Context(new SystemSource()[], Defaults::CURRENCY, [$englishId, Defaults::LANGUAGE_SYSTEM]);
        $this->importExportProfileRepository->create($this->getEnglishData()$context);

        $this->setDefaultLanguageToLocale('de-DE');
        $this->executeMigration();

        $translations = $this->connection->fetchAllAssociative('SELECT * FROM import_export_profile_translation');
        static::assertCount(12, $translations);

        $labels = array_column($translations, 'label');
        static::assertContains('Standardprofil Variantenkonfiguration', $labels);
    }

    public function testMigrateEnglishIsStandard(): void
    {
        $context = new Context(new SystemSource()[], Defaults::CURRENCY, [Defaults::LANGUAGE_SYSTEM]);
        $this->importExportProfileRepository->create($this->getEnglishData()$context);

        $this->executeMigration();

        
$sorts = $view->display_handler->getOption('sorts');
    // Change the label to something with special characters.     $sorts['id']['expose']['label'] = $expected_label = "<script>alert('unsafe&dangerous');</script>";
    // Use a custom sort field identifier.     $sorts['id']['expose']['field_identifier'] = $field_identifier = $this->randomMachineName() . '-_.~';
    $view->display_handler->setOption('sorts', $sorts);
    $view->save();

    // Test label escaping.     $this->drupalGet('test_exposed_form_sort_items_per_page');
    $options = $this->assertSession()->selectExists('edit-sort-by')->findAll('css', 'option');
    $this->assertCount(1, $options);
    // Check option existence by option label.     $this->assertSession()->optionExists('Sort by', $expected_label);
    // Check option existence by option value.     $this->assertSession()->optionExists('Sort by', $field_identifier);
    $escape_1 = Html::escape($expected_label);
    $escape_2 = Html::escape($escape_1);
    // Make sure we see the single-escaped string in the raw output.     $this->assertSession()->responseContains($escape_1);
    // But no double-escaped string.     $this->assertSession()->responseNotContains($escape_2);
    // And not the raw label, either.
$this->addTaxDataToSalesChannel($this->context, $tax);

        $cart->add(
            (new LineItem($id, LineItem::PRODUCT_LINE_ITEM_TYPE, $id, 1))
                ->setStackable(true)
                ->setRemovable(true)
        );

        $calculated = $this->processor->process($cart$this->context, new CartBehavior());

        static::assertCount(1, $calculated->getLineItems());
        static::assertTrue($calculated->has($id));
        $item = $calculated->get($id);
        static::assertInstanceOf(LineItem::class$item);
        static::assertInstanceOf(CalculatedPrice::class$item->getPrice());
        static::assertSame(119.99, $item->getPrice()->getTotalPrice());

        static::assertCount(1, $calculated->getDeliveries());

        /** @var Delivery $delivery */
        $delivery = $calculated->getDeliveries()->first();
        static::assertTrue($delivery->getPositions()->getLineItems()->has($id));
    }
$this->paymentMethodChangedCriteriaEventResult = null;
        $this->catchEvent(OrderPaymentMethodChangedCriteriaEvent::class$this->paymentMethodChangedCriteriaEventResult);

        $this->transactionStateEventResult = null;
        $this->catchEvent(StateMachineTransitionEvent::class$this->transactionStateEventResult);
    }

    public function testSetPaymentMethodOwnOrderOtherPaymentMethodOpen(): void
    {
        $this->sendValidRequest($this->ids->get('order-1')$this->getAvailablePaymentMethodId(1));
        $transactions = $this->getTransactions($this->ids->get('order-1'));
        static::assertCount(2, $transactions);
        $firstTransaction = $transactions->first();
        static::assertNotNull($firstTransaction);
        $lastTransaction = $transactions->last();
        static::assertNotNull($lastTransaction);
        static::assertNotSame($firstTransaction->getId()$lastTransaction->getId());

        static::assertNotNull($firstTransaction->getStateMachineState());
        static::assertNotNull($lastTransaction->getStateMachineState());
        static::assertSame('cancelled', $firstTransaction->getStateMachineState()->getTechnicalName());
        static::assertSame('open', $lastTransaction->getStateMachineState()->getTechnicalName());

        
$pattern = $this->getContainer()->get(SearchTermInterpreter::class)->interpret('match');
        $queries = $builder->buildScoreQueries(
            $pattern,
            $this->repository->getDefinition(),
            $this->repository->getDefinition()->getEntityName(),
            $context
        );
        $criteria->addQuery(...$queries);

        $result = $this->repository->searchIds($criteria, Context::createDefaultContext());

        static::assertCount(2, $result->getIds());

        static::assertEquals(
            [$recordA$recordB],
            $result->getIds()
        );

        static::assertGreaterThan(
            $result->getDataFieldOfId($recordB, '_score'),
            $result->getDataFieldOfId($recordA, '_score')
        );
    }
}


        $container->compile();

        $this->assertTrue($container->getDefinition(AutoconfiguredService1::class)->hasTag(AutoconfiguredInterface2::class));
        $this->assertTrue($container->getDefinition(AutoconfiguredService2::class)->hasTag(AutoconfiguredInterface2::class));
        $this->assertTrue($container->getDefinition(TaggedConsumerWithExclude::class)->hasTag(AutoconfiguredInterface2::class));

        $s = $container->get(TaggedConsumerWithExclude::class);

        $items = iterator_to_array($s->items->getIterator());
        $this->assertCount(2, $items);
        $this->assertInstanceOf(AutoconfiguredService1::class$items[0]);
        $this->assertInstanceOf(AutoconfiguredService2::class$items[1]);

        $locator = $s->locator;
        $this->assertTrue($locator->has(AutoconfiguredService1::class));
        $this->assertTrue($locator->has(AutoconfiguredService2::class));
        $this->assertFalse($locator->has(TaggedConsumerWithExclude::class));
    }
}

class ServiceSubscriberStub implements ServiceSubscriberInterface
{
exit();
      }
    }

    // This while loop holds the parent process until all the child threads     // are complete - at which point the script continues to execute.     while (pcntl_waitpid(0, $status) != -1);

    Database::addConnectionInfo('default', 'default', $default_connection['default']);
    $factory = new KeyValueDatabaseFactory($this->container->get('serialization.phpserialize'), Database::getConnection());
    $store = $factory->get('test');
    $this->assertCount(10, $store->getAll());
  }

}

    $this->defaultPluginCollection->setInstanceConfiguration('cherry', $expected);
    $config = $this->defaultPluginCollection->getConfiguration();
    $this->assertSame($expected$config['cherry']);
  }

  /** * @covers ::count */
  public function testCount() {
    $this->setupPluginCollection();
    $this->assertCount(3, $this->defaultPluginCollection);
  }

  /** * @covers ::clear */
  public function testClear() {
    $this->setupPluginCollection($this->exactly(6));
    $this->defaultPluginCollection->getConfiguration();
    $this->defaultPluginCollection->getConfiguration();
    $this->defaultPluginCollection->clear();
    $this->defaultPluginCollection->getConfiguration();
  }

    public function testConstraints(): void
    {
        $expectedType = new Type(['type' => 'bool']);

        $ruleConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('isPromoted', $ruleConstraints, 'Constraint isPromoted not found in Rule');
        static::assertCount(1, $ruleConstraints['isPromoted']);
        static::assertEquals($expectedType$ruleConstraints['isPromoted'][0]);
    }

    /** * @return array<boolean[]> */
    public static function matchTestData(): array
    {
        return [
            [true, true, true],
            [true, false, false],
            [
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
    {
        return new TraceableAdapter(new FilesystemAdapter('', $defaultLifetime));
    }

    public function testGetItemMissTrace()
    {
        $pool = $this->createCachePool();
        $pool->getItem('k');
        $calls = $pool->getCalls();
        $this->assertCount(1, $calls);

        $call = $calls[0];
        $this->assertSame('getItem', $call->name);
        $this->assertSame(['k' => false]$call->result);
        $this->assertSame(0, $call->hits);
        $this->assertSame(1, $call->misses);
        $this->assertNotEmpty($call->start);
        $this->assertNotEmpty($call->end);
    }

    public function testGetItemHitTrace()
    {

        ];
        $this->getWriter()->insert($this->configJsonDefinition, $data$context);

        $searcher = $this->getSearcher();
        $context = $context->getContext();

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('data', $string));
        $result = $searcher->search($this->configJsonDefinition, $criteria$context);

        static::assertCount(1, $result->getIds());
        static::assertEquals([$stringId]$result->getIds());

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('data.foo', 'bar'));
        $result = $searcher->search($this->configJsonDefinition, $criteria$context);

        static::assertCount(1, $result->getIds());
        static::assertEquals([$objectId]$result->getIds());

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('data', 'not found'));
        


  /** * Tests views.module: views_embed_view(). */
  public function testViewsEmbedView() {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');

    $result = views_embed_view('test_argument');
    $renderer->renderPlain($result);
    $this->assertCount(5, $result['view_build']['#view']->result);

    $result = views_embed_view('test_argument', 'default', 1);
    $renderer->renderPlain($result);
    $this->assertCount(1, $result['view_build']['#view']->result);

    $result = views_embed_view('test_argument', 'default', '1,2');
    $renderer->renderPlain($result);
    $this->assertCount(2, $result['view_build']['#view']->result);

    $result = views_embed_view('test_argument', 'default', '1,2', 'John');
    $renderer->renderPlain($result);
    
    $field_storage = FieldStorageConfig::load('node.field_user_reference');
    $this->assertSame('entity_reference', $field_storage->getType());
    $this->assertSame('user', $field_storage->getSetting('target_type'));

    // Validate that the source count and processed count match up.     /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->getMigration('d6_field');
    $this->assertSame($migration->getSourcePlugin()->count()$migration->getIdMap()->processedCount());

    // Check that we've reported on a conflict in widget_types.     $messages = iterator_to_array($migration->getIdMap()->getMessages());
    $this->assertCount(1, $messages);
    $this->assertSame($messages[0]->message, 'Widget types optionwidgets_onoff, text_textfield are used in Drupal 6 field instances: widget type optionwidgets_onoff applied to the Drupal 8 base field');
  }

}
Home | Imprint | This part of the site doesn't use cookies.