Example #1
0
    public function test_matcher_list()
    {
        $bemjson = ['block' => 'button', 'content' => ['block' => 'nested', 'content' => ['elem' => 'elem', 'mods' => ['red']]]];
        $list = ['green' => new \BEM\Matcher('button', function (\BEM\Context $ctx) {
            $ctx->mod('green', true);
        }), 'blue' => new \BEM\Matcher('button', function (\BEM\Context $ctx) {
            $ctx->mod('blue', true);
        })];
        $ids = $this->bh->addMatcherList($list);
        static::assertSame([0, 1], $ids);
        $testWithBlueGreen = '
<div class="button button--blue button--green">
  
  <div class="nested">
    
    <div class="nested__elem nested__elem--red">
      
    </div>

  </div>

</div>
';
        $out = $this->bh->apply($bemjson);
        static::assertSame($testWithBlueGreen, $out);
        // change closure
        $list['blue']->matcher = function (\BEM\Context $ctx) {
            $ctx->mod('red', true);
        };
        $testWithRedGreen = '
<div class="button button--red button--green">
  
  <div class="nested">
    
    <div class="nested__elem nested__elem--red">
      
    </div>

  </div>

</div>
';
        $out = $this->bh->apply($bemjson);
        static::assertSame($testWithRedGreen, $out);
        static::assertTrue($this->bh->removeMatcherById($list['blue']->id));
        $testWithGreen = '
<div class="button button--green">
  
  <div class="nested">
    
    <div class="nested__elem nested__elem--red">
      
    </div>

  </div>

</div>
';
        $out = $this->bh->apply($bemjson);
        static::assertSame($testWithGreen, $out);
        static::assertTrue($this->bh->removeMatcherById([$list['green']->id]));
        static::assertFalse($this->bh->removeMatcherById([0, 1]));
    }
Example #2
0
 /**
  * @param string $fileName
  *
  * @return array
  */
 public function loadMatchersFile($fileName)
 {
     return $this->bh->addMatcherList(include $fileName);
 }