Best Atoum code snippet using tag
Tag.php
Source:Tag.php
...16 along with ActiveLink PHP XML Package; if not, write to the Free Software17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/19/**20 * Tag class provides a base for parsing, modifying, outputting and creating XML tags21 * @class Tag22 * @package org.active-link.xml23 * @author Zurab Davitiani24 * @version 0.4.025 * @see XML26 */27class Tag {28 // protected variables29 var $tagStartOpen;30 var $tagStartClose;31 var $tagClose;32 var $tagEndOpen;33 var $tagEndClose;34 var $tagName;35 var $tagContent;36 var $tagAttributes;37 var $tagAttributeSeparator;38 var $tagAttributeSeparators;39 var $tagAttributeAssignment;40 var $tagAttributeValueQuote;41 var $FORMAT_NONE;42 var $FORMAT_INDENT;43 var $tagFormat;44 var $tagFormatIndentLevel;45 var $tagFormatEndTag;46 var $tagFormatNewLine = "\n";47 var $tagFormatIndent = "\t";48 /**49 * Constructor creates a tag object with the specified name and tag content50 * @method Tag51 * @param optional string name52 * @param optional string content53 * @returns none54 */55 function Tag($name = "", $content = "") {56 $this->tagStartOpen = "<";57 $this->tagStartClose = ">";58 $this->tagClose = "/>";59 $this->tagEndOpen = "</";60 $this->tagEndClose = ">";61 $this->setTagName($name);62 $this->setTagContent($content);63 $this->tagAttributes = array();64 $this->tagAttributeSeparator = " ";65 $this->tagAttributeSeparators = array(" ", "\n", "\r", "\t");66 $this->tagAttributeAssignment = "=";67 $this->tagAttributeValueQuote = '"';68 $this->FORMAT_NONE = 0;69 $this->FORMAT_INDENT = 1;70 $this->tagFormat = $this->FORMAT_NONE;71 $this->tagFormatIndentLevel = 0;72 $this->tagFormatEndTag = false;73 }74 /**75 * Find out whether attribute exists76 * @method attributeExists77 * @param string attrName78 * @returns true if attribute exists, false otherwise79 */80 function attributeExists($attrName) {81 return array_key_exists($attrName, $this->tagAttributes);82 }83 /**84 * Get attribute value by its name85 * @method getTagAttribute86 * @param string attrName87 * @returns string attribute value88 */89 function getTagAttribute($attrName) {90 return $this->tagAttributes[$attrName];91 }92 /**93 * Get tag content string94 * @method getTagContent95 * @returns string tag content96 */97 function getTagContent() {98 return $this->tagContent;99 }100 /**101 * Get tag name string102 * @method getTagName103 * @returns string tag name104 */105 function getTagName() {106 return $this->tagName;107 }108 /**109 * Get complete tag string with its attributes and content110 * @method getTagString111 * @returns string tag string112 */113 function getTagString() {114 $formatTagBegin = "";115 $formatTagEnd = "";116 $formatContent = "";117 if($this->tagFormat == $this->FORMAT_INDENT) {118 if($this->tagFormatIndentLevel > 0)119 $formatTagBegin = $this->tagFormatNewLine . str_repeat($this->tagFormatIndent, $this->tagFormatIndentLevel);120 if($this->tagFormatEndTag)121 $formatTagEnd = $this->tagFormatNewLine . str_repeat($this->tagFormatIndent, $this->tagFormatIndentLevel);122 }123 $tagString = $formatTagBegin . $this->getTagStringBegin() . $formatContent . $this->tagContent . $formatTagEnd . $this->getTagStringEnd();124 return $tagString;125 }126 /**127 * Get beginning of the tag string, i.e. its name attributes up until tag contents128 * @method getTagStringBegin129 * @returns string beginning of the tag string130 */131 function getTagStringBegin() {132 $tagString = "";133 if($this->tagName != "") {134 $tagString .= $this->tagStartOpen . $this->tagName;135 foreach($this->tagAttributes as $attrName => $attrValue) {136 $tagString .= $this->tagAttributeSeparator . $attrName . $this->tagAttributeAssignment . $this->tagAttributeValueQuote . $attrValue . $this->tagAttributeValueQuote;137 }138 if($this->tagContent == "")139 $tagString .= $this->tagAttributeSeparator . $this->tagClose;140 else141 $tagString .= $this->tagStartClose;142 }143 return $tagString;144 }145 /**146 * Get ending of the tag string, i.e. its closing tag147 * @method getTagStringEnd148 * @returns string close tag if tag is not short-handed, empty string otherwise149 */150 function getTagStringEnd() {151 $tagString = "";152 if($this->tagName != "" && $this->tagContent != "")153 $tagString .= $this->tagEndOpen . $this->tagName . $this->tagEndClose;154 return $tagString;155 }156 /**157 * Remove all tag attributes158 * @method removeAllAttributes159 * @returns none160 */161 function removeAllAttributes() {162 $this->tagAttributes = array();163 }164 /**165 * Remove a tag attribute by its name166 * @method removeAttribute167 * @returns none168 */169 function removeAttribute($attrName) {170 unset($this->tagAttributes[$attrName]);171 }172 /**173 * Reset the tag object - set name, content to empty strings, and reset all attributes174 * @method resetTag175 * @returns none176 */177 function resetTag() {178 $this->setTagName("");179 $this->setTagContent("");180 $this->removeAllAttributes();181 }182 /**183 * Create or modify an existing attribute by supplying attribute name and value184 * @method setAttribute185 * @param string attrName186 * @param string attrValue187 * @returns none188 */189 function setAttribute($attrName, $attrValue) {190 $this->tagAttributes[$attrName] = $attrValue;191 }192 /**193 * Set contents of the tag194 * @method setTagContent195 * @param string content196 * @returns none197 */198 function setTagContent($content) {199 $this->tagContent = $content;200 }201 /**202 * Set tag formatting option by specifying tagFormat to 0 (none), or 1 (indented)203 * @method setTagFormat204 * @param int tagFormat205 * @param optional int tagFormatIndentLevel206 * @returns none207 */208 function setTagFormat($tagFormat, $tagFormatIndentLevel = 0) {209 $this->tagFormat = $tagFormat;210 $this->tagFormatIndentLevel = $tagFormatIndentLevel;211 }212 /**213 * Set whether closing of the tag should be formatted or not214 * @method setTagFormatEndTag215 * @param optional boolean formatEndTag216 * @returns none217 */218 function setTagFormatEndTag($formatEndTag = true) {219 $this->tagFormatEndTag = $formatEndTag;220 }221 /**222 * Parse a string containing a tag into the tag object, this will parse the first tag found223 * @method setTagFromString224 * @param string tagString225 * @returns array array of [0]=>index of the beginning of the tag, [1]=>index where tag ended226 */227 function setTagFromString($tagString) {228 $i = 0;229 $j = 0;230 $tagStartOpen = $tagStartClose = $tagNameStart = $tagNameEnd = $tagContentStart = $tagContentEnd = $tagEndOpen = $tagEndClose = 0;231 $tagName = $tagContent = "";232 $tagShort = false;233 $tagAttributes = array();234 $success = true;235 $tagFound = false;236 while(!$tagFound && $i < strlen($tagString)) {237 // look for start tag character238 $i = strpos($tagString, $this->tagStartOpen, $i);239 if($i === false)240 break;241 // if tag name starts from alpha character we found the tag242 if(ctype_alpha(substr($tagString, $i + 1, 1)))243 $tagFound = true;244 // else continue searching245 else246 $i ++;247 }248 // if no tag found set success to false249 if(!$tagFound)250 $success = false;251 // if so far so good continue with found tag name252 if($success) {253 $tagStartOpen = $i;254 $tagNameStart = $i + 1;255 // search where tag name would end256 // search for a space separator to account for attributes257 $separatorPos = array();258 for($counter = 0; $counter < count($this->tagAttributeSeparators); $counter ++) {259 $separatorPosTemp = strpos($tagString, $this->tagAttributeSeparators[$counter], $tagStartOpen);260 if($separatorPosTemp !== false)261 $separatorPos[] = $separatorPosTemp;262 }263 //$i = strpos($tagString, $this->tagAttributeSeparator, $tagStartOpen);264 if(count($separatorPos) > 0)265 $i = min($separatorPos);266 else267 $i = false;268 // search for tag close character269 $j = strpos($tagString, $this->tagStartClose, $tagStartOpen);270 // search for short tag (no content)271 $k = strpos($tagString, $this->tagClose, $tagStartOpen);272 // if tag close character is not found then no tag exists, set success to false273 if($j === false)274 $success = false;275 // if tag short close found before tag close, then tag is short276 if($k !== false && $k < $j)277 $tagShort = true;278 }279 // if so far so good set tag name correctly280 if($success) {281 // if space separator not found or it is found after the tag close char282 if($i === false || $i > $j) {283 if($tagShort)284 $tagNameEnd = $k;285 else286 $tagNameEnd = $j;287 $tagStartClose = $j;288 }289 // else if tag attributes exist290 else {291 $tagNameEnd = $i;292 $tagStartClose = $j;293 // parse attributes294 $tagAttributesStart = $i + strlen($this->tagAttributeSeparator);295 $attrString = trim(substr($tagString, $tagAttributesStart, $j - $tagAttributesStart));296 $attrArray = explode($this->tagAttributeValueQuote, $attrString);297 $attrCounter = 0;298 while($attrCounter < count($attrArray) - 1) {299 $attributeName = trim(str_replace($this->tagAttributeAssignment, "", $attrArray[$attrCounter]));300 $attributeValue = $attrArray[$attrCounter + 1];301 $tagAttributes[$attributeName] = $attributeValue;302 $attrCounter += 2;303 }304 }305 $tagName = rtrim(substr($tagString, $tagNameStart, $tagNameEnd - $tagNameStart));306 if(!$tagShort) {307 $tagContentStart = $tagStartClose + 1;308 // look for ending of the tag after tag content309 $j = $tagContentStart;310 $tagCloseFound = false;311 // while loop will find the k-th tag close312 // start with one since we have one tag open313 $k = 1;314 while(!$tagCloseFound && $success) {315 // find k-th tag close from j316 $n = $j - 1;317 for($skip = 0; $skip < $k; $skip ++) {318 $n ++;319 $tempPos = strpos($tagString, $this->tagEndOpen . $tagName . $this->tagEndClose, $n);320 if($tempPos !== false)321 $n = $tempPos;322 else {323 $success = false;324 break;325 }326 }327 // if success, find number of tag opens before the tag close328 $k = 0;329 if($success) {330 $tempString = substr($tagString, $j, $n - $j);331 $tempNewPos = 0;332 do {333 $tempPos = strpos($tempString, $this->tagStartOpen . $tagName, $tempNewPos);334 if($tempPos !== false) {335 $tempPosChar = substr($tempString, $tempPos + strlen($this->tagStartOpen . $tagName), 1);336 $tagEndArray = $this->tagAttributeSeparators;337 $tagEndArray[] = $this->tagEndClose;338 $tempPosTagEnded = array_search($tempPosChar, $tagEndArray);339 if($tempPosTagEnded !== false && $tempPosTagEnded !== NULL) {340 $tempStartClose = strpos($tempString, $this->tagStartClose, $tempPos);341 $tempStartShortClose = strpos($tempString, $this->tagClose, $tempPos);342 // if open tag found increase counter343 if($tempStartClose !== false && ($tempStartShortClose === false || $tempStartClose < $tempStartShortClose))344 $k ++;345 $tempNewPos = $tempPos + strlen($this->tagStartOpen . $tagName);346 }347 else348 $tempNewPos = $tempPos + strlen($this->tagStartOpen . $tagName);349 }350 } while($tempPos !== false);351 }352 // if no tags opened we found the tag close353 if($k == 0)354 $tagCloseFound = true;355 // else set new j356 else {357 $j = $n + strlen($this->tagEndOpen . $tagName . $this->tagEndClose);358 }359 }360 if($tagCloseFound)361 $i = $n;362 else363 $success = false;364 }365 }366 // if so far so good, then we have everything we need! set the object367 if($success) {368 if(!$tagShort) {369 $tagContentEnd = $i;370 $tagContent = substr($tagString, $tagContentStart, $tagContentEnd - $tagContentStart);371 $tagEndOpen = $i;372 $tagEndClose = $tagEndOpen + strlen($this->tagEndOpen . $tagName . $this->tagEndClose);373 }374 else375 $tagEndClose = $tagStartClose + strlen($this->tagStartClose);376 $this->setTagName($tagName);377 $this->setTagContent($tagContent);378 $this->tagAttributes = $tagAttributes;379 }380 if($success)381 return array($tagStartOpen, $tagEndClose);382 else383 return false;384 }385 /**386 * Set tag name387 * @method setTagName388 * @param string name389 * @returns none390 */391 function setTagName($name) {392 $this->tagName = $name;393 }394}395?>...
tags.php
Source:tags.php
...12 * Date13 */14 'date' => [15 'attr' => [],16 'html' => function ($tag) {17 return strtolower($tag->date) === 'year' ? date('Y') : date($tag->date);18 }19 ],20 /**21 * Email22 */23 'email' => [24 'attr' => [25 'class',26 'rel',27 'target',28 'text',29 'title'30 ],31 'html' => function ($tag) {32 return Html::email($tag->value, $tag->text, [33 'class' => $tag->class,34 'rel' => $tag->rel,35 'target' => $tag->target,36 'title' => $tag->title,37 ]);38 }39 ],40 /**41 * File42 */43 'file' => [44 'attr' => [45 'class',46 'download',47 'rel',48 'target',49 'text',50 'title'51 ],52 'html' => function ($tag) {53 if (!$file = $tag->file($tag->value)) {54 return $tag->text;55 }56 // use filename if the text is empty and make sure to57 // ignore markdown italic underscores in filenames58 if (empty($tag->text) === true) {59 $tag->text = str_replace('_', '\_', $file->filename());60 }61 return Html::a($file->url(), $tag->text, [62 'class' => $tag->class,63 'download' => $tag->download !== 'false',64 'rel' => $tag->rel,65 'target' => $tag->target,66 'title' => $tag->title,67 ]);68 }69 ],70 /**71 * Gist72 */73 'gist' => [74 'attr' => [75 'file'76 ],77 'html' => function ($tag) {78 return Html::gist($tag->value, $tag->file);79 }80 ],81 /**82 * Image83 */84 'image' => [85 'attr' => [86 'alt',87 'caption',88 'class',89 'height',90 'imgclass',91 'link',92 'linkclass',93 'rel',94 'target',95 'title',96 'width'97 ],98 'html' => function ($tag) {99 if ($tag->file = $tag->file($tag->value)) {100 $tag->src = $tag->file->url();101 $tag->alt = $tag->alt ?? $tag->file->alt()->or(' ')->value();102 $tag->title = $tag->title ?? $tag->file->title()->value();103 $tag->caption = $tag->caption ?? $tag->file->caption()->value();104 } else {105 $tag->src = Url::to($tag->value);106 }107 $link = function ($img) use ($tag) {108 if (empty($tag->link) === true) {109 return $img;110 }111 if ($link = $tag->file($tag->link)) {112 $link = $link->url();113 } else {114 $link = $tag->link === 'self' ? $tag->src : $tag->link;115 }116 return Html::a($link, [$img], [117 'rel' => $tag->rel,118 'class' => $tag->linkclass,119 'target' => $tag->target120 ]);121 };122 $image = Html::img($tag->src, [123 'width' => $tag->width,124 'height' => $tag->height,125 'class' => $tag->imgclass,126 'title' => $tag->title,127 'alt' => $tag->alt ?? ' '128 ]);129 if ($tag->kirby()->option('kirbytext.image.figure', true) === false) {130 return $link($image);131 }132 // render KirbyText in caption133 if ($tag->caption) {134 $tag->caption = [$tag->kirby()->kirbytext($tag->caption, [], true)];135 }136 return Html::figure([ $link($image) ], $tag->caption, [137 'class' => $tag->class138 ]);139 }140 ],141 /**142 * Link143 */144 'link' => [145 'attr' => [146 'class',147 'lang',148 'rel',149 'role',150 'target',151 'title',152 'text',153 ],154 'html' => function ($tag) {155 if (empty($tag->lang) === false) {156 $tag->value = Url::to($tag->value, $tag->lang);157 }158 return Html::a($tag->value, $tag->text, [159 'rel' => $tag->rel,160 'class' => $tag->class,161 'role' => $tag->role,162 'title' => $tag->title,163 'target' => $tag->target,164 ]);165 }166 ],167 /**168 * Tel169 */170 'tel' => [171 'attr' => [172 'class',173 'rel',174 'text',175 'title'176 ],177 'html' => function ($tag) {178 return Html::tel($tag->value, $tag->text, [179 'class' => $tag->class,180 'rel' => $tag->rel,181 'title' => $tag->title182 ]);183 }184 ],185 /**186 * Twitter187 */188 'twitter' => [189 'attr' => [190 'class',191 'rel',192 'target',193 'text',194 'title'195 ],196 'html' => function ($tag) {197 // get and sanitize the username198 $username = str_replace('@', '', $tag->value);199 // build the profile url200 $url = 'https://twitter.com/' . $username;201 // sanitize the link text202 $text = $tag->text ?? '@' . $username;203 // build the final link204 return Html::a($url, $text, [205 'class' => $tag->class,206 'rel' => $tag->rel,207 'target' => $tag->target,208 'title' => $tag->title,209 ]);210 }211 ],212 /**213 * Video214 */215 'video' => [216 'attr' => [217 'autoplay',218 'caption',219 'controls',220 'class',221 'height',222 'loop',223 'muted',224 'poster',225 'preload',226 'style',227 'width',228 ],229 'html' => function ($tag) {230 // all available video tag attributes231 $availableAttrs = KirbyTag::$types[$tag->type]['attr'];232 // global video tag options233 $attrs = $tag->kirby()->option('kirbytext.video', []);234 $options = $attrs['options'] ?? [];235 // removes options from attributes236 if (isset($attrs['options']) === true) {237 unset($attrs['options']);238 }239 // injects default values from global options240 // applies only defined attributes to safely update tag props241 foreach ($attrs as $key => $value) {242 if (243 in_array($key, $availableAttrs) === true &&244 (isset($tag->{$key}) === false || $tag->{$key} === null)245 ) {246 $tag->{$key} = $value;247 }248 }249 // checks and gets if poster is local file250 if (251 empty($tag->poster) === false &&252 Str::startsWith($tag->poster, 'http://') !== true &&253 Str::startsWith($tag->poster, 'https://') !== true254 ) {255 if ($poster = $tag->file($tag->poster)) {256 $tag->poster = $poster->url();257 }258 }259 // converts tag attributes to supported formats (listed below) to output correct html260 // booleans: autoplay, controls, loop, muted261 // strings : height, poster, preload, width262 // for ex : `autoplay` will not work if `false` is a `string` instead of a `boolean`263 $attrs = [264 'autoplay' => $autoplay = Str::toType($tag->autoplay, 'bool'),265 'controls' => Str::toType($tag->controls ?? true, 'bool'),266 'height' => $tag->height,267 'loop' => Str::toType($tag->loop, 'bool'),268 'muted' => Str::toType($tag->muted ?? $autoplay, 'bool'),269 'poster' => $tag->poster,270 'preload' => $tag->preload,271 'width' => $tag->width272 ];273 // handles local and remote video file274 if (275 Str::startsWith($tag->value, 'http://') !== true &&276 Str::startsWith($tag->value, 'https://') !== true277 ) {278 // handles local video file279 if ($tag->file = $tag->file($tag->value)) {280 $source = Html::tag('source', null, [281 'src' => $tag->file->url(),282 'type' => $tag->file->mime()283 ]);284 $video = Html::tag('video', [$source], $attrs);285 }286 } else {287 // firstly handles supported video providers as youtube, vimeo, etc288 try {289 $video = Html::video(290 $tag->value,291 $options,292 // providers only support width and height attributes293 [294 'height' => $tag->height,295 'width' => $tag->width296 ]297 );298 } catch (Exception $e) {299 // if not one of the supported video providers300 // it checks if there is a valid remote video file301 $extension = F::extension($tag->value);302 $type = F::extensionToType($extension);303 $mime = F::extensionToMime($extension);304 if ($type === 'video') {305 $source = Html::tag('source', null, [306 'src' => $tag->value,307 'type' => $mime308 ]);309 $video = Html::tag('video', [$source], $attrs);310 }311 }312 }313 return Html::figure([$video ?? ''], $tag->caption, [314 'class' => $tag->class ?? 'video',315 'style' => $tag->style316 ]);317 }318 ],319];...
TagAdminTest.php
Source:TagAdminTest.php
1<?php2namespace Mars\Test\Unit;3class TagAdminTest extends \PHPUnit_Framework_TestCase4{5 protected static $tag_titles = [6 [['PHP', 'en-us'],],7 [['html', 'en-us'],],8 [['css', 'en-us'],],9 [['Linux', 'en-us']],10 [['Javascript', 'en-us']],11 [['node.js', 'en-us']],12 [['Art', 'en-us'], ['èºæ¯', 'zh-cn'],],13 [['Design', 'en-us'], ['设计', 'zh-cn'],],14 [['Geek', 'en-us'], ['æ客', 'zh-cn'],],15 [['Travel', 'en-us'], ['æ
游', 'zh-cn'],],16 [['Music', 'en-us'], ['é³ä¹', 'zh-cn'],],17 [['Sports', 'en-us'], ['ä½è²', 'zh-cn']],18 [['Algorithms', 'en-us'], ['ç®æ³', 'zh-cn']],19 [['Websites', 'en-us'], ['ç½ç«', 'zh-cn']],20 [['Facebook', 'en-us'], ['è¸ä¹¦', 'zh-cn']],21 [['Google', 'en-us'], ['è°·æ', 'zh-cn']],22 [['Microsoft', 'en-us'], ['微软', 'zh-cn']],23 ];24 protected static $tag_set = [];25 public static function tearDownAfterClass()26 {27 $tag_admin_service = service('tag_admin');28 foreach (self::$tag_titles as $titles) {29 foreach ($titles as $title) {30 $tag_admin_service->deleteTag(['title' => $title[0]]);31 }32 }33 }34 public function provideTagTitles()35 {36 $tag_titles = [];37 foreach (self::$tag_titles as $titles) {38 $tag_titles[] = $titles[0];39 }40 return $tag_titles;41 }42 /**43 * @dataProvider provideTagTitles44 */45 public function testSaveTag($title, $locale_key)46 {47 $locale_id = locale_set()->getId($locale_key);48 $tag_service = service('tag_admin');49 $pack = service('tag_admin')->saveTag($title, $locale_id);50 $this->assertTrue($pack->isOk());51 $tag_id = $pack->getItem('tag_id');52 $tag = $tag_service->findTag(['tag_id' => $tag_id]);53 $this->assertEquals($title, $tag->getTagTitle($locale_id));54 self::$tag_set[$tag_id][$locale_id] = $title;55 }56 /**57 * @depends testSaveTag58 */59 public function testCreateTagMainError()60 {61 $tag_admin_service = service('tag_admin');62 $pack = $tag_admin_service->createTagMain(63 0,64 0,65 'tag-title-for-test',66 'tag-main-for-test',67 'tag-zcode-for-test'68 );69 $this->assertFalse($pack->isOk());70 $this->assertEquals('not-positive', $pack->getError('tag_id'));71 $pack = $tag_admin_service->createTagMain(1, 0, '', '', '');72 $this->assertFalse($pack->isOk());73 $this->assertEquals('not-positive', $pack->getError('locale'));74 $pack = $tag_admin_service->createTagMain(1, 2, '', '', '');75 $this->assertFalse($pack->isOk());76 $this->assertEquals('empty', $pack->getError('title'));77 $tag_title = self::$tag_titles[0][0];78 $title = $tag_title[0];79 $locale_id = locale_set()->getId($tag_title[1]);80 $tag_main = $tag_admin_service->findTagMain(['title' => $title]);81 $pack = $tag_admin_service->createTagMain(82 $tag_main->tag_id,83 $tag_main->locale_id,84 uniqid('title-'),85 $tag_main->content,86 uniqid('zcode-')87 );88 $this->assertFalse($pack->isOk());89 $this->assertEquals('duplicated', $pack->getError('tag_id-locale'));90 $not_found_tag_id = 9999999999;91 $pack = $tag_admin_service->createTagMain($not_found_tag_id, 1, 'not exist tag id', '');92 $this->assertFalse($pack->isOk());93 $this->assertEquals('not-found', $pack->getError('tag_id'));94 $pack = $tag_admin_service->createTagMain(95 $tag_main->tag_id,96 $locale_id + 1,97 $tag_main->title,98 $tag_main->content,99 uniqid('zcode-')100 );101 $this->assertFalse($pack->isOk());102 $this->assertEquals('duplicated', $pack->getError('title'));103 $pack = $tag_admin_service->createTagMain(104 $tag_main->tag_id,105 $locale_id + 1,106 uniqid('title-'),107 $tag_main->content,108 $tag_main->zcode109 );110 $this->assertFalse($pack->isOk());111 $this->assertEquals('duplicated', $pack->getError('zcode'));112 }113 /**114 * @depends testCreateTagMainError115 */116 public function testCreateTagMain()117 {118 $tag_admin_service = service('tag_admin');119 foreach (self::$tag_titles as $titles) {120 if (isset($titles[1])) {121 $tag = $tag_admin_service->findTag(['title' => $titles[0][0]]);122 $locale_id = locale_set()->getId($titles[1][1]);123 $title = $titles[1][0];124 $pack = $tag_admin_service->createTagMain($tag->id, $locale_id, $title, '');125 $this->assertTrue($pack->isOk());126 self::$tag_set[$tag->id][$locale_id] = $title;127 }128 }129 }130 /**131 * @depends testCreateTagMain132 */133 public function testUpdateTagMain()134 {135 $tag_admin_service = service('tag_admin');136 $title = 'çµå';137 $locale_id = locale_set()->getId('zh-cn');138 $pack = $tag_admin_service->saveTag($title, $locale_id);139 $this->assertTrue($pack->isOk());140 $tag_main = $tag_admin_service->findTagMain(['title' => $title]);141 $new_title = 'çµå设å¤';142 $pack = $tag_admin_service->updateTagMain($tag_main->tag_id, $tag_main->locale_id, $new_title, '', null);143 $this->assertTrue($pack->isOk());144 $tag = $tag_admin_service->findTag(['tag_id' => $tag_main->tag_id]);145 $this->assertEquals($new_title, $tag->getTagTitle($locale_id));146 $pack = $tag_admin_service->deleteTag(['title' => $title]);147 $pack = $tag_admin_service->deleteTag(['title' => $new_title]);148 }149 /**150 * @depends testUpdateTagMain151 */152 public function testGetTagMainSet()153 {154 $tag_admin_service = service('tag_admin');155 foreach (self::$tag_set as $tag_id => $tag_titles) {156 $tag = $tag_admin_service->findTag(['tag_id' => $tag_id]);157 if (!$tag) {158 continue;159 }160 $tag_main_set = $tag->getTagMainSet();161 $this->assertEquals($tag_main_set->getItemCount(), count($tag_titles));162 $tag_main_set->setCountPerPage(0);163 $tag_main_items = $tag_main_set->getItems();164 foreach ($tag_main_items as $tag_main) {165 $this->assertEquals($tag_titles[$tag_main->locale_id], $tag_main->title);166 }167 }168 }169 /**170 * @depends testGetTagMainSet171 */172 public function testDeleteTagMain()173 {174 $tag_admin_service = service('tag_admin');175 $title = uniqid('China-');176 $locale_id = locale_set()->getId('en-us');177 $pack = $tag_admin_service->saveTag($title, $locale_id);178 $this->assertTrue($pack->isOk());179 $tag = $tag_admin_service->findTag(['tag_id' => $pack->getItem('tag_id')]);180 $tag_id = $tag->id;181 $pack = $tag_admin_service->deleteTagMain(['tag_id' => $tag_id, 'locale_id' => $locale_id]);182 $this->assertTrue($pack->isOk());183 $this->assertEquals(0, $tag->getTagMainSet()->getItemCount());184 $pack = $tag_admin_service->deleteTag(['tag_id' => $tag_id]);185 }186 /**187 * @depends testDeleteTagMain188 */189 public function testSchTagSet()190 {191 $tag_admin_service = service('tag_admin');192 $tag_set = $tag_admin_service->schTagSet();193 foreach ($tag_set->getItems() as $tag) {194 if (isset(self::$tag_set[$tag->id])) {195 $tag_arr = self::$tag_set[$tag->id];196 foreach ($tag_arr as $locale_id => $title) {197 $this->assertEquals($title, $tag->getTagTitle($locale_id));198 }199 }200 }201 $tag_set = $tag_admin_service->schTagSet(['keywords' => 'Trav']);202 foreach ($tag_set->getItems() as $tag) {203 $tag_arr = self::$tag_set[$tag->id];204 foreach ($tag_arr as $locale_id => $title) {205 $this->assertEquals($title, $tag->getTagTitle($locale_id));206 }207 }208 }209 /**210 * @depends testSchTagSet211 */212 public function testActivateTag()213 {214 $title = uniqid('title-');215 $locale_id = locale_set()->getId('en-us');216 $tag_admin_service = service('tag_admin');217 $pack = $tag_admin_service->saveTag($title, $locale_id);218 $this->assertTrue($pack->isOk());219 $tag_id = $pack->getItem('tag_id');220 $tag = $tag_admin_service->findTag(['title' => $title]);221 $this->assertEquals($tag_id, $tag->id);222 $pack = $tag_admin_service->deactivateTagById($tag_id);223 $tag = $tag_admin_service->findTag(['title' => $title]);224 $this->assertFalse($tag);225 $tag = $tag_admin_service->findTag(['title' => $title, 'status' => null]);226 $this->assertEquals(0, $tag->status);227 $pack = $tag_admin_service->activateTagById($tag_id);228 $this->assertTrue($pack->isOk());229 $tag = $tag_admin_service->findTag(['title' => $title, 'status' => null]);230 $this->assertEquals(1, $tag->status);231 $tag_admin_service->deleteTag(['tag_id' => $tag_id]);232 }233}...
tag
Using AI Code Generation
1use \mageekguy\atoum\tag;2{3 public function testTag()4 {5 ->given($tag = new tag())6 ->object($tag->add('foo'))->isIdenticalTo($tag)7 ->array($tag->getTags())->isEqualTo(array('foo'))8 ->object($tag->add('bar'))->isIdenticalTo($tag)9 ->array($tag->getTags())->isEqualTo(array('foo', 'bar'))10 ->object($tag->add('foo'))->isIdenticalTo($tag)11 ->array($tag->getTags())->isEqualTo(array('foo', 'bar'))12 ->object($tag->remove('foo'))->isIdenticalTo($tag)13 ->array($tag->getTags())->isEqualTo(array('bar'))14 ->object($tag->remove('foo'))->isIdenticalTo($tag)15 ->array($tag->getTags())->isEqualTo(array('bar'))16 ->object($tag->remove('bar'))->isIdenticalTo($tag)17 ->array($tag->getTags())->isEmpty()18 ;19 }20}
tag
Using AI Code Generation
1{2 public function test()3 {4 ->given(5 $tag = new tag()6 ->object($tag)7 ->isInstanceOf('tag')8 ->string($tag->display())9 ->isEqualTo('Hello World')10 ;11 }12}13{14 public function test()15 {16 ->given(17 $tag = new tag()18 ->object($tag)19 ->isInstanceOf('tag')20 ->string($tag->display())21 ->isEqualTo('Hello World')22 ;23 }24}25{26 public function test()27 {28 ->given(29 $tag = new tag()30 ->object($tag)31 ->isInstanceOf('tag')32 ->string($tag->display())33 ->isEqualTo('Hello World')34 ;35 }36}37{38 public function test()39 {40 ->given(41 $tag = new tag()42 ->object($tag)43 ->isInstanceOf('tag')44 ->string($tag->display())45 ->isEqualTo('Hello World')46 ;47 }48}49{50 public function test()51 {52 ->given(53 $tag = new tag()54 ->object($tag)55 ->isInstanceOf('tag')56 ->string($tag->display())57 ->isEqualTo('
tag
Using AI Code Generation
1use atoum\test;2{3 public function testMyMethod()4 {5 $this->variable(1)->isIdenticalTo(1);6 }7}8use atoum\test;9{10 public function testMyMethod()11 {12 $this->variable(1)->isIdenticalTo(1);13 }14}15use atoum\test;16{17 public function testMyMethod()18 {19 $this->variable(1)->isIdenticalTo(1);20 }21}22use atoum\test;23{24 public function testMyMethod()25 {26 $this->variable(1)->isIdenticalTo(1);27 }28}29use atoum\test;30{31 public function testMyMethod()32 {33 $this->variable(1)->isIdenticalTo(1);34 }35}36use atoum\test;37{38 public function testMyMethod()39 {40 $this->variable(1)->isIdenticalTo(1);41 }42}43use atoum\test;44{45 public function testMyMethod()46 {47 $this->variable(1)->isIdenticalTo(1);48 }49}50use atoum\test;51{52 public function testMyMethod()53 {54 $this->variable(1)->isIdenticalTo(1);55 }56}57use atoum\test;58{59 public function testMyMethod()60 {61 $this->variable(1)->isIdenticalTo
tag
Using AI Code Generation
1use mageekguy\atoum\test;2use mageekguy\atoum\asserters;3{4 public function testSomething()5 {6 $obj = new stdClass();7 $var = 1;8 $arr = array(1, 2, 3);9 $this->assert('Test type of variable')10 ->variable($var)->isInteger()11 ->object($obj)->isInstanceOf('stdClass')12 ->array($arr)->hasSize(3)13 ;14 }15}
tag
Using AI Code Generation
1require_once 'atoum.phar';2use atoum\atoum;3class myClass extends atoum {4public function testOne() {5$this->boolean(true)->isTrue();6}7}8require_once 'atoum.phar';9use atoum\atoum;10class myClass extends atoum {11public function testOne() {12$this->boolean(true)->isTrue();13}14}15require_once 'atoum.phar';16use atoum\atoum;17class myClass extends atoum {18public function testOne() {19$this->boolean(true)->isTrue();20}21}22require_once 'atoum.phar';23use atoum\atoum;24class myClass extends atoum {25public function testOne() {26$this->boolean(true)->isTrue();27}28}29require_once 'atoum.phar';30use atoum\atoum;31class myClass extends atoum {32public function testOne() {33$this->boolean(true)->isTrue();34}35}36require_once 'atoum.phar';37use atoum\atoum;38class myClass extends atoum {39public function testOne() {40$this->boolean(true)->isTrue();41}42}43require_once 'atoum.phar';44use atoum\atoum;45class myClass extends atoum {46public function testOne() {47$this->boolean(true)->isTrue();48}49}50require_once 'atoum.phar';51use atoum\atoum;52class myClass extends atoum {53public function testOne() {54$this->boolean(true)->isTrue();55}56}
tag
Using AI Code Generation
1$tag = new Atoum\Tag();2$tag->create('test');3$tags = $tag->getAll();4$tag = $tag->get('test');5$tag->delete('test');6$tag->deleteAll();7$tag->add('test', '1.php');8$files = $tag->getFiles('test');9$tag->deleteFile('test', '1.php');10$tag->deleteAllFiles('1.php');11$tag->deleteAllFiles('1.php');12$files = $tag->getFiles('test');13$tags = $tag->getTags('1.php');14$tag->deleteAllFiles('1.php');15$tag->deleteAllFiles('1.php');16$files = $tag->getFiles('test');17$tags = $tag->getTags('1.php');18$tag->deleteAllFiles('1.php');19$tag->deleteAllFiles('1.php');20$files = $tag->getFiles('test');21$tags = $tag->getTags('1.php');22$tag->deleteAllFiles('1.php');23$tag->deleteAllFiles('1.php');24$files = $tag->getFiles('test');25$tags = $tag->getTags('1.php');26$tag->deleteAllFiles('1.php');27$tag->deleteAllFiles('1.php');28$files = $tag->getFiles('test');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!